How to Make a Laser Beam Alarm Security System using the Raspberry Pi Pico board

Hello and welcome back! In this project, we are going to learn how to make a Laser Beam Alarm Security System using the Raspberry Pi Pico board. This is a very simple and fun project that you can easily make at home. For this project, I used a very simple mechanism. I used a laser module and an LDR (Light Dependent Resistor) sensor to detect the laser beam. The laser beam is pointed directly onto the LDR surface. When the laser beam hits the LDR, its resistance becomes low, and the system stays in normal mode. But when something blocks or breaks the laser beam, the resistance of the LDR goes up, and the alarm system gets activated.
I have also added LED lights and a buzzer to signal when the alarm is activated. Additionally, I designed a gate-shaped PCB for this project, so there’s no need to make extra parts. This makes it easy to install the components neatly. You can even print your PCBs through JLCPCB, using their free coupons.
Also, you can use the knowledge from this project to make security systems for doorways, gates, or any other area you want to protect. This is a great beginner project for understanding how to use the LDR sensor and laser module with the Raspberry Pi Pico. For programming, I used the Thonny IDE to write the code for this project. You can also modify or improve the code as you like.
Ok, let’s do this project step by step. The required components are given below.
- Raspberry Pi Pico board x 1 — Our store / Amazon
- Laser module — Our store / Amazon
- LED bulb Red x 4 — Our Store / Amazon
- LED bulb Blue x 4 — Our Store / Amazon
- D400 Transistor x 2 — Our store / Amazon
- LDR sensor — Our Store / Amazon
- 180ohm resistor x 2 — Our Store / Amazon
- 10k resistor x 1 — Our Store / Amazon
- 1k Resistor x 2 — Our Store / Amazon
- 5V Active buzzer x 1 — Our store / Amazon
- Female header x 2 — Our store / Amazon
- Two-pin terminal x 1 — Our store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.












Step 2
Secondly, let’s order the PCBs for this project. To do that, just follow the steps below.


- Click the “Instant Quote” button and upload the Gerber file, which you can download from the link below.
- Gerber file – Download
- For this project, I ordered five Red PCBs. Next, select the build time and shipping method. Finally, click “Save to Cart” and complete the payment.






Step 3
Thirdly, unbox your PCB package and get ready to start assembling the components.




Step 4
Now, solder all the components onto the PCB carefully.





Step 5
Next, connect the laser module. To do this, gently straighten the laser module pins using a plier so they fit properly onto the PCB. Afterward, connect the Raspberry Pi Pico board to the PCB.



Step 6
Now, adjust the LDR sensor so that it aligns perfectly with the laser beam. After that, connect the Raspberry Pi Pico board to your computer.



Step 7
Now, copy and paste the following program into the Thonny IDE.
- Program — Download
from machine import Pin, PWM, ADC
from time import sleep
# --- Pin setup ---
Laser = Pin(2, Pin.OUT)
LDR = ADC(26)
LED1 = PWM(Pin(4))
LED2 = Pin(5, Pin.OUT)
Buzzer = Pin(6, Pin.OUT)
Laser.value(1)
LED1.freq(1000) # Set PWM frequency (1 kHz)
threshold = 20000 # Adjust based on calibration
while True:
value = LDR.read_u16()
print("LDR:", value)
if value > threshold: # Beam broken → Intruder detected
print("ALERT! Intruder detected!")
LED1.duty_u16(0)
for i in range(10):
LED2.toggle()
Buzzer.value(1)
sleep(0.05)
Buzzer.value(0)
sleep(0.05)
else:
LED2.value(0)
Buzzer.value(0)
LED1.duty_u16(20000) # Set brightness (range: 0–65535)
sleep(0.1)
- Next, you need to adjust the threshold value, as it depends on your lighting conditions. After that, select the correct port.

- Now, save your program on the Raspberry Pi Pico board. Make sure to save it as
main.py. Finally, click the Run button to start your project.




Step 8
After uploading the program, make the bottom support for the PCB gate. Now, you can test your project and see it in action. Ok, enjoy this project. The full video guide is below. So we hope to see you in the next project. Have a great day!




How to Make a Laser Beam Alarm Security System using the Raspberry Pi Pico board