ja225huTue, Jul 12, 2022 After running this for a while, the water level sensor has corroded rather rapidly, leaking copper into the soil/water, this is obviously not desirable, to prevent this a capacitive moisture sensor would be ideal, but changing the setup so that the extant sensor is powered via one of the GPIO pins, and only powered in short, infrequent bursts while measuring would limit corosion and extend the lifespan of the sensor from a few days to several weeks or months.
Hello! I am John Åkerhielm (ja225hu), this is my tutorial for a simple IoT device for monitoring a plant's environment.
Time required; 1-2 hours.
I'll be able to determine how fast my plants dry out, and automatically logging when I am watering them.
Item | Price | Link |
---|---|---|
Esp32 development board | 167 sek | amazon.se |
37 Sensor kit | 282 sek | amazon.se |
Since I knew I wanted to stay in the smarthome arena, I decided that a wifi based device makes the most sense, both from a deployment (every home has wifi already), and development perspective.
I purchased the sensor kit since it was pretty cheap and a fun bunch of things to have. For this project I used:
I use MicroPython which I downloaded from the Micropython website. My development board has an esp32-wrover-b so I used the esp32spiram release of MicroPython.
Flashing was unproblematic. I just followed the instructions and flashed the device with esptool.py:
I prefer to use a simple text editor to write code, and manually upload to the device via terminal.
I found small script called mpfshell that very neatly sends files to the device.
I made two shell aliases to makes things neater.
The 'DHT11 Temperature Humidity sensor' and the 'Water Level Sensor' each use a single input pin, as well as 3.3V and GND.
I connect the DHT11 to pin 33 and the Water Level Sensor to pin 32.
I run a local homeassistant instance and a mosquitto mqtt broker, this keeps all my data in-house. Homeassistant does the logging, display and processing of data.
homeassistant and mosquitto are run as docker containers, this makes install, reinstall migration very easy. Also: all the components are free and open source.
To install homeassistant using docker-compose (get it this from your distros repository).
create a file called docker-compose.yaml:
and then run
in the same folder. More info here
The code is very simple
https://gist.github.com/fyra/2cfcfd639ed932714db77d038cbdfb2e
Data is published to the local MQTT broker over wifi.
Homeassistant sees the topics in homeassistant/sensor/ and automatically recognizes them as sensor entities.
I am using Homeassistant to log and display the data.
Homeassistant is a very easy to use platform for automation, so I might add a small pump for automatic watering of some plants eventually.
This project produced a passable prototype, next refining step would be evaluating the Water Level Sensor and calculating a percentage rather than the unsigned 12bit value that it currently is.
After that i'd want to physically design the device.
Those wires are not pretty.