Due to an editing error, an earlier version of this post mentioned Prometheus in the headline. This factual error was corrected, and we have added checks to our process to avoid such mistakes in the future.
I have a confession to make: I’m one of those people who has been making homemade bread during the coronavirus lockdown. I even grew my own sourdough starter.
In case you didn’t know, a starter is a yeasty mixture used to make bread rise. (There’s a basic recipe here.) You make it out of flour and water, but it needs to be regularly “fed” and partially discarded over the course of a week or two before it’s ready. The process takes weeks, but in the end it’s definitely worth it.
Since I’m a software developer here at Grafana Labs and also really interested in learning more about things that surround me, when I heard it was possible to make a sourdough starter monitoring system, I had to try it. (Word is it can improve the quality of a starter and the taste of your bread.) So for our Hack Days, I decided to take my starter-growing to the next level.
The system I made was inspired by sourd.io, which was created by Christine Sunu, and it’s the first IoT project that I’ve ever worked on. I enjoyed the process so much that I wanted to share it with everyone – especially anyone who’d like to dip their toe in IoT development. The setup is really easy, and I’m going to take you through the steps.
To build the sourdough monitoring system you will need:
- 1 DHT11 sensor module to measure temperature and humidity
- 1 HC-SR04 ultrasonic distance sensor to measure sourdough rise
- 2 HC-SR04 holders
- 1 ESP32-PICO-KIT V4 development board
- 7 M-F Dupont Cables
- 1 micro USB cable
- 1 USB charger
- 1 medium-sized jar for your sourdough starter, with a lid you can cut
- Something that will cut a hole in the middle of the lid
- A glue gun, superglue or double-sided scotch tape (ideally all of them)
You’re going to have to install Arduino IDE, a platform that’s used to write and upload programs to Arduino compatible boards. I installed version 1.8.10, since newer versions were throwing errors on OS Catalina, which I use. It worked well.
If your OS won’t recognize the USB serial automatically, you’ll probably need to install CP210x USB to UART Bridge VCP Driver. (I had to install it for my OS Catalina.) This driver basically lets your computer communicate with your ESP32 development board.
The database setup
The next important step is to set up a database where you’ll store the data from your sensors. InfluxDB time series database was my choice, and it’s generally a very popular option for IoT projects. You can easily set up InfluxDB Cloud, which allows you to store 30 days of data for free.
As soon as you have your InfluxDB cloud up and running, you’ll need to set up following things:
- A bucket, which is a named location where your time series data from the sensors will be stored. I created a specific bucket called “arduino” for my sourdough data.
- A token that has write access to the bucket where you’ll be storing your data for your monitoring system.
- A token that has read access to the bucket where you’ll be storing your data for your Grafana.
Now it’s time to start putting things together.
The DHT11 sensor module This is a very basic and cheap sensor made of two parts: a humidity sensor and a thermistor. It can be used to measure temperature and humidity of the environment in which the sourdough starter lives.
If you have a DHT11 sensor module, it will have three pins. Don’t worry if you see four – you probably just bought a sensor by itself. This has happened to me as well, and it’s an easily solvable problem: You just won’t use the third pin.
Connect the pins in the following way:
- Vcc pin to 3.3V on board
- Digital pin to pin 32 on board
- Gnd pin to Gnd on board
The HC-SR04 ultrasonic distance sensor This sensor provides 2cm to 4m of measurement function, with accuracy around 3mm. This will be used to measure how far your sourdough starter is from the lid and calculate its rise and/or fall.
The HC-SR04 has four pins that you’re going to connect to development board like this:
- Vcc pin to 5V on board
- Trig pin that sends the signal to pin 4 on board
- Echo pin that receives signal to pin 5on board
- Gnd pin to Gnd on board
Once you have your sensors and development board ready, you need to write and upload a program that is going to retrieve data from the sensors and send it to the InfluxDB database. Connect your ESP32 board with connected sensors through a microUSB to your computer.
Step 1: Set up Arduino IDE to support your ESP32 board
Open your Arduino IDE. If you are using an ESP32 board as I have recommended (and not an Arduino board), you need to add a board definition that adds support for your EP32 board. Go to Arduino > Preferences and add url https://dl.espressif.com/dl/package_esp32_index.json to the Additional Boards Manager URLs input. This open-source board definition adds support for programming ESP32 boards.
Then go to Tools > Boards > Boards Manager and add ESP32 board manager.
Next, in Tools > Boards, choose ESP32 Pico Kit board. This tells the Arduino IDE which profile and base libraries to use when compiling the firmware image, and how to flash it to the board. Make sure that in the Tools > Port submenu, you’ve selected the new COM port.
Step 2: Add libraries
For this project you’re going to use following libraries:
- DHT sensor library by Adafruit
- Adafruit Unified Sensor by Adafruit
- NTP Client by Fabrice Weinberg
- HCSR04 by Martin Sosic
Go to Sketch > Include Library > Library Manager and install all of these libraries. Make sure that you have all of them installed before moving to the next steps.
Step 3: Create a program
Sketch is the name that Arduino uses for the unit of code that is uploaded to and run on an Arduino board. You can download the sketch you’ll need from my github.
In the folder I created, you’ll find two important files : sourdough_monitor.ino and config_template.h. In the first file, you have your program. In the second, you’re going to store your variables.
Rename config_template.h to config.h
Add your variables:
- Your wifi name and password, so ESP32 can connect to your internet
- Your InfluxDB information — host, organisation id, token, bucket
- Root Certificate
Below you can find the program code with the comments explaining each section.
Step 4: Uploading and running the program to ESP32
Let’s make this all come together! 💪
Click on the open button (arrow pointing up), choose Open, find your sourdough_monitor.ino file and open it.
Then go to Tools > Serial Monitor and open it. This will allow you to see the debug output from the board. Set the port speed on the bottom to 115200.
And finally, use the Upload button (the arrow pointing to the right) in the UI to build and upload the program to the ESP32.
When the upload has completed, your Serial Monitor will show:
- Startup & connect to WiFi
- Results of submitting metrics
If everything was set up correctly, you will also soon see incoming data in your InfluxDB database.
Data visualization in Grafana
When you have all your data flowing to InfluxDB, it’s time to visualize them in Grafana. Follow the installation guide to set it up.
Unfortunately, Influx data source doesn’t provide authentication with a token, so you’ll need to add the Flux [BETA] data source plugin. Fill out your organization I.D., bucket and token, and save the data source.
Next, create dashboards. Flux data source has a query editor compatible with its cloud interface, and you can just copy-paste queries from your InfluxDB query editor.
The jar monitoring system
Time for the handiwork. 👷♀️ I’m including details on how I mounted my jar, but I’m sure there is a MUCH better way, so feel free to improvise.
You can put the jar itself aside for the moment, because this is all about the lid. Carefully make one 2cm x 5cm hole in the middle of the lid for the HC-SR04, and a smaller one next to it for the DHT11.
Put the HC-SR04 sensor in a HC-SR04 holder then place the second holder on top of it. Glue the sensor holders with the sensors to the lid. With double-side tape, stick the DHT11 to the lid so it will be facing the inside of the jar.
With a glue gun, carefully glue the ESP32 board to the top of the HC-SR04 holder. Make sure that you’re only gluing the extended parts on which the ESP32 board stands, and not the board itself.
The photo below is how it should look. (I later added a cover from a cut plastic bottle to make sure that sourdough doesn’t dry out through the holes in the lid.)
Put the jar in your kitchen – or wherever you plan to keep your starter – and plug it to the USB charger.
Now you’re ready to add your starter ingredients and begin monitoring the progress.
The bread I made with my monitored started was the best I’ve baked so far. I can’t say that’s connected to the monitoring system because I didn’t change how I’ve been feeding my started, but it tasted really good.
I really hope you’ll try this out and let me know how it goes. Also, if you have some fun and interesting IoT ideas, I would ABSOLUTELY love to hear about them, too!