Categories
TUTORIALS

USING IR BREAKBEAM SENORS TO DETECT THE FULLNESS OF A TRASH BIN AND CHANGE RGB COLOR ACCORDINGLY

This tutorial will show how to detect the fullness of a trash can by using an IR breakbeam sensor, and a RGB LED will change its color according to the changes.

Parts list :

  • Arduino Uno
  • IR Breakbeam Sensor
  • Wires (of various lengths and ends)
  • An LED light bulb
  • 3 330 ohm resistor

Infrared (IR) break-beam sensors are a simple way to detect motion. They work by having an emitter side that sends out a beam of human-invisible IR light, then a receiver across the way which is sensitive to that same light. When something passes between the two, and its not transparent to IR, then the ‘beam is broken’ and the receiver will let you know.

Compared to PIR sensors, breakbeams are faster and allow better control of where you want to detect the motion. Compared to Sonar modules, they’re less expensive. However, you do need both emitter and receiver on opposite sides of the area you want to monitor.

This is the 3mm IR version. It works up to 25cm / 10″. You can power it from 3.3V or 5V, but 5V will get you better range and is what I suggest. The receiver is open collector transistor output which means that you do need a pull up resistor if you want to read a digital signal off the signal wire. Most microcontrollers have the ability to turn on a built in pull up resistor. If you do not, connect a 10K resistor between the white wire of the receiver and the red wire.

Step 1 : Circuit

The wiring for it is simple. For the emitter and the receiver connect the red wires to the positive end on the breadboard and the black wires to the negative end. Connect the receivers white(sometimes yellow) wire to pin 4 on the arduino.

For the LED pins connect the red cathode to pin 9, green to pin 10 and blue to pin 11 and the common to GND.

Step 2 : Code

The code for our “warning system” has two basic functions: sense and response. We want to sense when the bin is almost full and respond by displaying that the bin is full.. In order to ensure the code and sensor are working properly, I have also included in the code to display when the connection is broken or unbroken.

/* 
  IR Breakbeam sensor demo!
*/

#define SENSORPIN 4         // the sensor is connected to pin 4 on the arduino

// variables will change:
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;
int sensorState = 0, lastState=0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  // Here we'll configure the Arduino pins we're using to
  // drive the LED to be outputs:
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);  
     
  // initialize the sensor pin as an input:
  pinMode(SENSORPIN, INPUT);     

  
  digitalWrite(SENSORPIN, HIGH); // turn on the pullup
  
  Serial.begin(9600);
}

void loop(){
  // read the state of the pushbutton value:
  sensorState = digitalRead(SENSORPIN);

  // check if the sensor beam is broken
  // if it is, the sensorState is LOW:
  if (sensorState == LOW) 
  {     
    // turn LED on:
    // Red (turn just the red LED on):

    digitalWrite(RED_PIN, HIGH);
    digitalWrite(GREEN_PIN, LOW);
    digitalWrite(BLUE_PIN, LOW);;  
  } 
  else 
  {
      // Off (all LEDs off):
    
      digitalWrite(RED_PIN, LOW);
      digitalWrite(GREEN_PIN, LOW);
      digitalWrite(BLUE_PIN, LOW);
  }
  
  if (sensorState && !lastState) {
    Serial.println("Unbroken");
  } 
  if (!sensorState && lastState) {
    Serial.println("Broken");
  }
  lastState = sensorState;
}

Step 3 : Results

The breakbeam sensor is put on either sides of the waste bin which in this case would be a sharp disposal bin.

Scenario 1 : Bin is not full

Scenario 2 : Bin is full

Step 4 : Change according to the type of bin used

The breakbeam sensor used here has a maximum range of 10″. There are different sensors available that can be used. It is important to mention that the capacity at which the LED blinks is decided during the installation of the sensor. So to vary that later would mean re-installing the senors. The receiver and emitter should be in line for it to work perfectly.

Leave a Reply

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