Use a Wi-Fi enabled Raspberry PI Pico W and MicroPython to measure the soil moisture in your potted plants and store the measurements in the Sanity Content Cloud.
Read soil moisture levels for up to three capacitive moisture sensors at a configured interval and store these levels in a Sanity document.
- Raspberry PI Pico W (how to buy)
- Soil moisture sensor(s) (you can connect up to 3 to one Raspberry PI Pico W), for example SparkFun SEN-13322
- Various jumper wires, connectors, breadboard, etc. See this guide for an example of how to hook up a moisture sensor to a Raspberry PI Pico
First, make a fork of this repository to your personal GitHub account and clone it to your local computer.
The Sanity Content Cloud offers a convenient way to store and read the sensor measurements, and the Raspberry PI Pico W will post sensor updates directly there. The Sanity Content Studio allows you to easily view and edit the sensor data stored in the Content Cloud.
- Go to https://sanity.io/get-started/create-project and get your project ID and dataset
- Copy
.env.example
in thestudio
-folder to.env
and replace the sample values with the project id and dataset from the previous step - Run the Content Studio locally with
npm run dev
Once the board and sensors are hooked up, you are ready to deploy the MicroPython app to the Raspberry PI so it can measure and send sensor measurements at regular intervals to the Sanity Content cloud.
- Install MicroPython on your Raspberry PI Pico W.
- Go to the
board
folder and copyconfig.example.py
toconfig.py
and change the config according to your Sanity config. - Connect to the Raspberry PI and load the program onto it. There are several options here:
- Thonny
- Pyboard
- PyCharm with the MicroPython plugin
- VSCode with the MicroPython plugin
- Open
config.py
in theboard/
folder and set thePROGRAM_MODE
tosetup
- Flash the device with all the files contained in the
board
folder. Make sure you enable the REPL, so you can see logs and debug if something goes wrong. - (Optional) Open
config.py
again and changePROGRAM_MODE
tocalibrate
. This will allow you to find the min/max values of the moisture sensors (make sure to have a glass of water readily available). - Flash the device again as in step 2
- Open
config.py
in theboard/
folder and set thePROGRAM_MODE
toapp
- Flash the device again as in step 2. The PI will now read sensor levels at the configured interval and post updates to your Sanity Content Cloud dataset.