How I created sourdough monitoring system and how can you easily make one too

Is my sourdough bread going to taste better? Will see. Was it fun to make? Absolutely. Do I recommend making your own? 100%!

Ivana Huckova
8 min readJun 23, 2020

This blog was originally written for and published at Grafana blog. 🧡

Sourdough monitoring system is actually my first IoT project that I’ve ever worked on. I truly enjoyed the process and I would like to share with everyone, who would like to dip their toe in IoT development, how easily they can do that as well. Below you can find instructions that should guide you through the process.

Getting a hardware

As a first step you need to get necessary hardware. For the sourdough monitoring system you are going to 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

And some other tools and items:

  • Jar for your sourdough starter with the lid that you can cut
  • Something to cut the hole in the middle of jar lid
  • Glue and/or tape — glue gun, superglue or double-sided tape (ideally all of them)

Installing necessary software

As a first step, you need to install Arduino IDE which is a platform that is used to write and upload programs to Arduino compatible boards. I have installed the version 1.8.10, as newer versions were throwing errors on OS Catalina. Version 1.8.10 was recommended as a solution on Arduino forums and it worked for me as well.

Secondly, you will probably need to install CP210x USB to UART Bridge VCP Driver if your OS won’t recognise the USB Serial automatically. This driver basically lets your computer communicate with your ESP32 development board. I am on OS Catalina and I had to install this driver.

Setting up a database

Next very important thing is to set up a database where you are going to store the data from your sensors. InfluxDB time series database was my choice and it is generally a very popular option for IoT projects. You can very 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 will need to set up following things:

  • Bucket (bucket is a named location where your time series data from the sensors will be stored. I have created a specific bucket for my sourdough data called arduino).
  • Token that has write access to the bucket where you are going to be storing your data for your monitoring system.
  • Token that has read access to the bucket where you are going to be storing your data for your Grafana.

Connecting sensors and development board with cables

Now it is time to connect both sensors to board through the cables.

DHT11

DHT 11 sensor 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 our sourdough starter lives.

If you have bought a DHT11 sensor module, then you should see 3 pins. No worries if you see 4 — you have probably bought just a sensor by itself. This has happened to me as well and it is an easily solvable problem — you just won’t use the third pin.

As you can see on the image on the left, we are going to connect these pins in a following way:

  • Vcc pin to 3.3V on board
  • Digital pin to pin 32 on board
  • Gnd pin to Gnd on board

HC-SR04

HC-SR04 sensor provides 2cm — 4 meters measurement function, with accuracy around 3mm. This sensor will be used to measure how far is your sourdough starter from the lid and calculate its rise and/or fall. HC-SR04 has 4 pins that you are going to connect to development board in the following way:

  • 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

Programming

Now, when 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 microUSB to your computer.

Setting 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 have selected the new COM port.

Adding libraries

For this project you are 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.

Creating a program

You can download the sketch from my github. Sketch is the name that Arduino uses for a program. It’s the unit of code that is uploaded to and run on an Arduino board. In the folder downloaded from the github, you will find 2 important files — sourdough_monitor.ino and config_template.h. In the first file, we have our program. In the second, we are going to store our variables.

File config.h:

  1. Rename config_template.h to config.h
  2. 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

File sourdough_monitor.ino:

Below you can find the program code with the comments explaining each section.

Uploading and running the program to ESP32

Let’s make this all come together!💪

Click on the open button (arrow pointing up), choose Open and find your sourdough_monitor.ino file and open it.

Then go to Tools > Serial Monitor and open it. This will allow us to see the debug output from the board. Set the port speed on the bottom to 115200.

And lastly, use the Upload button (arrow pointing to right) in the UI to build and upload the program to the ESP32.

Once when the upload has completed, our Serial Monitor will show:

  • Start up & connect to WiFi
  • Results of submitting metrics

If everything was set up correctly, you will soon see incoming data also in your InfluxDB database.

Visualise of our data in Grafana

Now, when you have all your data flowing to InfluxDB, it is time to visualise them in Grafana. Follow the installation guide and set up Grafana. Add Flux [BETA] data source as unfortunately Influx data source doesn’t provide authentication with token. Fill out your organisation id, 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 are able to just copy-paste queries from your InfluxDB query editor.

Add monitoring system to sourdough jar

Now comes the handy part of work. 👷‍♀️ Below, you will find the instructions of how I mounted my jar, but I am sure there is a MUCH better way, so feel free to improvise with what you have.

You are going to take the lid from the jar and move the jar away, as we are not going to use that. Carefully, make 1 bigger hole in the middle of the jar for HC-SR04 and smaller next to it for DHT11.

Put HC-SR04 sensor in the HC-SR04 holder and add the second holder on top of it. Glue HC-SR04 in the holders to the lid. With double-side tape stick DHT11 to the lid so it is facing the jar.

With a glue gun, you should carefully glue down the ESP32 board to the top of the HC-SR04 holder. Make sure that you are gluing only extended parts on which ESP32 board stands and not the board itself.

And this is how it looks. Just place it in the kitchen (or any other are where you keep your starter) and plug it to the USB charger. I have later added a cover from cutted plastic bottle to make sure that sourdough is not drying out through the holes in the lid.

I really hope you will try this out and let me know how it went! Also, if you have some fun and interesting IoT ideas, I would ABSOLUTELY love to hear about them!

--

--