Irrigation 8 – Solar Powered Sensor Unit

A solar powered, ESP8266 based sensor unit for my automatic irrigation system.

Finally all parts arrived and my irrigation sensor is now ready. I took my ESP8266 Breakout Board as basis. During soldering works I realized that there are some details missing in my breakout design (mainly missing designations). Therefore I have updated its design as well (Github). Using the XCSOURCE FT232RL 3.3V 5.5V FTDI USB zu TTL Serielles Adaptermodul Arduino Mini Anschluss TE203 and the soldering jumper there is no need for the “PROG” button. It is handled by the converter it self. I use the same sonsors I have used for the prototype (MTS1EU Greenhouse Sensor Kit Soil Hygrometer Module and DHT11 Temperature/Humidity Module for Arduino. Gewächshaus Pflazen .)

Circuit Diagram
Circuit Diagram
PCB Sensor
PCB

I use a small 5V / 81mA solar panel from Conrad. The panel drives very little current so I don’t need to care about charging logic. A simple Zener diode (BZX85C3V9) should be enough. I also changed the transistor to a PNP type as some of my readers recommended. Also the GPIOs I use have changed due to layout reasons. I have put the latest version of Fritzing and code on my Github.

So thats what the result looks like.

 

sensor5 sensor4 sensor3 sensor2 Sensor1

Irrigation Part 7 – ESP8266 Breakout Board

When I started layouting the PCB for my irrigation sensor I realized the advantages of a breakout board. They are handy for developing, sure. But they also bear the big advantage that you do not have to take care about repetitive tasks (such as pull-up resistors). Additionally they ease up layouting by adding two additional layers to your design. That simplifies the design and it also minimizes the footprint of the final PCB.

When I started layouting the PCB for my irrigation sensor I realized the advantages of a breakout board. They are handy for developing, sure. But they also bear the big advantage that you do not have to take care about repetitive tasks (such as pull-up resistors). Additionally they ease up layouting by adding two additional layers to your design. That simplifies the design and it also minimizes the footprint of the final PCB.

Size was the most important factor for me. It isn’t just a question of space, it is also a question of price (PCB cost ist based on cm²). Beside the pull up resistors for CH_PD, GPIO_0, GPIO_2 and RESET and the buttons to ground RESET and GPIO_0 (PROG) I have also foreseen a pin header for connecting my XCSOURCE FT232RL USB<->TTL. The voltage supply of the USB-TTL converter can be enabled or disabled with a jumper. Additionally I have foreseen solder jumpers CTS->REST and DTR->GPIO_0. I’ve not tried personally but some sources say that this connections make the manual buttons obsolete by handing over this task to the USB-TTL converter. Finally there is also a solder jumper to connect GPIO_16 and RESET (for wake up after deep sleep) and a capacitor as voltage stabilizer. Other boards like the Huzzah Board use a voltage converter for this but I have made good experience with the capacitor.

My followers on twitter know that it took several attempts before I got my final version ready (special thanks here to @ccxx72, @i_grr, @bdcatalin und @tzapulica for their help).  I also faced some troubles with  Fritzing but finally you can download my result at Github: https://github.com/Stromspielplatz/misc/tree/master/ESP8266%20ESP-12%20Breakout

ESP8266-ESP12 Breakout Board Circuit Diagram
ESP8266-ESP12 Breakout Board Circuit Diagram
ESP8266-ESP12 Breakout Board PCB
ESP8266-ESP12 Breakout Board PCB

Tracking Motion Level using Raspberry PI and MATLAB/SIMULINK

Some days ago I have already confessed to be somehow fascinated of the Netflix Socks. Every evening I have to search for the episode (actually I look “The Man in the High Castle” based on the novel from Philip K. Dick) and the time I fell asleep. So something like the Netflix Socks was ideal but I have some major doubts.

First of all I have no problem with cold feet. So I rather take my socks off. Then there is the issue with the battery. I really don’t want wo have another wearable I have to take care about. And last but not least I often watch movies with my wife. And to be honest I’m not even a Netflix customer. For me is Amazon Prime in combination with a Fire TV Stick the better choice but that is another story. So I had the idea to make something video based. I’m not sure if this will work, because if it would be so easy, I’m sure my Samsung TV would have such  function. But I want to give it a try and start with a little feasibility study.

