Working With Force Sensitive Resistor

Introduction

In my previous article I explained about Windows Form Application using Arduino and in this article I'll show you how to use FSR Sensor to fade LED. This sensor is simple to setup and great for sensing pressure.

Requirements
  • Arduino Uno
  • Force Sensitive Sensor
  • Bread Board
  • 10K ohm Resistor
  • 220k ohm Resistor
  • Led
Connection 
  • FSR pin-1 to Analog A0
  • FSR pin-2 to 5v
  • Led anode pin-3
  • Cathode pin to Gnd  

Programming
  1. int ledpin = 3;  
  2. int sensorPin = A1;  
  3. int value;  
  4. void setup()  
  5. {  
  6.     pinMode(ledpin, OUTPUT);  
  7.     Serial.begin(9600); // Baud Rate  
  8. }  
  9. void loop()  
  10. {  
  11.     value = analogRead(sensorPin);  
  12.     Serial.println(value);  
  13.     value = map(value, 0, 1023, 0, 255);  
  14.     Map value 0 - 1023 to 0 - 255(PWM)  
  15.     analogWrite(ledpin, value);  
  16.     delay(100);  
  17. }  
Explanation

Initialize
the value ledpin=3 digital and Sensorpin=A1 as analog and declare the value as int. In the Setup() function set the pinMode to the LED as OUTPUT and set the baud rate(9600). In the loop() function we want to set the conditions for Force Sensitive Sensor.
  • Value=analogRead(sensorPin) // Read and save the Analog value from the pote
  • Serial.println(value) // Print the value
  • value=map(value,0,1023,0,255) //Map value
  • analogWrite(ledPin,value //Send PWM value to led
  • PWM //Pulse Width Modulation
  • delay(1000) //Set delay time to 1sec
Output


Conclusion

And finally I conclude that we can fade an LED using Force Sensing Resistor.

Up Next
    Ebook Download
    View all
    Learn
    View all