What you need:
1PCS Arduino UNO
1PCS Laser Transmitter Sensor
1PCS Laser Receiver Sensor
6P Female to Male Dupont Cable
Connection:
Laser Transmitter Sensor Arduino UNO
S D12
+ 5V
– GND
Laser Receiver Sensor Arduino UNO
S D2
+ 5V
– GND
Code:
int LED = 13;
int LaserSensor = 2;
int SensorReading = HIGH;
int Laser = 12;
void setup() {
pinMode(LED, OUTPUT);
pinMode(Laser, OUTPUT);
pinMode(LaserSensor, INPUT);
}
void loop() {
digitalWrite(Laser, HIGH);
delay(200);
SensorReading = digitalRead(LaserSensor);
if(SensorReading == LOW)
{
digitalWrite(LED, HIGH);
}
else
{
digitalWrite(LED, LOW);
}
}
Result:
When there is an obstacle, the LED will turn on
When there is no obstacle, the LED will turn off
Where to buy:
Amazon Link:
https://www.amazon.com/dp/B07FQ6696X
https://www.amazon.com/dp/B07H95679S
Website Link:
Alibaba Link:
Aliexpress Link:
eBay Link:
Any question please email sales@diymalls.com