How to use the Photo Interrupter Sensor with Arduino
How to use the Photo Interrupter Sensor with Arduino
INTRODUCTION
A Photo Interrupter sensor (or Photogate) consists of an infrared LED and a phototransistor with a gap in between the two sides. The sensor is a form of contactless switch which turns on when an object placed in the gap between the LED and the phototransistor causing the connection between the light sending source (infrared LED) and the light receiving source (phototransistor) to be disrupted.
APPLICATIONS
One of the common applications is the counting of passing objects. When an object passes through the gap of the sensor, the processor can be programmed to keep track of the number of times the light source was disrupted and add it to the counter. Another common application is detecting open and closed positions of doors just like an impact switch sensor.
WIRING DIAGRAM
VCC – 5V
OUT (Pin labeled S on the sensor) – Digital Pin 3
GND - GND
CODE
int Led = 13; // define LED pin int buttonpin = 3; // define photo interrupter signal pin int val; //define a numeric variable void setup() { pinMode(Led, OUTPUT); // LED pin as output pinMode(buttonpin, INPUT); //photo interrupter pin as input } void loop() { val=digitalRead(buttonpin); //read the value of the sensor if(val == HIGH) // turn LED on when sensor is blocked { digitalWrite(Led,HIGH); } else { digitalWrite(Led,LOW); } }
END RESULT
Observe the built-in LED of the Arduino switching ON/FF when you place an object (like a piece of paper) in the gap of the Photo Interrupter Sensor.
ADDITIONAL RESOURCES
https://arduinomodules.info/ky-010-photo-interrupter-module/
https://www.instructables.com/id/How-to-use-photo-interrupters-with-your-ARDUINO/
https://www.rohm.com/electronics-basics/photointerrupters/what-is-a-photointerrupter