I have been working for some time on a Raspberry Pi based, open source indoor air quality monitor (CO2, temperature, humidity, air pressure) called LiV Pi.
LiV Pi is a connected device that offers an intranet website, device control over XMPP/Jabber, email and twitter alerts, support for major IoT platforms, IFTTT integration and much more... LiV Pi is powerful and flexible, however setting up LiV is a long and difficult process for those with limited knowledge of Linux.
Based on my experience with LiV Pi, I wanted to build a simple, reliable and easy to set up device that can be used for home monitoring and home automation. Livduino should also be easy to modify and adapt.
I will document here each stage of this project. At the end of the project, I will update the components' list and I will upload the schematics and code to Github.
Next photo shows LiVduino breadboard at the begging of July.
I started work on a device that can measure temperature, humidity and luminosity. LiVduino will be a connected device, able to send measurements data to various IoT platforms and control (switch on/off) other devices. This seems like a good starting point that would allow a good number of automation applications:
- switch on/off fan (or AC unit or heater) when temperature level reaches threshold
- switch on/off humidifier/de-humidifier when humidity level reaches threshold
- switch on/off lamp when light measurement reaches threshold
From the very beginning, I made a few design decisions:
- I decided to stay away from analog sensors and sensor calibration in general and use digital, pre-calibrated sensors instead.
- I also decided in favour of using I2C devices whenever possible.
- In terms of Arduino platforms, I chose to go with the popular Atmega 328 (there are so many Unos and Nanos out there).
I started with an Arduino Uno connected over I2C to a real-time clock module (DS3231) and an LCD1602, which I had handy (see next photo).
Once I had this setup working (thank you Adafruit for your nice libraries!), I ordered a couple of temp/humidity modules (SHT-31 and HTU21D), a luminosity module (TSL 2561) and one 128x64 OLED screen (SSD1306). I selected all those based on online reviews, availability of libraries (thanks again to Adafruit, Sparkfun and the great Arduino community!) and because all of them have I2C interfaces. I decided to ditch LCD1602 in favour of SSD1306 which has smaller form factor and draws less current.
I connected an Arduino Nano to my sensors. Next photo shows measurements being displayed on the screen. I also added a buzzer, so I can get an audio alarm whenever thresholds are exceeded. There are three measurements displayed on the screen (T, H, L), so I need a visual indication when I hear the buzzer and I want to know which measurement(s) triggered the alarm ( you can see the ">" symbol in front of "L").
I then added a button so that I can stop the buzzer from sounding. The visual alarm still shows on the screen, however the buzzer can not be heard any longer when the button is pushed. I also added a new page that displays the date/time and the state of the Buzzer (if button is pushed, the state is OFF, so the buzzer stays silent when an alarm is raised).
I plan to control a Sonoff switch with LiVduino in the future, so I will add another push-button that will show if automation via Sonoff is on or off.
First picture shows the breadboard with all the parts.
I bought a Sonoff device (second photo). I installed Easy ESP on it and I was able to switch it on and off using HTPP commands sent from my web browser: so far, it seems to be working pretty nicely.
I already had a NodeMCU which I am planning to use so I can send commands to Sonoff. Third photo shows my NodeMCU connected to an Arduino Uno over serial comm. The idea is to send commands from Nano to NodeCMU and then have NodeMCU control Sonoff over WiFi.
The small module in between NodeMCU and Arduino Uno is a voltage level adapter (3.3V to 5V).
I installed ESP Easy on Sonoff and configure it with a fixed IP address. I then wrote an Arduino sketch that switches Sonoff on and off every 5 seconds. You can find the code and a file describing the rules on Sonoff on GitHub (see code section below).
Last part to take care of in this project was the serial communication between Nano and NodeMCU. Processors on both sides are little endian, so even if the default data alignment at compile time is different, I was able to define a structure that can be accessed on both sides. (no data padding - you can check how __attribute__ ((packed)) works). I will upload the code to GitHub once I put all code pieces together).
I might start working on a PCB and turn this into a little Arduino device.
LiVduino stage 1
LiVduino stage 2
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!