Français
← Back to the sheet

A4 or Letter, portrait. Light ink: outlines only.

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

Mission 01 wiring, breadboard view Full-size breadboard seen from above. The ESP32 straddles the middle gap at the left end, USB port to the left; only the top row of holes (j) stays free next to its pins. Twelve numbered wires: 1 red from 3V3 to the red plus rail, 2 black from GND to the blue minus rail, 3 yellow from GPIO34 to the sensor row, where the photoresistor and the 10 kilo-ohm resistor meet; the photoresistor's other leg goes into the plus rail and the resistor's other leg into the minus rail. 4 orange from GPIO25 to the buzzer S pin, 5 red from the plus rail to buzzer plus, 6 black from buzzer minus to the minus rail. 7 green from GPIO26 to the 220 ohm resistor, which leads to the LED long leg; 8 black from the LED short leg to the minus rail. 9 blue from GPIO27 to one button leg, 10 black from the diagonal button leg to the minus rail. The laser is not on the breadboard: on the other side of the door, wire 11 joins the battery pack red wire to laser pin S and wire 12 the black wire to laser pin minus; the middle pin stays empty. FIG. 1 — BREADBOARD VIEW (FROM ABOVE)+−−+jihgfedcba+−−+jihgfedcba25303540455055ESP325VCMDD3D213GND1214GPIO27GPIO26GPIO25333235GPIO34VNVPEN3V3USBS+−+AB3GPIO34 → sensor row4GPIO25 → buzzer S7GPIO26 → 220 Ω → LED +9GPIO27 → button A12568103V3 → +GND → −LDR10 kΩsensor rowbuzzer module220 Ωgreen LEDbuttonLED: long leg (+) toward the 220 Ω, flat side = short leg (−).Other side of the doorNot on the breadboard, not wired to the ESP32+−+OFF3×AA pack · 4.5 VCLASS 2laser moduleS−empty111211 red (+) → S · 12 black (−) → −Middle pin: empty.Keep the pack OFF until you aim (ask for help).Wire list#COLOURFROMTO1redESP32 3V3+ rail (red)2blackESP32 GND− rail (blue)3yellowESP32 GPIO34sensor row4orangeESP32 GPIO25buzzer S5red+ railbuzzer +6blackbuzzer −− rail7greenESP32 GPIO26220 Ω → LED long leg8blackLED short leg− rail9blueESP32 GPIO27button leg A10blackbutton leg B (diagonal)− rail11redbattery pack red (+)laser S12blackbattery pack black (−)laser −Direct, no wire: LDR leg → + rail · 10 kΩ leg → − rail.
#ColourFromTo
1redESP32 3V3+ rail (red)
2blackESP32 GND− rail (blue)
3yellowESP32 GPIO34sensor row
4orangeESP32 GPIO25buzzer S
5red+ railbuzzer +
6blackbuzzer −− rail
7greenESP32 GPIO26220 Ω → LED long leg
8blackLED short leg− rail
9blueESP32 GPIO27button leg A
10blackbutton leg B (diagonal)− rail
11redbattery pack red (+)laser S (the + supply), NOT the ESP32
12blackbattery 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.

PinGoes toRole
3V3+ rail: LDR, buzzer +Power out (3.3 V)
GND− rail: 10 kΩ, buzzer −, LED, buttonGround
GPIO34Sensor row (LDR + 10 kΩ)Input, analog (0–4095)
GPIO25Buzzer SOutput
GPIO26220 Ω → green LEDOutput
GPIO27Button (other leg to GND)Input with internal pull-up

