The first thing you'll need to do is build all the sensors and prepare the Raspberry Pi 3. The sensors consist of a reed switch, a voltage divider, a Feather HUZZAH ESP8266 or ESP8266 breakout, a LiPo backup battery, a power supply, and a half-size breadboard (you can solder all the wiring together if you prefer).

First, we need to build the voltage divider out of 1M Ohm and 470K Ohm resistors. 3.3v is connected from the ESP8266 to one side of the door/window open reed switch. The other side of the switch is wired to the voltage divider (more on the voltage divider below). Here is a schematic of the wiring:

The voltage divider reduces the 3.3v range coming out of the reed switch to the 0-1v range needed by the analog pin on the ESP8266.

This schematic uses the Analog pin to sense whether the reed switch is open or closed, you can also use any digital I/O pin. If you're sensing a light or photocell temperature sensor, you'll want to stick with analog input. Adjust your design as necessary!

Now, I used half-sized solderless breadboards (Adafruit Product ID 64) for building my alarm system sensors. As an alternative, you can solder the voltage divider and reed switch directly into the circuit using your preferred low-voltage wiring (I'd recommend 22 AWG hook-up wire - Adafruit Product ID 1311). This is particularly easy if you don't solder headers into the ESP8266 board you're using.

Just follow the schematic to build the sensors. Remember, you'll need one sensor for each door and window you want to protect. We'll modify the Lua code going onto each sensor to configure a unique sensor ID for each device. The Python program, which runs on the Raspberry Pi, has a translation table from sensor IDs to human-meaningful text, e.g., sensor ID "sensor001" = "front door." This allows the program to insert a useful message into the Adafruit.IO topic queue (more about that in a bit).

These are really very simple circuits to build. The most complicated part is the voltage divider. There is a useful WikiPedia article on voltage dividers, and there are many voltage divider calculators on the Internet. The one I used to design the sensor's voltage divider is from Learning About Electronics.

Of course, if you know the formula for the calculation, you can just use that directly. I'm not a EE, though, so I'd have had to look it up anyway. Incidentally, the voltage divider is the first "project" in Hayes and Horowitz's classic "Learning the Art of Electronics" (Adafruit Product ID 3066) - it starts on page 11.

Test the voltage divider by applying 3.3v to Vin and measuring the voltage between the two resistors with your meter. It should read about one volt. Once that's working correctly, connect 3.3v to one side of the reed switch and connect the other side to Vin of the voltage divider. Connect one side of R2 to R1 and the other to ground. Finally, connect Vout (the connection between the two resistors) to the single Analog pin on the ESP8266. The voltage divider assures that we will not exceed the ESP8266's input voltage restriction on the analog pin.

You will also need to set up or have available a Raspberry Pi 2 or 3 (I use a 3) to run the MQTT broker and the Python program. Follow the usual process for configuring Jessie on the Raspberry Pi and connect it to your network. Wired or wireless will do, though for bandwidth reasons I used a wired connection.

That's it! It's really quite simple. 

Next: Programming the ESP8266 with Lua

This guide was first published on Jun 23, 2016. It was last updated on May 01, 2024.

This page (Building the Hardware) was last updated on May 27, 2016.

Text editor powered by tinymce.