Pressure sensor

My program lights up different LEDs on the Arduino based on the pressure applied to the FSR. On low pressure, it’s green; on medium, blue and on higher pressure, red. It can be used in trash cans to check for the amount of trash inside, or installed under the insoles of shoes to check how relaxed the fit is.


const int ledGreen = 7; // Level Min
const int ledBlue = 4; // Level Medium
const int ledRed = 2; // Level Full
int fsrPin = A0; 
int fsrReading; 
void setup(void) {
   // Debugging information via the Serial monitor
   Serial.begin(9600);
   pinMode(ledRed, OUTPUT);
   pinMode(ledBlue, OUTPUT);
   pinMode(ledGreen, OUTPUT);
}
void loop(void) {
   fsrReading = analogRead(fsrPin); 
   if (fsrReading <=512) {
      digitalWrite(ledRed, LOW);
      digitalWrite(ledGreen, LOW);
      digitalWrite(ledBlue, LOW);
   }
   if (fsrReading > 512 && fsrReading <= 600) {
      digitalWrite(ledRed, LOW);
      digitalWrite(ledGreen, HIGH);
      digitalWrite(ledBlue, LOW);
   }
   if (fsrReading > 600 && fsrReading <= 680) {
      digitalWrite(ledRed, LOW);
      digitalWrite(ledGreen, LOW);
      digitalWrite(ledBlue, HIGH);
   }
   if (fsrReading > 680) {
      digitalWrite(ledRed, HIGH);
      digitalWrite(ledGreen, LOW);
      digitalWrite(ledBlue, LOW);
   }
   //Serial.print("Analog reading = ");
   Serial.println(fsrReading); // Raw analog reading
   delay(250); // Slow down the output for easier reading
}

img_20160928_075818

Leave a Reply