Introduction: HackerBox 0054: Smart Home
Greetings to HackerBox Hackers around the world! HackerBox 0054 explores home automation through smart switches, sensors, and more. Configure Sonoff WiFi smart switches. Modify smart switches to add programming headers and flash alternate firmwares. Set up Home Assistant, MQTT, and integrate smart home hubs like Amazon Alexa or Google Home. Assemble DIY WiFi smart nodes using Wemos ESP8266 modules. Configure WiFi smart nodes as switch control points, sensors points, or both. Explore multiple sensor options for smart home operations. Experiment with pulse oximetry and heart-rate monitoring.
This guide contains information for getting started with HackerBox 0054, which can be purchased here while supplies last. If you would like to receive a HackerBox like this right in your mailbox each month, please subscribe at HackerBoxes.com and join the revolution!
HackerBoxes is the monthly subscription box service for hardware hackers and enthusiasts of electronics and computer technology. Join us and live the HACK LIFE.
Step 1: Content List for HackerBox 0054
- Two Sonoff Basic WiFi Smart Switches
- Two Wemos D1 Mini ESP8266 Modules
- Two Wemos D1 Mini Relay Shields
- Two Wemos D1 Mini Prototype Shields
- Two Mains AC to 5V DC Power Adapters
- FTDI Serial USB Module
- MAX30100 Pulse Oximeter Heart Rate Module
- MH-SR602 PIR Motion Sensor Module
- Water Sensor Module
- Two DS18B20 Digital Temperature Sensors
- Two 4.7K Resistors
- Male-Female DuPont 10cm Jumpers
- Exclusive Vinyl Webcam Spy Blocker Sheet
- Exclusive HackerBox HackLife Iron-On Patch
Some other things that will be helpful:
- One or two two-prong AC extension cords
- Soldering iron, solder, and basic soldering tools
- Computer for running software tools
Most importantly, you will need a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.
As always, we request that you review the HackerBoxes FAQ. There, you will find a wealth of information for current and prospective members. Almost all of the non-technical support emails that we receive are already answered in the FAQ, so we really appreciate it if you have a quick look.
Step 2: Home Automation With Sonoff Smart Switches
Sonoff Basic Smart Switches are remote control power switches that support Smart Home functionality by switching power for almost any electrical device according to messages sent over WiFi. Sonoff Basic Smart Switches comprise an ESP8266 WiFi microcontroller, a power relay to switch the load on and off, and a tiny AC to DC power converter to supply the microcontroller and relay from the same line that is being switched.
CAUTION: Smart switch devices connect to your home mains power. Mains power can be dangerous. You should understand the implications of connecting devices to mains power. Do not ever work on a device while it is connected to the mains power source. Do not attempt to adjust, modify, or program a device while it is connected to a mains power source. If you lack the experience or comfort to safely work with mains power, please have someone with the proper expertise join in to help you out. SAFETY FIRST!
A good starting point, is to put together a "switchable extension cord" as shown in the drawing. Note that an AC mains power line has an N (NEUTRAL) CONDUCTOR which is usually WHITE. It also has an L (LINE, LIVE, HOT) CONDUCTOR that is usually BLACK. There may also be a G (GROUND) CONDUCTOR that is usually GREEN or BARE METAL. The N CONDUCTOR connects to the wider plug blade and the ribbed or marked insulating jacket. Keep these in mind while connecting to the L and N screw terminals of the Sonoff Smart Switch.
Be sure to screw down the plastic housing ends of the Sonoff Smart Switch so that the teeth inside grip onto the insulating jacket of the mains conductors. This provides a strain relief that helps prevents a live wire from being pulled loose which could then cause damage or injury. If the cord or appliance being switched has a third GROUND conductor, be sure the ground on both sides of the Sonoff Smart Switch are connected together (bypassing the switch).
The default app that communicates with, and controls, Sonoff Smart Switches right out of the box is eWeLink.
Step 3: Hack the Sonoff
There are solder holes for a header on the board inside the Sonoff smart switch. The header includes power, ground, TX, and RX. These can be used to reprogram the ESP8266. The button on the Sonoff Smart Switch connects to GPIO0, so it can be used to boot the ESP8266 into programming mode.
It is suggested to use a female header on the Sonoff Smart Switch board. Since there are high voltages on the board while in use, we do not want a bent male header pin to short anything out.
Remember to completely disconnect the mains power supply before opening the Sonoff smart switch. Once the switch had been programmed, seal it completely back up into its housing prior to reconnecting the high voltage mains supply.
Video: Connecting to the Sonoff Header
There are a number of different firmwares that can be loaded onto ESP8266-based Smart Switches for your hacking pleasure. One of the most popular is Tasmota (see About Tasmota on the project's site).
Video: Loading Tasmota to Sonoff
Video: Complete Guide to Tasmota
Step 4: Home Assistant and MQTT
Home Automation Software facilitates control of common appliances found in a home, office, or sometimes a commercial setting, such as lights, HVAC equipment, access control, sprinklers, and other devices. It usually provides for scheduling tasks, such as turning sprinklers on at the appropriate time, and event handling, such as turning lights on when motion is detected.
Two common Home Automation platforms are Home Assistant and openHAB. They are both open source and very full featured. We will look more into Home Assistant.
Video: Home Assistant Beginners Guide
MQTT (Message Queuing Telemetry Transport) is a lightweight, publish-subscribe network protocol for transporting messages between devices.
Video: Understanding MQTT in Home Assistant
Step 5: DIY Smart Switch With Wemos D1 Mini
The Wemos D1 Mini is a popular ESP8266 module with built in WiFi support and USB interface. It can be easy programmed via the Arduino IDE and other platforms supporting the ESP8266.
An ESP8266 module, such as the Wemos D1 Mini, can be connected to a relay to provide the same functionality as the Sonoff Smart Switch. Such a configuration also provides serval additional GPIO pins. These IO pins can support connection of sensors (inputs), indicators/actuators (outputs), additional relays, and various other devices.
Furthermore, the relay can be used to switch any type of signal, not just the powering mains voltage. Switching other signals can support controlling air conditioning systems, irrigation/sprinklers, garage doors, access/gate locks, and low voltage lighting such as landscape or pool lights. There are many examples online of projects like these.
The Wemos D1 Mini can be powered by any adequate 5V supply, such as a "wall wart" phone charger, via the microUSB port. Alternatively, a small AC to DC power adapter (very much like the one built into the Sonoff Smart Switch) can be used for power. However: Extreme care must be taken when carefully connecting mains power to the power adapter. Also, an enclosure must be provided to protect and isolate the power adapter before the mains power is activated.
Step 6: Sensors Useful for Home Automation
Motion Sensor
The MH-SR602 is a passive infrared sensor (PIR sensor). PIRs measure infrared (IR) light radiating from objects in their field of view. They are most often used in PIR-based motion detectors. PIR sensors are commonly used in security alarms and automatic lighting applications. All objects with a temperature above absolute zero emit heat energy in the form of radiation. Usually this radiation isn't visible to the human eye because it radiates at infrared wavelengths, but it can be detected by electronic devices such as PIRs.
This example demonstrates how to use a PIR motion sensor module in an Arduino project. Since the MH-SR602 PIR Motion Sensor operates in the voltage range of 3.3V-15V. It can be used with 3.3V supply and signaling with the Wemos D1 Mini (ESP8266) or with a 5V Arduino.
Water Sensor
This demo project for the Water Sensor pretty much speaks for itself. The sensor module operates with either 3.3V or 5V. The output can be sensed using any analog input pin and the Arduino analogRead() function.
Temperature Sensor
The DS18B20 is a temperature sensor that can be used in a variety of applications. The sensor communicates using the 1 wire (I2C) bus and only requires one 4.7K pull up resistor to operate. This example project demonstrates interfacing the DS18B20 with the Wemos D1 Mini.
Step 7: Pulse Oximeter and Heart-Rate Monitor
Pulse oximetry is a noninvasive method for monitoring a patient's oxygen saturation. Though its reading of peripheral oxygen saturation (SpO2) is not always identical to the more desirable reading of arterial oxygen saturation (SaO2) from arterial blood gas analysis, the two are correlated well enough that the safe, convenient, noninvasive, inexpensive pulse oximetry method is valuable for measuring oxygen saturation in clinical use.
The MAX30100 (or MAX30102) is an integrated pulse oximetry and heart-rate monitor biosensor module. It includes internal LEDs, photodetectors, optical elements, and low-noise electronics with ambient light rejection. The MAX30100 provides a complete system solution to ease the design-in process for mobile and wearable devices.
This example project illustrates interfacing the MAX30100 module to the Wemos D1 Mini.
NOTICE: The MAX30100 module, as with any DIY solution, is only intended for educational experimentation and demonstration purposes. These demonstration units are absolutely not medical devices and should not be relied upon for diagnosis or any other clinical purpose. Always consult your licensed medical practitioner for more information.
Step 8: Hack the Planet
We hope you are enjoying this month's HackerBox adventure into electronics and computer technology. Reach out and share your success in the comments below or on the HackerBox Facebook Group. Also, remember that you can email support@hackerboxes.com anytime if you have a question or need some help.
What's Next? Join the revolution. Live the HackLife. Get a cool box of hackable gear delivered right to your mailbox each month. Surf over to HackerBoxes.com and sign up for your monthly HackerBox subscription.