Introduction: Interface Force Sensitive Resistor to Fade an LED Using NodeMCU

Picture of Interface Force Sensitive Resistor to Fade an LED Using NodeMCU

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....

Step 1: Things Needed

Picture of Things Needed

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

Step 2: Description

Picture of Description

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.

Step 3: Circuit Wiring

Picture of Circuit Wiring

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

Step 4: 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 }

Step 5: Output

Picture of Output

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!

Comments

drakopp (author)2017-10-17

Is it possible to connect two Force Sensitive Resistors because NodeMCU has one analog input?

About This Instructable

870views

26favorites

License:

Bio: Work until you no longer have to introduce yourself.
More by TheCircuit:Carrot Almond MilkshakeDIY - Flower VasePotato Stuffing - Who's Hungry
Add instructable to: