Categories
TUTORIALS

Using Force Sensitive Resistor to Detect the Fullness of a Trash Bin and Change RGB Color Accordingly

Introduction:

This tutorial will show how to detect the fullness of a trash can by using two force sensitive resistor (FSR), and a RGB LED will change its color according to the changes. Basically, FSR is a resistor which can change its resistance depending on how much pressure it receives, and it is very sensitive to pressure change.

In our project, we are going to stick two FSRs on the inner wall of a trash can, one on the half  and the other on the top.  If the trash can is less than half-full, the RGB will be green. If the trash can is half-full, the trashes will touch the FSR on the middle and it can capture the change of the pressure. Then the RGB will change to blue color. If the trash can is full, trashes will touch the other FSR on the top, and the RGB will change to red color.

However, for this tutorial, we are just using the Arduino board to connect all the  parts together and use our fingers to touch the FSRs instead of the trashes.

Parts List:

  • Arduino board
  • Breadboard
  • Wires
  • Two Square Force Sensitive Resistors *
  • One RGB LED
  • Optional: 9 volts Battery (if you need it to work without connecting to the computer)

* Note: In this case, we are going to use the Square FSR  from Adafruit (Product ID: 1075). There are different shapes of FSRs available on Adafruit and you can choose the shape that fits your project best.

Wiring the sensors:

Let’s connect one FSR first. Connect one end of the pin to 5 volts, and the other end to Analog 0 pin (A0). Then connect a 10k ohms resistors from A0 to ground, because we want to protect our sensor from burning down. Do the same thing to the second FSR, but change the Analog 0 to Analog 1.

Secondly, connect the RGB LED to the board. There are four pins with different length on RGB. The longest pin is common, which should be connected to ground. Based on the longest pin, the color order is RED, COMMON, GREEN and BLUE.

Connect the common pin to ground, and connect the red, green and blue pin to digital pin 2,3 and 4. Between each digital pin and RGB pin, connect a 330 ohms resistor.

Circuit Diagram :

*In the diagram, the FSRs are circle, but in our project, we use the square FSR. They are basically the same things with different shapes.

Code:

Now let’s start to run the code. Firstly, we declare some variables to identify the pins we are connecting to. Make sure that your sensors are connected to the same pins as in your code, because otherwise it won’t work. Then we declare two variables to store values from the analog pins connected to our FSRs.

In our main code, we set the speed of serial monitor and the output of the RGB pins at first. Then we read the value from FSRs and print them on the serial monitor, so that we can check if the sensors are working properly. We use three “if” statements to set three different conditions:

(1) When both of the FSRs are not being pressed, the RGB will only output the green light through the green pin.

(2) When the first FSR is being pressed and the second is not, the RGB will output the blue light through the blue pin.

(3) When both of the FSRs are being pressed, the RGB will output the red light through the red pin.

We loop the code every second. Now, if you load the code and open your serial monitor, you will able to see the value from the two FSRs every second, and the RGB color will change according to which FSR you are pressing. You can change the delay time in the delay() code, so if you want your sensor to be more responsive to pressure change you can make the number smaller.

*My Arduino software is in Chinese because it adjusts to the language in my computer. Don’t worry about it.

The complete code is included below. Have fun playing with your Arduino!

Leave a Reply

Your email address will not be published. Required fields are marked *