Skip to main content

Infrared (IR) break-beam sensor

Infrared (IR) break-beam sensors are an easy way to detect movement. This sensor has a transmitter and receiver part. Point the transmitter at the receiver to create a light beam that will trigger the receiver if this bundle is interrupted.

KW-1516-1-1400x1050w.jpg

For this test i didn't use an LED as mentioned in the code and tutorial (see sources bottem of the page)
You can leave it out of the setup if you don't need it and connect the data(yellow wire) directly to pin 5 (digital) on the arduino.
Because it works with infrared light, use it indoors and close the curtains and maybe don't use halogen lights ;) I made that mistake.

 

code:

void setup() {
  
  Serial.begin(9600);
  pinMode(5, INPUT_PULLUP);
  pinMode(13, OUTPUT);

}

void loop() {

  int val = digitalRead(5);

  if (val == 0) //Beam is broken
  {
    digitalWrite(13, LOW);
  }
  else
  {
    digitalWrite(13, HIGH);
  }

  Serial.print("The value of pin 5 is: ");
  Serial.println(val);

  delay(100);


}

 

You can borrow this sensor for testing at the Blackbox location IBB. Contact: blackbox.ibb-pastoe@hku.nl

 

source: 

https://www.kiwi-electronics.com/nl/infrarood-straal-detector-5mm-leds-1577?search=kw-1516

https://www.youtube.com/watch?v=GWdDeB7Sltw

https://github.com/nickredsox/youtube/blob/master/Arduino/IR%20Beam/ir_beam_arduino/ir_beam_arduino.ino