1.1k
The KY-010 Photo Interrupter module consists of an optical emitter/detector. If the sensor is broken the LED is turned on.
Connection
Connect the power line (middle) and ground (left) to +5V and GND. Connect the signal (S) to pin 3 on the Arduino.
KY-010 | Arduino |
– (left) | GND |
middle | +5V |
S (right) | Pin 3 |
Code
[codesyntax lang=”cpp”]
int Led = 13; // define LED pin
int buttonpin = 3; // photo interrupter pin
int val;
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);
}
}
[/codesyntax]
Links
37 in 1 box Sensor Kit For Arduino Starters brand in stock