This lesson introduces the FSR (Force Sensitive Resistor) component. This component detects physical pressure and is a fun input for your projects. This lesson also includes an activity where you’ll practice using the FSR.
The Force Sensitive Resistor (FSR) is a sensor that detects physical pressure. Adafruit Learn has an excellent overview of the FSR and you should definitely check it out if you’re looking for more information about the sensor.
The pressure that the FSR detects can come in several forms, but two common ones are squeezing and weight.
The input that comes from the FSR is similar to what you receive from a photoresistor in that it will return a range of inputs.
The FSR is a thin component that has a circular head. Here’s an image of the FSR from Sparkfun Electronics:
This project is similar to the Fading LED except instead of using the photoresistor or potentiometer to change the LED’s brightness, you’ll be using the FSR! The FSR is a great component that can be included in a variety of projects once you understand the basic functionality.
The steps for this project are split between the circuit setup and the sketch itself. The sketch is a basic project designed to get you up and running with this new sensor.
Refer to this fritzing diagram for the circuit setup:
The connection should look like this:
Here’s the basic sketch to get up and running with the FSR. Experiment with changing some of the values. The serial monitor is included so that you can monitor the input values from the FSR.
// declare global variables
int fsrPin = 0; // fsr is connected to analog 0
int ledPin = 11; // led is connected to pin 11 (pwm)
int fsrReading; // analog reading from the fsr
int ledBrightness;
void setup() {
Serial.begin(9600); //setup the serial monitor for debugging
pinMode(ledPin, OUTPUT); //set the led pin to output
}
void loop() {
fsrReading = analogRead(fsrPin); // read the value from the analog pin
Serial.print("FSR Reading = ");
Serial.println(fsrReading);
/*
* we need to use map to change the range from the analog reading to the
* brightness of the LED, just like with the photoresistor and potentiometer projects
*/
ledBrightness = map(fsrReading, 0, 1023, 0, 255); // map the analog values to the brightness
// press harder for brighter LED!
analogWrite(ledPin, ledBrightness);
delay(100); // delay the writing slightly
}
Code language: JavaScript (javascript)
Now that you have a basic understanding of how to set up the FSR circuit, go ahead and begin integrating it into some of your other circuits!