WiFi Sensors, Relays, etc ...


This page describes my experiments with WiFi Sensors based on ESP8266 modules and some other home automation projects.

ESP8266 and sensors

I use ESP-07 and ESP-12E modules and simple universal board. For measuring I use following sensor types:

ESP8266 has pins Reset and GPIO16 connected and deep sleep functionality is used. Sensors measure values every 5 minutes and sleeps between measuring.


Current that draws ESP8266 depends on mode (STA vs. AP) and from state. Critical is boot, firmware flash and WiFi operations. See more infoexternal link about it. With insufficient power supply you may have problems: unexpected reboots, error messages to serial line after failed boot, etc. Also account reserve for powering your sensors.

I have tried following powering methods:

Measuring battery

I use two Li-Ion batteries in series for powering sensors (with POLOLU-2842) and ADC input for measuring battery voltage. Note, that ADC in ESP8266 has range cca 0.2 ÷ 1.2 V.

Source code

Here is source code, developed using Arduino IDE. It's common for my all sensors and particular one must be enabled by uncommenting some lines at top of code.

ESP8266 programming

For programming, I use CP2104 USB UART and Level shifter for 5 V ⇄ 3.3 V conversion.

IOT database

I store measured data to database. Database model is very simple and self explained, I hope:

Database model

Scripts for initial populate of DB tables are located in project IotDbScripts. Here is crucial parts: create_tasbles.sql | populate.sql


IotDatabase is ORM layer between DB tables and Java. It's use EclipseLinkexternal link as ORM engine. For each database table, there is mapping class - Person, SensorType, Sensor, etc. Also service layer for obvious tasks is created.



IotService is Java EE application based on:

IOT Service

IotService is deployed on Apache Tomcat server, and this service has following purposes:


This JAX-RS Service is responsible for storing data from sensors, and for sending alerts. Everytime sensor measures value, WiFi connection is established and following HTTP GET request with sensor code and measured value is sent to IotService:


Request contains sensor code and measured value.

IOT Insert value Service

When measured value is under/over defined alert, email message is sent, like this:

Alert email


This MVC Controller generates web page with chart. It loads values and create desired averages. Controller stores JSON data for chart to MVC Model. In next phase, processing is redirect to JSP page (MVC View). Google chartsexternal link API is used for chart rendering.


Other Services

I have developed some other JAX-RS Services for getting data in JSON and other things.

Base station

For displaying measured values without PC or tablet I made simple station with Arduino LEONARDO ETH and 20*4 LCD display. It's housed in old box with power supply. There are five front panel buttons, that I use for choosing values to be displayed. Here is source code, developed using Arduino IDE.


Base station contains two power relays to control 230 V outlets. Required state of relays is stored to database tables and base station check this using JAX-RS service and set desired state. For driving relays there is expand board with PCF8574, the I²C 8-bit expander and ULN2803A.

Control relay states

Basen pump controller

One of two relays I use for switching basen pump ON/OFF to give maximum efficiency of solar panels. The system consists of the following parts:

Basen with solar panels and IOT controlled pump

When pump control works correctly, temperature of solar panel has typical sawtooth shape, water in basen temperature rises gently.

Basen with solar panels temperatures

Measuring indoor Air quality

The CCS811external link Air Quality Breakout is a digital gas sensor with I²C bus. I tried it with ESP8266 but it not works for me. So I connected it to Fishino UNOexternal link and made simple measuring station. There is also Si7021 for measuring temperature and relative humidity. Both sensors operates at 3.3 Volts, so there is Level shifter for 5 V ⇄ 3.3 V conversion on I²C bus.

Station displays sensors values on LCD and sends it to IOT service. There is also RGB status LED and 4-buttons keyboard for settings various modes. Here is source code, developed using Arduino IDE.


At this time, I have six ESP modules with various sensors in gardenhouse, greenhouse and outdoor. Server side service is under daily development, but if somebody is interested about source code, let me mail, it's nothing secret.

Valid XHTML 1.0!     Creative Commons License - non commercial