Want to make a laser beam like the movies? Do they slice people in half? No, they don’t because that is dangerous. But they can act as an invisible tripwire to alert you of intruders. Add a camera to your tripwire to take a pic whenever it gets crossed, or a buzzer to ring to scare off intruders, and you have yourself a functional part of an IoT home security system.
Software SetupFor this project, you will need one, but preferably two ESP32s, a laser emitter module, and a photoresistor sensor. One ESP32 is used to detect the laser and send data to a cloud service. The other ESP32 is just used to power the laser emitter, so this can be any microcontroller board (Arduino, Raspberry Pi, etc).
I used Arduino IDE to setup my ESP32s. Simply follow this tutorial on how to install ESP32 into your Arduino IDE.
Use the Arduino IDE to install the code provided at the bottom into the appropriate ESP32. The program named LaserCode gets installed into the ESP32 being used with the laser emitter, and the program named PhotoresistorCode gets installed into the one used with the photoresistor.
Laser CodeThe laser code is very simple. Just provide an output to a specific pin to keep the laser powered on.
Photoresistor CodeThe photoresistor code requires you to add your Wi-Fi router’s SSID and password in order to connect to the cloud. You also need to include a Gateway URL from an IoT service that we will talk about later.
The program measures the resistance of the photoresistor sensor. As light intensity increases, the resistance in the photoresistor's resistance decreases. When a laser points at the photoresistor, a resistance of 0 is measured. This means that if the laser gets interrupted, there will be a resistance greater than 0 at that instance. Hence, our program detects whether the resistance is 0 and sends that info to the cloud.
Hardware SetupFollow the schematic below to wire your two ESP32s together with their appropriate sensor/module. The ESP32 with the photoresistor sensor is powered using 3.3V, but it can be used with 5.0V as well. This would allow users to attach a buzzer to that ESP32 to alarm of an intruder.
Because the laser emitter is so precise and the photoresistor is so small, typically 4.46mm × 5mm × 2.09mm (0.18in × 0.20in × 0.08in), it may be difficult to setup depending on how far you place your laser from the photoresistor. However, you can find larger photoresistors that are about 20mm long which will make setting up your project a lot easier and allow you to place the laser and the photoresistor further away from each other.
You can send the sensor data to the cloud about how often your laser gets crossed. Even better, you can create a dashboard that tells you when your room was entered, and display video and pictures if you decide to include a camera. This can all be done with the adaptive IoT platform and cloud service of uBeac. Just create a free account and follow the uBeacsetup instructions found in the OS Monitoring tutorial and you can make simple dashboards such as the one below.
If you have any suggestions about new ideas or any questions about uBeac, please leave them in the comments below. Thanks for reading and happy connecting!
Comments