This tutorial describes how to create laser tripwire with an Arduino Uno. If you are unfamiliar with the Arduino platform please refer to the “Setting Up Arduino Tutorial.”

In this tutorial, you will learn how to set up a laser tripwire sensor and trigger an actuator, in this case an LED, upon the beam being broken. You will learn how to use an if/else loop, laser diodes, and a photoresistor.

WARNING: Lasers can be harmful to the eyes and you should never look directly into the beam.


  1. Arduino Uno R3
  2. “DOT” Laser Module
  3. 20 piece Photoresistor Set
  4. 9V, 1A Power Adapter
  5. Jumper Wires
  6. USB Cable (A-to-B)
  7. Breadboard

Table of Contents

  1. Circuit Design
  2. Writing the Code
    1. Pin Definitions
    2. Setup
    3. Loop
  3. Uploading and Running the Code


1.1 Circuit Design

The circuit design for this project is fairly simple. There are 3 parts of the circuit: the laser power, the photoresistor receiver (the sensor), and the LED indicator (the actuator). Microcontrollers are typically said to receive information from the outside world through sensors and to relay information or perform actions through actuators. I am choosing to use a LED indicator as my actuator, but this could be an alarm, SMS text, or even a door lock.

I always like to make a schematic (Figure 1: Circuit Schematic) using Fritzing, an open-source schematic capture and PCB routing software. This way I always have something to reference in the future. You can download Fritzing using the following link (optional):

Figure 1: Circuit Schematic

The first part of the circuit is the power for the laser diode. You can power the laser diode of the 5V pin (Red Wire). Although I want to be able to turn the laser on/off, the Digital Output pins on the Arduino do not provide enough power for my laser diode. The negative lead will go to GND (Black Wire). Make sure you don’t require a current limiting resistor for your laser diode. If you do, size appropriately.

Next, we will create our actuator (LED indicator). The purpose of the actuator is to inform us that the laser diode beam has been broken. The LED and resistor should be connected in series between Pin 9 (Light Blue Wire) and GND (Black Wire). The resistor is there to limit current through the LED and should be sized accordingly depending on your LED to prevent burning it out. Remember that the longer lead on the LED is positive and should be connected to Pin 9.

Finally, the last part of the circuit is the photoresistor (Figure 2: Photoresistor), our sensor. A photoresistor is a resistor whose values change depending on light shining on the face of the resistor. One lead should be wired to Pin 7 (Light Blue Wire) and the other lead to GND (Black Wire). The photoresistor I am using has a high resistance when light is shining on it and a low resistance when no light is present.

Figure 2: Photoresistor

2.0 Writing the Code

2.1 Pin Definitions

The first part of the code is to define the pins. This step is optional, but I chose to give the pins descriptive names so they are easy to remember and track. Also, if I ever change how the circuit is wired I only have to change the Pin Definition as opposed to changing every line of code where the pin number is mentioned.

In our circuit, the photoresistor is defined as “Pin 7” and the LED is defined as “Pin 9”.

Figure 3: Pin Definitions

2.2 Setup

In the setup part of the code, configure the LED pin as a digital output.

Figure 4: Setup Code

We also configure the photoresistor as a digital input with a pullup resistor (INPUT_PULLUP). The circuit we are creating is similar to the one below and a common electrical circuit. The pullup resistor and voltage source are internal to the MCU (Arduino) in this case and the “button” is our photoresistor. When the laser diode shines on the photoresistor, it has a high resistance and the pullup resistor pulls the voltage of the input to a digital high. When the beam is broken, the resistance of the photoresistor drops and the input voltage goes to digital low.

Figure 5: Pullup Resistor Input Circuit

2.3 Loop

For the repeating loop, I wrote an IF/ELSE statement that continuously polls the photoresistor digital input. IF the digital input is high, the LED output is off; ELSE the LED output is on.

Figure 6: Loop Code

3.0 Uploading and Running the Code

Figure 7: Arduino Circuit with Laser Tripwire

Upload the code to the Arduino. Make sure the Arduino is connected using the 9V Power Adapter as power over USB might not be sufficient to power both the Arduino and the laser diode. Once the program begins, the laser diode should be outputting a beam of light. If the beam is shining on the photoresistor, the LED will be off (Figure 8: Laser Tripwire). When the beam is broken, the LED lights up indicating the trip wire has been tripped (Figure 9: Tripwire Broken).

Figure 8: Laser Tripwire

Figure 9: Tripwire Broken

TIP: If your LED is not lighting up, use a multimeter to check the resistance of the photoresistor with the laser diode shining on it and with the beam broken. The photoresistor should have a value in the kilo-Ohms with the light hitting the photoresistor and the low hundreds of Ohms or lower.

Appendix: Laser Tripwire Code Text