Tinker Mission · Projects 02
Laser alarm
Guard a doorway with a laser line. When someone crosses the low laser beam, a buzzer sounds and your phone gets an alert.
- Level 2
- One afternoon (3–4 h · estimate)
- About 30–60 CAD (estimate)
- Ask for help: steps 13 and 16
Links
- Online sheettinkermission.com/en/projects/laser-alarm/
- The codetinkermission.com/sketches/02-laser-alarm.ino
- The lesson: Voltage, current, resistancetinkermission.com/en/lessons/voltage-current-resistance/
Scan a code with a phone camera to open the online sheet, download the code or read the lesson.
Safety first
- Not built by us yet. Younger makers: an adult follows every step of this sheet.
- Class 2 laser only (1 mW or less, class printed on the label or the listing). No class shown, or 5 mW: do not use it.
- Beam at ankle height, pointing into the sensor tube. Never at eyes, people or pets. Never look into the beam. No mirrors.
- Switch the pack off when not in use. Don't run it with pets or toddlers around. Indoors only, never toward windows, vehicles or aircraft.
- Power: a 3×AA pack for the laser; a USB power bank or the computer for the board. Never a bare LiPo cell.
- Unplug before you rewire. Keep small parts and wires away from pets and from anyone who might put them in their mouth.
Parts
- ×1 ESP32 boardESP32-WROOM-32 DevKit, 38 pins, USB (micro-USB or USB-C), 3.3 V logic. Clones may have a different pin order: check the labels printed on your board.
- ×1 Laser moduleRed 650 nm dot laser module, 5 V. Buy only a module whose label or listing says Class 2 (≤ 1 mW). If the listing shows no class, or shows 5 mW, do not buy it: most cheap 3-pin modules are 5 mW (Class 3R) and unlabelled.
- ×1 3×AA battery holder3-cell AA holder with on/off switch and bare or JST wires; 3 AA alkaline batteries (not included). 3×AA gives about 4.5 V for a 5 V module: to confirm when we build it.
- ×1 Photoresistor (LDR)GL5528 type, 5 mm
- ×1 10 kΩ resistor10 kΩ, 1/4 W, through-hole, 5 % or better
- ×1 220 Ω resistor220 Ω, 1/4 W, through-hole
- ×1 Green LED5 mm green LED, through-hole
- ×1 Active buzzer moduleActive (built-in tone) buzzer module, 3 pins S / + / −, 3.3–5 V, sounds when S is HIGH. If it buzzes right at power-up, it is low-trigger: return it or swap HIGH/LOW in the code.
- ×1 Push button6 mm tactile switch, 4 legs
- ×1 BreadboardFull-size 830 points. A 38-pin ESP32 leaves a free hole on one side only; board too wide? Use two breadboards side by side.
- 1 set Jumper wires (male-to-male)Male-to-male, about 10–20 cm, 20 wires or more
- ×5 Jumper wires (female-to-male)Female-to-male, about 20 cm or longer. The battery holder wires will not hold on the laser's male pins by themselves (a mini breadboard also works there).
- ×1 USB cableData cable (not charge-only) matching the board's port
- ×1 USB power bank (optional)Any 5 V power bank
Tools
- Computer with Arduino IDEArduino IDE 2.x + “esp32 by Espressif” 3.3.x (free download from arduino.cc)
- Small screwdriverSmall Phillips (or flat)
- Multimeter (optional)Any basic digital multimeter
- 3D printer (optional)Black PLA. No printer: a black straw or rolled black paper works
- Tape (optional)Masking tape or blue tack
Wiring
| # | Colour | From | To |
|---|---|---|---|
| 1 | red | ESP32 3V3 | + rail (red) |
| 2 | black | ESP32 GND | − rail (blue) |
| 3 | yellow | ESP32 GPIO34 | sensor row |
| 4 | orange | ESP32 GPIO25 | buzzer S |
| 5 | red | + rail | buzzer + |
| 6 | black | buzzer − | − rail |
| 7 | green | ESP32 GPIO26 | 220 Ω → LED long leg |
| 8 | black | LED short leg | − rail |
| 9 | blue | ESP32 GPIO27 | button leg A |
| 10 | black | button leg B (diagonal) | − rail |
| 11 | red | battery pack red (+) | laser S (the + supply), NOT the ESP32 |
| 12 | black | battery pack black (−) | laser −, NOT the ESP32 |
No wire needed: the LDR's other leg goes straight into the + rail, the 10 kΩ's other leg into the − rail. The laser's middle pin stays empty. Check your laser's pinout: on S / middle / − modules, S is the + supply.
| Pin | Goes to | Role |
|---|---|---|
| 3V3 | + rail: LDR, buzzer + | Power out (3.3 V) |
| GND | − rail: 10 kΩ, buzzer −, LED, button | Ground |
| GPIO34 | Sensor row (LDR + 10 kΩ) | Input, analog (0–4095) |
| GPIO25 | Buzzer S | Output |
| GPIO26 | 220 Ω → green LED | Output |
| GPIO27 | Button (other leg to GND) | Input with internal pull-up |
Build steps
1 Lay out your parts.
Check: Every part in the list is on the table.
2 Make the sensor tube.
Roll black paper into a tube about 3 cm long and 6 mm wide inside (or print one in black PLA, or cut a black drinking straw). The LDR will sit at the bottom.
Check: The LDR is at the end, and no side light gets in.
3 Place the ESP32.
Press the board across the middle gap of the breadboard, so each row of pins has its own holes. Put the side with
3V3/GPIO34/25/26/27on the side that keeps a free hole. Board too wide? Use two breadboards. Clones may have a different pin order: check the labels printed on your board. USB port at the end of the breadboard, no cable yet.Check: The board sits flat and no pin is bent.
4 Rails.
Wire the ESP32 pin
3V3to the red (+) rail and aGNDpin to the blue (−) rail.Check: Red wire on red rail, blue/black wire on blue rail.
5 Voltage divider, part 1.
Put the 10 kΩ resistor between a free row (call it the “sensor row”) and the − rail.
Check: One leg in the sensor row, one in the − rail.
6 Voltage divider, part 2.
Put one LDR leg in the sensor row and the other leg in the + (3V3) rail. LDR legs have no direction. The sensor has to reach the doorway: set the breadboard on the floor by the door frame (USB power bank there), or extend the LDR with two long female-to-male jumpers.
Check: The sensor row now holds one resistor leg and one LDR leg.
7 Connect to the board.
Jumper from the sensor row to
GPIO34.Check: Three things meet in the sensor row: resistor, LDR, wire to GPIO34.
8 Upload the code.
Install the board package, open the sketch, plug in the USB cable, choose “ESP32 Dev Module”, upload.
Check: “Done uploading” appears.
9 Test the sensor.
Open the Serial Monitor at 115200 baud. Cover the LDR with a finger, then uncover it.
Check: The number drops when covered and rises when uncovered.
10 Add the buzzer.
Unplug USB first. Buzzer
StoGPIO25,+to the 3V3 rail,−to the GND rail. If it buzzes as soon as you power up, it is a low-trigger module: return it or swap HIGH/LOW in the code.Check: Pins match the wiring table.
11 Add the green LED.
GPIO26→ 220 Ω resistor → long leg (+) of the LED. Short leg to the GND rail.Check: The long leg faces the resistor side.
12 Add the arm button.
One leg to
GPIO27, the opposite leg to the GND rail. No resistor needed: the code turns on the board's internal pull-up.Check: The two wired legs are diagonal from each other (not on the same side).
13 Wire the laser. · Ask for help
Class 2 only: the label or listing must say Class 2 (≤ 1 mW); no class, or 5 mW, do not use it. Check your module's pinout: on S / middle / − modules, S is the + supply. Push a female-to-male jumper onto pin
Sand one onto pin−, then join S to the red wire of the battery pack and − to the black wire (or use a mini breadboard). The middle pin stays empty. Keep the pack switched off, and switch it off whenever you are not using it. Don't run it with pets or toddlers around.Check: The pack is off. Someone experienced has checked the red/black wires and the Class 2 label.
14 Set up the phone.
Install the free ntfy app, subscribe to a topic you make up (random letters and numbers, no names). Anyone who guesses it can read it.
Check: The topic appears in the app.
15 Fill in the code.
Type your Wi-Fi name, password and the same topic into the sketch. Use a 2.4 GHz Wi-Fi network (the ESP32 does not do 5 GHz). Upload again.
Check: The topic in the code matches the app exactly.
16 Aim the beam. · Ask for help
Put the sensor tube on one side of the doorway and the laser on the other, both at ankle height, the laser pointing into the tube. Set the breadboard on the floor by the door frame (USB power bank there), or extend the LDR with two long female-to-male jumpers. Indoors only, never toward windows, vehicles or aircraft; no pets or toddlers around. Switch on the pack and watch the Serial Monitor: the number jumps up when the dot is in the tube. Write down this “lit” number (laser on target) and the “dark” number (hand in the beam). Switch the pack off when you are done.
Check: Number high with the beam, low when you pass a hand through.
17 Set the threshold.
Pick a number halfway between your “lit” and “dark” numbers (from step 16) and put it in
threshold. Upload again.Check: The threshold is between the two numbers.
18 Test like a spy.
Press the button, leave the room within 5 seconds, walk back in.
Check: LED blinks, then stays on; the buzzer sounds and the phone alert arrives. Press the button to silence and disarm.
My notes
Lit (laser on target)
Dark (hand in the beam)
Threshold (halfway)