Example Code for Arduino-LED State Reflection
Last revision 2026/01/08
The LED on 13 pin will reflect the state of the output pin of the laser photoelectric switch. Try to block the laser and watch the effect.
Hardware Preparation
| Name | Model/SKU | Quantity | Purchase Link |
|---|---|---|---|
| Laser Photoelectric Switch | FIT0319 (GAB100M-AK) | 1 | DFRobot Product Page |
| Arduino Board | - | 1 | - |
Wiring Diagram
The output pin of the laser photoelectric switch is connected to pin 10 of the Arduino board.The LED on 13 pin will reflect the state of the output pin. The Receptor will output high level when it detects laser signal.
Other Preparation Work
Connection:
- output pin(black) -- Arduino digital pin 10
- VCC pin(brown) -- VCC(+5V)
- GND pin(blue) -- GND(0V)
Sample Code
/*!
* @file FIT0319.ino
* @brief The LED on 13 pin will reflect the state of the output pin of the laser photoelectric switch.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author YouYou from DFRobot
* @version V1.0
* @date 2013-05-17
*/
/*
Connection:
output pin(black) -- Arduino digital pin 10
VCC pin(brown) -- VCC(+5V)
GND pin(blue) -- GND(0V)
*/
int led = 13;
int laserOut = 10;
void setup()
{
pinMode(led,OUTPUT);
pinMode(laserOut,INPUT);
}
void loop()
{
digitalWrite(led,digitalRead(laserOut));
}
Result
Try to block the laser and watch the effect. The LED on 13 pin will reflect the state of the output pin of the laser photoelectric switch.
Additional Information
NOTE: Class 3R are usually up to 5 mW and involve a small risk of eye damage within the time of the blink reflex. Staring into such a beam for several seconds is likely to cause damage to a spot on the retina.
Was this article helpful?
