Friday 16 December 2016

IoT Home Alarm based on ESP8266


  • Multipurpose board - same PCB different flavours
  • Based on the well known ESP12F (ESP8266) module
  • Can run on batteries (2xAAA) or on power supply
  • Very low power consumption when running on batteries thanks to the deep-sleep feature
  • Capable of updating software through Wi-Fi




Depending on how the board is populated, it can act as:

Window/door status sensor using reed-switch. A notification is triggered when the door is closed AND when it's open. The controller software knows the window/door status at any time.
Tamper protection using an additional reed-switch. It triggers an alarm if the device is being attacked with an external magnetic field in an attempt to fool the door status switch.
Another lever switch can sense if the case is being opened or removed from its location.

Temperature/humidity sensor using the DHT22 module
Temperature only using the Dallas/Maxim DS18B20 sensor
The DS18B20 sensor can coexist with the window/door alarm version of the board

Twin relay output board
This version of the board cannot run on batteries. It must be supplied with a 5V dc source. A regulator will provide 3.3V for the ESP12F module.

This is an early stage prototype of the relay board - PCB by OSH Park

Some versions of the board could be associated, such as:


  • Window/door alarm + DS18B20 temperature sensor - runs on both batteries and external power supply
  • Relay board + DS18B20 temperature sensor - runs on external 5V only
  • Relay board + DHT22 temperature/humidity sensor - runs on external 5V only


Depending on the position of the JP4 jumper, power supply for the sensors DHT22 and DS18B20 can be taken straight from the 3.3V rail or from an ESP12F pin. This can help saving battery power by switching off the sensors if they are not needed; typical case is when the module is in the deep-sleep status.

DHT22 temperature and humidity board - early prototype PCB by OSH Park

All PCBs used for this advanced prototype were manufactured by the chinese company PCBWay.

PCB layout

Schematic diagram explanation


The schematic diagram pictured above represents the whole system, reflecting the PCB design. However it is never assembled in full.
Depending on the version of the circuit, only some of the components are actually populated (soldered) on the PCB.

Window/door alarm: in this version the relay part of the diagram is not relevant. All related components are not implemented.
The window/door status is sensed by S1 (reed-switch). R3 - C2 are a low-pass filter useful to get rid of RF noise that could be picked-up by the EX-OR gate due to high impedance of the input stage.
Pull-up resistor R1 value must be kept as high as possible in order to minimize battery consumption. In my tests I used both 1M or 2M2 resistors with good results.
IC1A PIN 3 provides the actual window/door status to GPIO4 of the ESP12F module. GPIO4 status is sampled as soon as the ESP12F wakes-up from deep-sleep and its status sent to the controller software through Wi-Fi.
The stage made with R7, C5, IC1B is a frequency doubler. It generates a 40mS pulse each time S1 closes or opens. It wakes-up the ESP module by providing a reset pulse, when the window/door is opened AND when is closed.

The stage made around IC1D is the tamper sensing section. It acts in a very similar way to the window/door switch. The tamper lever switch and S2 reed-switch are both normally open.
If a tamper attempt is made, one or both of them close generating a reset pulse of 40mS through IC1C and waking-up the ESP module.

Relay output board: in this version, the left-hand part of the diagram, the one related to window/door alarm is not relevant. The related components will not be populated on the PCB.
K1 and K2 are driven by the MOSFETs Q1 and Q2. LEDs D2 and D3 light up when their related relays become energized.
The relays are driven by the same GPIOs used in the window/door alarm version of the board, that is GPIO4 and GPIO5. In this case these GPIOs are configuraed as outputs rather then inputs.

Temperature/humidity sensors: this version of the board is very simple. Temperature sensing can be made with DS18B20 or DHT22 sensors. They are mutually exclusive.
Humidity measurement can be made with DHT22 only. They both use the same GPIO12.
The position of JP4 jumper selects whether the sensor power is taken from 3.3V rail or from GPIO14.

All relevant files can be downloaded here:

https://github.com/glcos/IAA

WARNING:
The purpose of this project is to practice and play (why not) with ESP8266 MCU. It is a hobby project for electronics enthusiasts.
This board does not replace a professionally engineered alarm. Do not rely on it.
It will not prevent bad guys from sneaking into your house.
BUILD AND USE IT AT YOUR OWN RISK!