Description
The KY-010 light barrier module / photo interrupter module is a 3-pin module that brings its signal pin HIGH when an object blocks light from traveling between its emitter and sensor. This sensor is great for detecting the swipe of a card through a slot or other applications where detecting something opening or closing is necessary.
Datasheet
Tech Specs for the KY-010 module:
- Min/Max Operating Voltage 3.3V to 5V DC
- Dimensions: 0.728in x 0.591in( 18.5mm x 15mm)
Device Pinout & Schematics
This module has three pins: GND, Vcc+, and Signal.
KY-010 Light Barrier / Photo Interrupter Code Example for Arduino
In this KY-010 Light Barrier module example code, we will write “Detected!” to the serial console when the sensor detects an object in its path.
Arduino Wiring:
- KY-010 Module GND to Arduino GND
- KY-010 Module Signal to Arduino PIN 11
- KY-010 Module Vcc+ to Arduino 5V
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 on LED when sensor is blocked
{
digitalWrite(Led,HIGH);
}
else
{
digitalWrite(Led,LOW);
}
}