Introduction
In this tutorial, we will show you how to use a Square Force Sensitive Resistor (FSR) to detect when a pedestrian or a bike is passing by. The FSR will trigger an RGB LED to light up for a few seconds, providing a sense of safety for neighborhoods. This system can be easily set up by placing the FSR on the sidewalk, particularly in areas where vacant lots pose a higher safety risk. Moreover, this setup can also help conserve energy by only turning on the lights when someone passes by.
Parts list
- Force Sensitive Resistor (FSR) (In this tutorial, we use Square Force-Sensitive Resistor (FSR) Alpha MF02A-N-221-A01 From Adafruit, Product ID: 1075)
- Arduino board
- Breadboard
- Wires
- RGB LED
- Three 220 ohm resistors
- One 10k ohm resistor
Optional: Battery
Workflow
- Connect one end of the FSR to the 5V power source, the other to Analog A0, and the ground. Make sure to use a 10k ohm resistor between the ground wire.
- Connect the longest lead of the RGB LED to the ground. Connect the blue lead to pin 11, the green lead to pin 10, and the red lead to pin 9. Remember to use a 220-ohm resistor for each wire to prevent burning out the LED.
- That’s all for the wiring! Ensure that the code matches the pins you have just connected. You can also adjust the color of the LED to your preference.
- In the following code, the LED will turn white when a pedestrian passes by (which is detected by a value of around 1,000). If it’s a bike passing by (detected by a value of around 2,000), the LED will turn blue. Be sure to test the values you want to detect and adjust the threshold and reaction color to your liking.
Circuit Diagram
Well done! It will look like this!
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
/* Tutorial - Using Force Sensitive Resistor (FSR) to Identify Pedestrian or Bike by Blinking RGB LED This project uses a force-sensitive resistor to detect when a pedestrian or bike passes by and will blink white or blue to light up the surrounding area. We have tested the reading value for a person, which is around 1000, and for a bike, which is between 1000 to 2000. modified April 1, 2023 by Teresa Chang This project extends 1. ELEGOO Lessons 2 and 4 https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink 2. Adafruit FSR Tutorial https://learn.adafruit.com/force-sensitive-resistor-fsr/using-an-fsr */ // Define Pins and Variables int fsrPin = 0; // The FSR and 10K pulldown are connected to a0 int fsrReading; // The analog reading from the FSR resistor divider #define BLUE_RGB 11 #define GREEN_RGB 10 #define RED_RGB 9 int redIntensity; // Variables for RGB LED colors int greenIntensity; int blueIntensity; // The setup function runs once when you press reset or power the board void setup(void) { Serial.begin(9600); pinMode(RED_RGB, OUTPUT); pinMode(GREEN_RGB, OUTPUT); pinMode(BLUE_RGB, OUTPUT); } // The loop function runs over and over again, and blink the color of purple, blue, and green sequentially. void loop(void) { fsrReading = analogRead(fsrPin); Serial.print("Analog reading = "); Serial.print(fsrReading); // print out the raw analog reading // Thresholds for detection of pedestrians(900 to 1500) and bikes(above 1500) // This section presents two ways to control the RGB LED. The first way is by switching on and off the three color LEDs in the RGB LED, while the second way is by using the values for the color, which can form a greater variety of colors. if (fsrReading < 900) { // The reading value for a person is around 1000 Serial.println(" No one is passing"); digitalWrite(RED_RGB, LOW); digitalWrite(BLUE_RGB, LOW); digitalWrite(GREEN_RGB, LOW); // Turn the RGB LED off when no one is passing by making the voltage LOW } else if (fsrReading < 1500) { Serial.println(" Someone's passing! Light up!"); redIntensity = 255; // Turn the RGB LED's color to white by using the values for the color white. greenIntensity = 255; blueIntensity = 255; analogWrite(RED_RGB, redIntensity); analogWrite(BLUE_RGB, blueIntensity); analogWrite(GREEN_RGB, greenIntensity); delay(10000); // Turn on for 10 seconds } else { Serial.println(" Bike!"); digitalWrite(BLUE_RGB, HIGH); // Turn the RGB LED's color to blue by making the voltage HIGH delay(10000); } delay(1000); // Detect the FSR value every second } |
Let’s test it!
Congratulations! You now know how to use an FSR to trigger an RGB LED. If you’re interested in seeing how we apply this to projects, please check out our project on Healthy Blocks.