Skip to main content

How to use Force Sensitive Resistor - Pressure sensor




Force Sensitive Resistor - Pressure sensor


Introduction 

In this tutorial you will learn how to use an FSR - Force Sensitive Resistor with Arduino to fade an LED. This sensor is a variable resistor just like a photocell or flex sensor. The resistance changes by applying pressure on it.

Picture

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard
  • Force sensitive resistor
  • LED
  • 10KOhm & 220 Ohm resistors
Picture

The Circuit

Picture
The connections are pretty easy, see the image above with the breadboard circuit schematic.

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);

************************************************************************
/* How to use a Force sensitive resistor to fade an LED with Arduino
  */
  
//Constants:
const int ledPin = 3;     //pin 3 has PWM funtion
const int sensorPin = A0; //pin A0 to read analog input

//Variables:
int value; //save analog value


void setup(){
  pinMode(ledPin, OUTPUT);  //Set pin 3 as 'output' 
  Serial.begin(9600);       //Begin serial communication

}

void loop(){
  
  value = analogRead(sensorPin);       //Read and save analog value from potentiometer
  Serial.println(value);               //Print value
  value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
  analogWrite(ledPin, value);          //Send PWM value to led
  delay(100);                          //Small delay
  
}

************************************************************************

Well done!

Picture
You have successfully completed one more Arduino "How to" tutorial and you learned how to use a Force Sensitive Resistor with Arduino.

I hope you liked this, let me know in the comments.

Comments

Popular posts from this blog

Arduino ​Obstacle Avoiding Robot Ardunio Computer

Build Your Own Arduino Weather Station

Complete Guide for Nokia 5110 LCD with Arduino