The idea of all the sleep tracking is to measure movements. Wearables to this with acceleration sensors. I want to do this with a Raspberry PI and the Raspberry PI Cam. I will use MATLAB/SIMULINK for programming. MATLAB/SIMULINK is a rather more a platform than a programming language and in my opinion predestined for engineers. They follow a common marketing  approach and sell it cheap for students and make expensive (really expensive) for professionals. Fortunately there is a Home Edition since some years. When I found it I was a bit disappointed because it is still rather expensive for private persons (for the basis and some toolboxes you pay already more than 200$) But I really like the system and as they support Raspberry, Arduino, Lego Mindstorms, and other platforms and therefore it is a nice playground for makers like me.

After following the installation procedure of the development software itself you have to get the Hardware Support Package for Raspberry. A wizard will lead you through the installation process and at the end you will have SD card with Raspbian and the MATLAB software. In my case the network setup afterwards didn’t work so I had to connect a monitor, keyboard and mouse and make the network setting manually. For programming you have to use SIMULINK to run your software permanently on the Raspberry. I will not explain how to use the software. They have tons of tutorials on their website and in the meanwhile you find a lot of resources in the internet. Before you can use the Raspberry PI Cam you have to follow a few steps.

simulink model
SIMULINK model for motion measurement

The SIMULINK model is really easy. I just connect the camera with  “Sum of absolute metrics” directly and through a  delay block. Then make a small type conversion and put it to a UDP socket. Additionally I connect an Image Viewer to align the camera. For testing I use a socket server I’ve downloaded from the internet.

Matlab
Testing the model

For data acquisition I use the server of my irrigation project. I create a table tblmotion to store my measuring values.

Beside the motion measurment value I also store the raw bytes coming from my model because it was late in the evening when I did this and so I was not sure if my type conversion was working. I didn’t want to loose the data from the trial and with raw data I could have corrected the type conversion afterwards if it would have failed.

As socket server I use a PHP script. To run a PHP script in the Raspberry shell you have to install the PHP-CLI.

After having a nap in front of the TV I did the data analysis the next day with MATLAB. I did not invest in the database toolbox so I just query the data, export it to CSV and import it in MATLAB. I’ wearing a Garmin Vivosmart so I knew I felt asleep approx. 01:00. Looking at the data there seems to be a trend in the motion value.

Motion value
Motion value

So I do a bit of data analytics. I build some statistic values (STDDEV, AVG, VARIANCE) over different periods (1min, 5min, 10min, 20min) in SQL and import the data in MATLAB

The result makes me quite confident.

aggregate data

The data show a significant change in the movement value between 00:30 and 01:00. So the challenge will be to put this information in a reliable algorithm. Most properly I will have to get the neuronal network toolbox soon to make some trials.

Stay tuned!

Irrigation- Part 2: Data Recording

I use a Raspberry PI 2 as server for my data recording. Additionally you need a SD card, a power supply (I use just a USB cable to connect it to my access point) and if needed a WLAN stick. I strongly recommend to use a case e.g. like this one

First of all the Raspberry needs an operating system (raspbian) installed. There are plenty of manuals for that in the internet. As you have seen in the Arduino project I send my data using a web server. Writing a small socket server would have been the more lightweight solution but it is really a tough job to program a service that runs 24/7 stable and robust. Therefore I like to use some kind of a well-known and tested middleware. For data recording the combination of Apache webserver, PHP and MySQL (LAMP) is an ideal solution for me. There are many tutorials for setting up such a system in the internet (I used this one). Instead of using the “real” MySQL I use the open source successor MariaDB.  I just replace

apt-get install apache2 apache2-utils php5 libapache2-mod-php5 php5-mysql mysql-server mysql-client phpmyadmin -y

by

apt-get install apache2 apache2-utils php5 libapache2-mod-php5 php5-mysql mariadb-server mysql-client phpmyadmin -y

MariaDB and MySQL are compatible on a wide scale. So you can use almost all the tools you use for MySQL also for MariaDB.

To improve my tool chain I also install a samba server on the Raspberry. You find a tutorial here. I develop on a Windows platform and the Samba server enables me to mount the wwwroot of the raspberry as network share. So I can simply develop on this share without taking a detour using FTP. For developing on the MariaDB you can use the installed PHPMyAdmin or you install the MySQL Workbench instead. The Workbench throws an error when connecting to a MariaDB but it’s working without any problems. It’s a matter of taste which way you prefer. Ich like the Workbench because I’m used to work in a real IDE for database development so the PHPMyAdmin feels a bit unfamiliar for me.

After setting up the Raspberry and the development tool chain you can create a database. I call my database simply “templogg”

Then I  create a table called “tbllogging”

The column “dt” is a datetime column and acts as my primary key. The columns temp, humidity and soil are data type real and take the measuring values. As you could see in the Arduino code, the PHP script, called “newrecord.php” is missing. I put the script directly in the wwwroot.

The script requires the MySQL extension in the php.ini.

The mysqli extension is not enabled by default, so the php_mysqli.dll DLL must be enabled inside of php.ini. In order to do this you need to find the php.ini file (typically located in c:\php), and make sure you remove the comment (semi-colon) from the start of the line extension=php_mysqli.dll, in the section marked [PHP_MYSQLI]. – http://php.net/manual/en/mysqli.installation.php

After that I try my script. I call the URL with some test data. You can do that with any browser.

http://raspberryip/newrecord.php?temp=33.00&humidity=44.00&soil=55.00

Then I check if the data has been recorded correctly.

When it works I delete the test data.

Now I start my Arduino and check if the recording works fine with that too. If that’s the case the prototype will do measurements on a houseplant for the next weeks.

Prototype in Aktion

In the meanwhile I will make a small website to display my measurements without using my database IDE.

Irrigation- Part 1: A Prototype

In a first step I will make a prototype for my sensor board. Usually you build a prototype just on a breadboard. But I would like to use my prototype for some weeks to see how my sensors work and how much energy is needed. Therefore I use a prototype circuit board instead.

My shopping list for that:

Additionally I need:

  • A prototype circuit board
  • 3 pcs. 10k Resistors (can be even bigger as long aa all 3 are equal)
  • 1 electrolytic capacitor (>500uF)
  • 1 Transisotr (e.g. BC547C)
  • 1 3K3 Resistor
  • a pin header
  • a jumper
  • a soldering iron

I know that there a many statements about the right soldering iron in the internet but for me personally a cheap soldering station is more than enough. There is also a good desoldering pump coming with the station and every beginner will need it. If you have too much money then spend it in a quite good solder. As power supply I use a USB powerbank that I’ve received as a giveaway. You can also get one for less than 10€ (e.g. here)

I try to do not solder items directly when building a prototype. Therefore I use pin headers. The disadvantage is that the prototype is not that robust but the advantage is I can easily borrow some parts without taking the soldering iron.

The ESP8266 just takes 3.3V so I take the USB to TTL converter also as voltage converter. Be sure to put the jumper to 3.3V. To safe energy I will put my ESP in deep-sleep. To prevent my sensors taking power when they are not used I use a transistor to power them on only when needed. The ESP needs quite a high current when connecting to the WLAN. I use an electrolytic capacitor parallel to the voltage supply. Sizing of that is no rocket science, it should be somewhere between 400uF and 2200uF (6-10V). For programming the ESP the CH_PD Pin has to be put on ground. Some recommend a button for that but I prefer a jumper.

The manual for the ESP8266 says that for wake up from deep-sleep pin 16 has to be connected to CH_PD. Unfortunately for some reasons this is not working with mine. I use the RESET for the wakeup instead. This prevents using some options for wakeup but I don’t care for the prototype.

 

Der Prototyp in EAGLE
Prototype in EAGLE

It is a puzzle to place all the components on the board. I tried to save as much space because I had a small leftover to be used.

Meine Prototyen Platine
My final prototype

For programming my ESP I use the Arduio IDE. You have to install the ESP board in the IDE. Add in File->Properties->Additional Board Manager URLs: http://arduino.esp8266.com/stable/package_esp8266com_index.json  Select Board „…“ > Board Manager… , choose esp8266 and press install. After that you can program the ESP like any other Arduino. For programming the jumper has to be set on starting the board. Sometimes the upload fails with some strange error messages. If this happens I simply restart the ESP and try it again. Remember to remove the jumper after uploading the software. Wake-up from deep-sleep is not working when the jumper ist set.