Intro: ESP8266 Laser Tripwire
Have you ever wanted to have a laser security alarm that will notify you when it's set off? Of course you have, that's why you're here. Well that's exactly what this Instructable is all about. We're building a simple laser tripwire powered by the increasingly-popular ESP8266 that will send a message to your phone/tablet whenever the beam is broken.
This instructable uses methods that are only available in Android, but don't despair iPhone users. In the last step I'll link you some information that you can use to get an alert via a text message instead, so you too can bask in the laser awesomeness.
Also, instead of a phone or tablet, you can interact with EventGhost. That's not covered here, but if you have EventGhost, just google AutoRemote with EventGhost.
Step 1: Prerequisites/Items Needed
For this project you will only need a few items. I've provided links to what I used on Amazon to make things easy, but you can definitely find them cheaper elsewhere, sometimes significantly cheaper.
1. ESP8266 - Specifically, I'm using the NodeMCU ESP8266 12E. - https://amzn.com/B010O1G1ES
2. A light sensor, any light sensor will do as long as it has a digital output. Note that the one I'm using reads LOW when the laser is pointing at it, and HIGH when it is not. If yours is different, you will need to adjust the code. - https://amzn.com/B00AFSAOLM
3. A LASER! - https://amzn.com/B00TMEWKPS You can get these for about a buck on ebay.
4. A mosfet or transistor. I'm using a BS170 mosfet, but an NPN transistor should work, as well. - BS170 Mosfet
5. A small mirror. Any small flat mirror will do. I used one of my wife's old makeup mirrors, just make sure it's not a magnifying mirror.
6. Wire and hardware - Hookup wire, and some small screws and little bitty springs for the mirror cell. You might be able to get around not having springs, you just need to be able to aim the laser.
7. Some sort of case to put it all in. I made mine by routing out a channel in a piece of scrap maple, but you can do whatever. I think everything will juuuuuuust about fit in an altoids tin. If you use one of the smaller ESP8266 boards, and a smaller sensor than I did, I'm sure it will squeeze in there. Then again, it's probably not a good idea to trap your wifi board inside a metal box...
There are also some prerequisites for your phone/tablet. They can be minor, or involved, depending on your customization preference. Bare minimum, you will need to download AutoRemoteLite on your Android device. (Sorry, no iPhone equivalent that I'm aware of. ¯\_(ツ)_/¯ ), as well as the apk attached to this instructable.
AutoRemoteLite - https://play.google.com/store/apps/details?id=com....
AutoRemote is a messaging service that can receive messages from the internet and pass them to an app called Tasker so it can... do things. You don't have Tasker? No worries, that's what the attached apk is for. It's a small app, made with Tasker's app factory, that will monitor for incoming messages and respond with a notification that the laser has been tripped. Don't worry, battery impact should be nill.
If you wan't more customization, you can purchase Tasker and the full version of AutoRemote and go to town! You can set it up to send you a text, email your mom, feed your dog, whatever you want.
Step 2: Connections
The code is set up to use the NodeMCU's D1 and D2 pins. If you have a different board, or if you have an irrational hatred for pins D1 and D2, you can adjust the code to use whatever. Just look for the PIN ASSIGNMENTS part of the code.
Because of the relatively high current draw of the laser, compared to say, an LED, we need to run it with a transistor or mosfet. I don't recommend trying to run the laser straight from the board's D1 pin. I have successfully ran these from an arduino pin, but the arduino can handle higher currents. The NodeMCU, and any ESP8266 board, will only handle about 12ma, and the laser needs about 30ma to function properly. Running the laser from the pin directly will result in a dim beam, and possibly a burnt out pin.
Step 3: The Mirror
Since the laser and the sensor are on the same board, we need to bounce the beam back to the sensor. This is more complicated to set up and aim than making the laser separate, but by doing it this way, we can use a single power supply, and we can control the laser based on what's happening. ie, the laser turns off when you break the beam so your cat/child won't accidentally blind themselves by walking through it.
The mirror mount is based on the same concept used to adjust small telescope mirrors. Three screws/springs hold the mirror to the base plate and tightening/loosening the screws adjusts the angle of the mirror. It's hard to explain, so I'll let the pictures do that.
Step 4: Setting Up AutoRemote
Download AutoRemote to your device, then open it up and follow along with the pictures. When you copy the key, make sure you do not copy the = or the &, only what's in between them. When you paste it into the code, make sure you paste over the <> brackets.
Step 5: The Code
The code is available here, GitHub ESP8266 Laser Tripwire
Upload the code via the arduino IDE. If you haven't programmed an ESP8266 using arduino before, the process is very simple. First you must install the ESP8266 boards to your IDE. In the arduino IDE, just click tools, boards, board manager, then search for ESP8266 and install. Done. Then you select your board, in this case NodeMCU 1.0, and upload as normal. Note that the code will not compile until you have selected an ESP8266 board.
The code itself is pretty simple. In a nutshell, when power is applied, the laser will fire in short pulses until it hits the sensor, then it will stay on. The reason for the pulses is to help reduce accidental eye exposure while aiming, and to let you know that the laser is not yet armed. Once it finds the sensor, the beam is armed. When the beam is broken, the laser turns off and the ESP8266 requests a specific web page that will send the alarm message to your device and trigger the notification. After a short delay, the laser turns on again and resumes normal operation.
Step 6: Install App
Install the attached app to your phone/tablet. There's no configuration requirements, it's ready out of the box. When you get a message from AutoRemote, it will pop up with your regular notifications and play the system default sound.
Make sure you check the allow unknown sources setting in your phone, or you won't be able to install apps from outside the play store. Each phone is a little different, but it's probably in your security settings.
As I mentioned, Autoremote also works with EventGhost, so you can get notifications on you PC instead, but I haven't tried it. If you know what EventGhost is, you probably know how to figure it out.
Step 7: Put It All Together
Now just find something to protect and set everything up. You can watch this short video to see how everything works. Thanks for looking!
Step 8: IPhone Users, or Anyone Who Would Rather Receive a Text
If you have an iPhone, or if you'd just rather receive a text instead of installing apps on your phone, you can check out this page on how to use the ESP8266 to send text messages via Twilio. Sorry, I have not used this method, so you'll have to do some work to make it happen.