Chìa khóa mô-đun Photo Interrupter KY-010 cho Arduino, sẽ kích hoạt tín hiệu khi ánh sáng giữa khe hở của cảm biến bị chặn.
Sơ Đồ Kết Nối
COCe Chạy Chương Trình
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);
}
}
Trả lời