Rather then pull @fruitnut’s thread on soil monitoring off topic, I decided to create a new thread to answer @horna in case others may find it useful.
I’ll start with the caveat that I’m not claiming this is better than any commercially available weather station, but for anyone who likes tinkering with electronics, or has a spare raspberry pi they want to put to good use, this might be an alternative that gives you complete control over the data you are collecting.
Materials required
- Any raspberry pi (the Pi Zero W works well)
- the ADT7410 i2c temperature chip
- three small lengths of jumper wire with female connectors on one end and the other end matching your pi GPIO header (some raspberry pi models take male connectors, some take female connectors, some have no headers at all and will need either one soldered on first)
- a soldering iron & beginner-level soldering skills
- a short section of PVC pipe with an internal diameter wide enough to fit the ADT7410 chip inside
- optional: scraps of mylar or similar foil insulation to cover the PVC
- for outdoors: a scrap of hard plastic or metal sheeting to divert rain from entering the top of the PVC pipe
Setup steps
First, follow the “assembly” instructions for soldering the chip header.
Next, follow the instructions for installing the Python libraries on your pi and connecting the chip.
The end of those instructions include the sample python code for printing the temperature to the screen every 30 seconds. Once you’ve run that and confirmed it works, you can tweak that code to instead save the reading to either a local database or to send it to a script running on a web server either on the local network or the internet (as I have done). My script uploads three fields via the POST method: temperature, time, and a sensor ID (to associate the temperature with the correct monitor).
Here’s a slightly simplified version of my own code to upload and log any errors (this code does NOT have a backup option to save locally if the website is unavailable):
#!/usr/bin/python3
import time
import board
import busio
import adafruit_adt7410
import requests
from datetime import datetime
i2c_bus = busio.I2C(board.SCL, board.SDA)
adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48)
adt.high_resolution = True
webKey = 'password for your website'
webURL = 'https://yourwebsite-script-address-goes-here'
curTime = datetime.now()
newTemp = {'temp': adt.temperature, 'sensor': 'zero1', 'time': curTime, 'key': webKey}
rez = requests.post(webURL, data = newTemp, headers={"Accept":"text/html", "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/5
37.36"})
if rez.text != 'OK':
with open('/home/pi/gh/log', 'a') as f:
print(str(curTime) + " " + rez.text, file=f)
You can then create a crontab entry to run the script every minute:
* * * * * /home/pi/monitor.py
For my greenhouse temperature monitor, I have it placed in the center of the rafters, a few feet below the peak of the roof and around the highest part of the eventual tree canopy, while for the outdoor monitor, I have it mounted on the outside north wall of my greenhouse, with the wire running through the wall to the raspberry pi mounted inside. Photo was posted here:
To display that data, I pull it from the mySQL database using PHP and generate a chart using the Chart.js library. Here’s what that page looks like:
You can view the page source here for an idea of how to use Chart.js similarly:
I’m sure I left out something important, so I’m happy to answer any questions or help troubleshoot if anyone else tries to follow this and runs into problems.