Interface Force Sensitive Resistor to Fade an LED Using NodeMCU

by CodeChamp in Circuits > Sensors

6466 Views, 30 Favorites, 0 Comments

Interface Force Sensitive Resistor to Fade an LED Using NodeMCU

Cover.jpg

Hello Makers,

I'm back with another cool Instructable.

This Instructable is part of a series of Instructables with the NodeMCU, my previous Instructables shows you how to get started with the NodeMCU, and lots more. So make sure, you check that first before trying out this.

In this instructable I'm going to show you how to use an FSR - Force Sensitive Resistor with NodeMCU to fade an LED. This sensor is a variable resistor just like a flex sensor. The resistance changes by applying pressure on it.

So let's get begin....

Things Needed

14.jpeg

This is a really simple tutorial and all you need to get started is :

Hardware Component

  • NodeMCU
  • FSR ( Force Sensitive Resistor )
  • LED
  • 10K Ohm & 100 Ohm resistors
  • Bread Board
  • Jumper Wires
  • Micro USB Cable

Software Components

  • Arduino IDE

Description

03.jpeg
02.jpeg
06.jpeg
04.jpeg
08a.jpg
05.jpeg
07.jpeg
09.jpeg
01.jpeg

What is a Force Sensitive Resistor?

FSRs are sensors that allow you to detect physical pressure, squeezing and weight. They are simple to use and low cost.

FSR's are basically a resistor that changes its resistive value (in ohms) depending on how much its pressed. These sensors are fairly low cost, and easy to use but they're rarely accurate. They also vary some from sensor to sensor perhaps 10%. So basically when you use FSR's you should only expect to get ranges of response. While FSRs can detect weight, they're a bad choice for detecting exactly how many pounds of weight are on them.

Circuit Wiring

09.jpg
10.jpeg
11.jpg
11.jpeg
01.jpg
02.jpg
03.jpg
04.jpg
05.jpg
06.jpg
07.jpg
08.jpg
ezgif.com-gif-maker (1).gif

No soldering skills are required as we will be using a breadboard.

The connections are pretty easy, see the Images and GIF.

Before you get started with coding you need Arduino IDE.
To download Arduino IDE and for NodeMCU setup, you can check my first instructacle.

Interfacing Servo Motor With NodeMCU

The Code

How it works:

Read analog value from flex sensor : value=analogRead(sensorPin);
Map analog values 0-1023 to PWM values 0-255 : value = map(value, 0, 1023, 0, 255); Send PWM value to led ; analogWrite(ledPin, value);

Download the "FSR.ino" file and open it up in the Arduino IDE.
Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload.

You can tinker with it if you like based on the application, or just use it as it is.

CODE

/* Interface Force Sensitive Resistor to fade an LED using NodeMCU

* By TheCircuit */

//Constants:

const int led = 16; // Pin D0 has PWM function const int sensorOut = A0; // Pin A0 to read analog input

//Variables: int pressure; //To store analog value

void setup(){ pinMode(led, OUTPUT); // Set Pin D0 as 'output' Serial.begin(9600); // Begin serial communication

}

void loop(){ pressure = analogRead(sensorOut); //Read and store analog value from Force Sensitive Resistance Serial.println(pressure); //Print value pressure = map(pressure, 0, 1023, 0, 255);//Map value 0-1023 to 0-255 (PWM) analogWrite(led, pressure); //Send PWM value to led connected at pin D0 delay(100); //Small delay }

Downloads

Output

ezgif.com-video-to-gif.gif
Zero Pressure.PNG
Pressure1.PNG
Slight.PNG

Using Serial monitor you can check the output from the analog pin connected to FSR.

Depending upon the pressure applied the LED is faded.

That's all makers!

You have successfully completed one more NodeMCU Instructable "Interface Force Sensitive Resistor to fade an LED using NodeMCU".

I hope you liked this, Stay Tuned for more Projects!