Introduction: Interfacing Force Sensitive Resistor to Arduino
An FSR(Force Sensitive Resistor) is a sensor that allows you to measure physical pressure, weight and squeezing. They are pretty much used in DIY electronics as they are available at low cost.
In this Instructable, I'll show you how to Interface an FSR to Arduino and change the brightness of an LED depending on the pressure applied on the FSR.
Step 1: Components Required
For this project, you will need:
- Arduino Uno.
- FSR (Force Sensitive Resistor).
- 10K Resistor.
- Hook-up Wires.
- LED
- BreadBoard.
Step 2: About the FSR
The FSR is made of 2 layers separated by a spacer. The more one presses, the more of those Active Element dots touch the semiconductor and that makes the resistance go down.
FSRs are basically a resistor that changes its resistive value (in ohms Ω) depending on how much it is 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 FSRs 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: Connections
The connections are pretty easy and straight forward. Make the circuit by referring the images.
- The FSR has two pins, one will be connected to 5V pin.
- The other to A0 directly and to Gnd pin via a resistor.
If you need to connect the LED and control it's brightness, then connect it across pin 13 and Gnd of the Arduino.
Step 4: The Code
/* FSR simple testing sketch. <br>Connect one end of FSR to power, the other end to Analog 0. Then connect one end of a 10K resistor from Analog 0 to ground */ int fsrPin = 0; // the FSR and 10K pulldown are connected to a0 int fsrReading; // the analog reading from the FSR resistor divider void setup(void) { Serial.begin(9600); } void loop(void) { fsrReading = analogRead(fsrPin); Serial.print("Analog reading = "); Serial.print(fsrReading); // the raw analog reading if (fsrReading == 0) { Serial.println(" - No pressure"); } else if (fsrReading < 10) { Serial.println(" - Light touch"); } else if (fsrReading < 50) { Serial.println(" - Light squeeze"); } else if (fsrReading < 150) { Serial.println(" - Medium squeeze"); } else { Serial.println(" - Big squeeze"); } delay(1000); }
The above code is for simply reading the values. The below code can be used to change the brightness when you connect an LED across the Digital Pin 13 of the Arduino.
/* FSR testing sketch. Connect one end of FSR to 5V, the other end to Analog 0. Then connect one end of a 10K resistor from Analog 0 to ground Connect LED from pin 13 through a resistor to ground int fsrAnalogPin = 0; // FSR is connected to analog 0 int LEDpin = 11; // connect Red LED to pin 11 (PWM pin) int fsrReading; // the analog reading from the FSR resistor divider int LEDbrightness; void setup(void) { Serial.begin(9600); // We'll send debugging information via the Serial monitor pinMode(LEDpin, OUTPUT); } void loop(void) { fsrReading = analogRead(fsrAnalogPin); Serial.print("Analog reading = "); Serial.println(fsrReading); // we'll need to change the range from the analog reading (0-1023) down to the range // used by analogWrite (0-255) with map! LEDbrightness = map(fsrReading, 0, 1023, 0, 255); // LED gets brighter the harder you press analogWrite(LEDpin, LEDbrightness); delay(100); }
Step 5: The Result
Once you have uploaded the code, open up the serial monitor. You will see it display the values from the FSR. You can use these values to run different applications based on your projects. Like if you want to control an LEDs brightness upload the second code on to the Arduino.
That's All Folks !!! Stay Tuned For More !!