Build steps

  1. 1 Lay out your parts.

    Check: Every part in the list is on the table.

  2. 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. 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 / 27 on 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.

    Step 3: place the ESP32 The ESP32 is lowered onto the left end of the breadboard, USB port at the end, its two pin rows going into rows i and a on either side of the middle gap. A zoom shows the board's cross-section: pins in a and i, one free hole in j next to each pin. 3×1×1830+−aijOne free hole (j) beside each pin

    Check: The board sits flat and no pin is bent.

  4. 4 Rails.

    Wire the ESP32 pin 3V3 to the red (+) rail and a GND pin to the blue (−) rail.

    Step 4: power rails Two jumpers: wire 1 red from the ESP32 3V3 pin to the red plus rail, wire 2 black from a GND pin to the blue minus rail. 4×2+−123V3GND+−

    Check: Red wire on red rail, blue/black wire on blue rail.

  5. 5 Voltage divider, part 1.

    Put the 10 kΩ resistor between a free row (call it the “sensor row”) and the − rail.

    Steps 5 to 7: the voltage divider Callout 1: the 10 kilo-ohm resistor goes from the sensor row (row 30, highlighted) into the minus rail. Callout 2: the photoresistor goes from the sensor row into the plus rail, its head inside a short black tube that faces the doorway. Callout 3: yellow wire 3 joins the sensor row to GPIO34. 5–7×110 kΩ×1×1+−3123row 30 = sensor row10 kΩto the door

    Check: One leg in the sensor row, one in the − rail.

  6. 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. 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. 8 Upload the code.

    Install the board package, open the sketch, plug in the USB cable, choose “ESP32 Dev Module”, upload.

    Step 8: plug in USB and upload A USB data cable goes into the ESP32's port at the end of the breadboard; the other end goes to the computer running the Arduino IDE. 8×1data×1+−IDE

    Check: “Done uploading” appears.

  9. 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. 10 Add the buzzer.

    Unplug USB first. Buzzer S to GPIO25, + 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.

    Step 10: add the buzzer USB unplugged first. The buzzer module's three pins go into row f, columns 38 to 40. Wire 4 orange goes from GPIO25 to pin S, wire 5 red from the plus rail to pin plus, wire 6 black from pin minus to the minus rail. 10×1×3+−456S+−

    Check: Pins match the wiring table.

  11. 11 Add the green LED.

    GPIO26 → 220 Ω resistor → long leg (+) of the LED. Short leg to the GND rail.

    Step 11: add the green LED The 220 ohm resistor goes in row h from column 44 to 47. The LED's long leg goes in f47, its short leg in f48. Wire 7 green joins GPIO26 to row 44; wire 8 black joins row 48 to the minus rail. A zoom shows the long leg is plus and the flat side marks the short leg. 11×1220 Ω×1×2+−78+−long leg = +220 Ω

    Check: The long leg faces the resistor side.

  12. 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.

    Step 12: add the arm button The push button straddles the middle gap at columns 53 and 55. Wire 9 blue joins GPIO27 to leg A (bottom half, column 53); wire 10 black joins leg B, diagonally opposite (top half, column 55), to the minus rail. A zoom shows the button from above with legs A and B on a diagonal. 12×16 mm×2+−910ABwired legs on a diagonal

    Check: The two wired legs are diagonal from each other (not on the same side).

  13. 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 S and 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.

    Step 13: wire the laser (ask for help) Close-up, away from the breadboard. The 3×AA pack has its switch on OFF. Wire 11 joins the pack's red wire to laser pin S; wire 12 joins the black wire to laser pin minus (a female-to-male jumper on each pin, or a mini breadboard, makes the joint hold). The middle pin stays empty. The module is labelled Class 2. 13×1Class 2×13×AAOFFCLASS 2S−1112+−

    Check: The pack is off. Someone experienced has checked the red/black wires and the Class 2 label.

  14. 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. 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. 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.

    Step 16: aim the beam (ask for help) Seen from above: the laser on one side of the doorway and the sensor tube on the other, facing each other, the beam crossing the doorway. Side view: both at ankle height, about 10 centimetres above the floor, below knee height. A crossed-out view shows the beam at eye level: never do that. 16×1×1From abovelasertube + LDRbeamSide view≈ 10 cmknee: maxnever eye level

    Check: Number high with the beam, low when you pass a hand through.

  17. 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. 18 Test like a spy.

    Press the button, leave the room within 5 seconds, walk back in.

    Step 18: test like a spy Three moments. 1: press the button. 2: the green LED blinks for 5 seconds while you leave, then stays on. 3: walking back in, a foot breaks the beam; the buzzer sounds and the phone gets an alert. Press the button again to silence it. 18125 s3

    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)