Autonomous Duckweed Cultivator — ESP32 Control Software
This repository contains the firmware used for the two ESP32 microcontrollers that form part of the autonomous duckweed cultivator developed by the iGEM Brno 2025 team.
Each ESP32 board handles a specific subsystem of the bioreactor:
- The main (lights) board controls lighting, valve actuation, and PROBE optical biomass measurement.
- The pump board manages nutrient and harvesting pumps, additive mixing, and pH/EC monitoring.
This single source file can be compiled for either of the two boards depending on the MAIN_BOARD symbol:
- When
MAIN_BOARDis defined, the firmware runs in main board mode — managing the LEDs, valves, and PROBE sensor array. - When
MAIN_BOARDis not defined, it runs in pump board mode — controlling the peristaltic and harvesting pumps, mixers, and monitoring pH and conductivity sensors.
The ESP32s communicate with a central Raspberry Pi server over Wi-Fi and MQTT, forming a distributed control network for the bioreactor.
- Automatic Wi-Fi and MQTT reconnection on startup.
- Status LED blink patterns:
- 3 blinks: Wi-Fi connection failed.
- 5 blinks: MQTT connection failed.
- MQTT-based command and telemetry exchange with the Raspberry Pi (
bioreactor.local).
- Controls 5 electromagnetic valves and 5 LED lights, one per cultivation layer.
- Reads PROBE optical biomass sensor signals (analog inputs).
- MQTT Commands:
open_valve_<id>/close_valve_<id>light_on_<id>/light_off_<id>all_lights_on/all_lights_offall_valves_on/all_valves_offtrigger_probe_measurementget_probe_readings
- Controls:
- 4 peristaltic pumps (for nutrient inflow/outflow)
- 1 harvesting pump (PWM controlled)
- Additive mixer
- Reservoir mixing pump
- Monitors pH and conductivity sensors (analog inputs).
- MQTT Commands:
start_pump:<power%>/stop_pumpperistaltic_on:<id>/peristaltic_off:<id>additive_mixing_on/additive_mixing_offreservoir_mixing_on/reservoir_mixing_offtrigger_ph_cond_measurementget_ph_cond_reading
| Component | Role | Connection |
|---|---|---|
| ESP32 (Main Board) | Lights, valves, PROBE sensor | Wi-Fi → MQTT |
| ESP32 (Pump Board) | Pumps, mixers, pH & EC sensors | Wi-Fi → MQTT |
| Raspberry Pi | Central controller + GUI | MQTT Broker (bioreactor.local) |
| Direction | Topic | Description |
|---|---|---|
| ESP → Server | esp_to_server/rack0 / esp_to_server/pump |
Sensor data and status updates |
| Server → ESP | server_to_esp/rack0 / server_to_esp/pump |
Control commands |
| ESP Client IDs | esp/rack0, esp/pump |
MQTT client identifiers |
- Hardware: 2× ESP32 microcontrollers
- Software:
- Arduino IDE or PlatformIO
- Libraries:
WiFi.hPubSubClient.h
At the top of the file, configure your Wi-Fi and MQTT details:
const char* wifi_network_name = "Nitroduck-BioReactor";
const char* wifi_network_password = "iGEM2025";
const char* mqtt_server_uri = "bioreactor.local";
To select the board mode:
#define MAIN_BOARD 1 // Enable for main (lights) board
// #define MAIN_BOARD 1 // Comment out for pump board
- Connect the ESP32 to your computer via USB.
- Open the file in Arduino IDE or PlatformIO.
- Select the correct board and port.
- Upload the firmware.
This firmware communicates with the BioReactorManager (Raspberry Pi software) via MQTT.
The corresponding repository can be found here:
👉 BioReactorManager Repository
Detailed hardware design, sensor integration, and system overview are documented on our iGEM wiki:
🔗 iGEM Brno 2025 Hardware Page
This project is licensed under the MIT License.
You are free to use, modify, and distribute this code for any purpose with attribution.
Developed by the iGEM Brno 2025 hardware subteam.
Primary author: Martin Pavella