Community project

C4 Control System

Photo of C4 Control System
Generated with AI

kioki sama

Published November 28, 2026

The C4 Control System is a dual-role ESP32 automation platform that can operate as either an independent watering controller or a fan controller, depending on how each board is configured. It monitors soil moisture across two zones using capacitive sensors, controls 12V submersible pumps via relay modules with flyback diode protection, and includes a low-water float switch safety cutoff. The system supports multiple ESP32 boards working together, each selectable via serial commands to handle watering, fan control, or both.

This guide provides a complete wiring diagram, parts list, calibration procedure, and step-by-step assembly instructions. Builders will learn how to wire the soil moisture sensors, relay modules, and pump power safely, configure the dual-role firmware, calibrate moisture thresholds with the included serial interface, and deploy the system with independent fan controllers. The modular design allows scaling from single-zone gardens to multi-zone installations with coordinated environmental control.

Wiring diagram

Wiring diagram for C4 Control System
Loading diagram…

Gather all the parts

QtyComponent
1

Gravity: IP65 Capacitive Soil Moisture Sensor

Capacitive soil moisture sensor with IP65 waterproof and corrosion-resistant construction. Compatible with Arduino, ESP32, and Raspberry Pi.

1

DFRobot DFR0017 relay module

5V powered, active HIGH TTL control; NO contacts switch pump positive.

1

12V DC Submersible Mini Water Pump

12V, maximum 0.5A running; startup below 2A

Two-wire brushed DC submersible water pump for small irrigation or circulation projects. It is an external load and must be driven through a relay, MOSFET, or motor driver; do not connect directly to an MCU GPIO.

1

1N4001 Flyback Diode

General-purpose silicon rectifier diode used as a flyback / freewheeling diode to suppress back-EMF voltage spikes from inductive loads (DC motors, relays). Rated 50 V reverse voltage and 1 A forward current. Connected in parallel across the motor terminals with cathode (striped band) to the motor positive (+) / 5 V supply side and anode to the motor negative (−) / transistor collector side. Requires no firmware or library — purely passive protection component. Higher-voltage 1N400x rectifier variants are compatible substitutes when the current and package fit the design.

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Gravity: IP65 Capacitive Soil Moisture Sensor

Capacitive soil moisture sensor with IP65 waterproof and corrosion-resistant construction. Compatible with Arduino, ESP32, and Raspberry Pi.

1

DFRobot DFR0017 relay module

5V powered, active HIGH TTL control; NO contacts switch pump positive.

1

12V DC Submersible Mini Water Pump

12V, maximum 0.5A running; startup below 2A

Two-wire brushed DC submersible water pump for small irrigation or circulation projects. It is an external load and must be driven through a relay, MOSFET, or motor driver; do not connect directly to an MCU GPIO.

1

1N4001 Flyback Diode

General-purpose silicon rectifier diode used as a flyback / freewheeling diode to suppress back-EMF voltage spikes from inductive loads (DC motors, relays). Rated 50 V reverse voltage and 1 A forward current. Connected in parallel across the motor terminals with cathode (striped band) to the motor positive (+) / 5 V supply side and anode to the motor negative (−) / transistor collector side. Requires no firmware or library — purely passive protection component. Higher-voltage 1N400x rectifier variants are compatible substitutes when the current and package fit the design.

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Float Switch

Float switch (liquid level switch): a buoyant float carries a magnet that actuates a hermetically sealed reed contact as the liquid rises or falls past the mounting point. Two-wire SPST dry contact (normally-open or normally-closed) with no power supply of its own -- wired like a push-button on a GPIO with INPUT_PULLUP, where open/closed indicates the level is above/below the float. Common for pump on/off control, tank full/empty detection, and sump alarms.

1

12V Barrel-Jack Adapter

12 V / 2 A wall adapter with a 5.5 mm / 2.1 mm barrel jack. Used to power motor drivers, LED strips, or boards that need a higher rail.

1

ESP32-S3-DevKitC-1 N8R8 fan controller

Separate USB-powered controller; GPIO4 controls its fan relay. Same firmware, select fan role by USB serial command.

1

DFRobot DFR0017 relay module

5V powered, active HIGH TTL control; NO contacts switch pump positive.

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Pc Fan

Standard 4-wire PC/case fan (Intel 4-wire PWM spec): always-on +12V power, ground, a ~25 kHz PWM control input (TTL, pulled to 5V or 3.3V), and an open-collector tachometer output (2 pulses/rev, needs an external pull-up to read RPM). Unlike a brushed DC motor it is brushless with built-in commutation, so it is driven directly from an MCU PWM pin rather than through an H-bridge; do not wire it like a bidirectional dc-motor. With no PWM signal it runs at full RPM. 5V 4-wire variants exist but 12V is standard.

1

Pc Fan

Standard 4-wire PC/case fan (Intel 4-wire PWM spec): always-on +12V power, ground, a ~25 kHz PWM control input (TTL, pulled to 5V or 3.3V), and an open-collector tachometer output (2 pulses/rev, needs an external pull-up to read RPM). Unlike a brushed DC motor it is brushless with built-in commutation, so it is driven directly from an MCU PWM pin rather than through an H-bridge; do not wire it like a bidirectional dc-motor. With no PWM signal it runs at full RPM. 5V 4-wire variants exist but 12V is standard.

1

12V Barrel-Jack Adapter

12 V / 2 A wall adapter with a 5.5 mm / 2.1 mm barrel jack. Used to power motor drivers, LED strips, or boards that need a higher rail.

Assemble it in 8 steps

1. Wire sensors with power unplugged

Use one SEN0308 probe per zone. Connect both VCC wires to 3V3 and both GND wires to GND. Zone 1 AOUT goes to GPIO1 (moisture reading); zone 2 AOUT goes to GPIO2.

2. Fit the low-water switch

Mount the float above the pump intakes. Connect SIGNAL to GPIO6 (tank check) and its other wire to GND. Arrange the float so contacts close with enough water and open when low. It needs no VCC. Test both positions before connecting pump power.

  • A reversed or stuck float can let pumps run dry. A broken wire stops watering, but this is not a certified safety system.

3. Wire relay control

Use two DFRobot DFR0017 active-HIGH modules, not an arbitrary active-LOW two-channel board. Connect VCC to the board's USB-powered 5V rail and GND to common GND. Relay 1 IN goes to GPIO4; relay 2 IN to GPIO5. Fit one 10 kΩ resistor between each IN and GND to hold it off during startup.

  • This design uses modules with 3.3V-compatible TTL inputs. Do not connect a 5V-output relay input circuit directly to ESP32 GPIO.

4. Connect pump power and protection

Use small 12V pumps rated at most 0.5A running each, with startup below the adapter's 2A limit. Adapter +12V goes to both relay COM terminals. Each NO terminal goes to its pump positive; leave NC unused. Both pump negatives and adapter negative join common GND. Place one diode across each pump: striped cathode to positive, anode to negative. USB supplies board and relay power, never the pumps.

  • Never connect 12V to ESP32 power or sensor pins. Use enclosed low-voltage adapters only; no mains wiring. Keep motor currents out of breadboard tracks and use insulated screw connections.

5. Place tank and calibrate

Place both pumps in one tank, with separate tubes to the two zones. Keep the tank below tube outlets to prevent siphoning. Keep electronics dry and above the tank. Firmware initially disables watering. With pump power unplugged, read each sensor's millivolts in dry and well-watered drained soil. Set DRY_MV and WET_MV for each probe, then set ENABLE_WATERING to true. Test the float and relay off behavior before reconnecting pump power. Start with supervised short watering tests.

  • Three-second pulses and two-minute soaking pauses are starting settings, not a guaranteed water dose. Do not leave the system unattended until calibrated and tested.

6. Add the independent fan controller

Use a separate ESP32-S3-DevKitC-1 N8R8 powered through its USB port. Its GPIO4 goes to fanRelay IN (on/off control); its 5V pin powers fanRelay VCC. Connect all grounds. Fit fanPulldown between IN and GND. Do not connect the two boards' 5V outputs together. The fanUSB rail represents the second board's USB power, not the 12V adapter.

  • Use the specified DFR0017 module with a 3.3V-compatible control input; never allow 5V onto GPIO4.

7. Connect both fans to their own adapter

Use two 12V four-wire PC fans, each rated no more than 0.5A with combined startup current below 2A. Fan adapter positive goes to fanRelay COM. NO supplies both fan 12V wires. Fan grounds join adapter negative and common GND. Leave each PWM and TACH wire disconnected and individually insulated; with PWM disconnected the fans run at full speed whenever relay power is on. Check the actual connector pin labels rather than relying on wire colors.

  • Keep blades guarded and wiring away from water. Never connect fan 12V to an ESP32 power pin. Use insulated terminals rather than breadboard tracks for fan current.

8. Deploy and select each board's role

Deploy this same firmware to each board separately over USB. On the extra board use the serial console at 115200 baud and send capital F once to save the fan role and restart. Send 1 to turn both fans on or 0 to turn both off. The fans always start off after reset. The watering board defaults to its original role; capital W restores that role if needed. No temperature sensor, wireless link, or cloud is added.

Review all connections

1. Connections between "level" and "ESP32"

FunctionlevelESP32
dataSIGNALGPIO 6
groundGNDGND

2. Connections between "supply" and "ESP32"

FunctionsupplyESP32
power+12V12V
groundGNDGND

3. Connections between "soil1" and "ESP32"

Functionsoil1ESP32
powerVCC3V3
groundGNDGND
analogAOUTGPIO 1

4. Connections between "relay1" and "ESP32"

Functionrelay1ESP32
powerVCC5V
groundGNDGND
digitalINGPIO 4
powerCOM12V
dataNO → 12V DC Submersible Mini Water Pump PUMP+EXT

5. Connections between "pulldown1" and "ESP32"

Functionpulldown1ESP32
digitalP1 → DFRobot DFR0017 relay module INEXT
groundP2GND

6. Connections between "pump1" and "ESP32"

Functionpump1ESP32
groundPUMP-GND

7. Connections between "diode1" and "ESP32"

Functiondiode1ESP32
passiveCathode → 12V DC Submersible Mini Water Pump PUMP+EXT
passiveAnode → 12V DC Submersible Mini Water Pump PUMP-EXT

8. Connections between "soil2" and "ESP32"

Functionsoil2ESP32
powerVCC3V3
groundGNDGND
analogAOUTGPIO 2

9. Connections between "relay2" and "ESP32"

Functionrelay2ESP32
powerVCC5V
groundGNDGND
digitalINGPIO 5
powerCOM12V
dataNO → 12V DC Submersible Mini Water Pump PUMP+EXT

10. Connections between "pulldown2" and "ESP32"

Functionpulldown2ESP32
digitalP1 → DFRobot DFR0017 relay module INEXT
groundP2GND

11. Connections between "pump2" and "ESP32"

Functionpump2ESP32
groundPUMP-GND

12. Connections between "diode2" and "ESP32"

Functiondiode2ESP32
passiveCathode → 12V DC Submersible Mini Water Pump PUMP+EXT
passiveAnode → 12V DC Submersible Mini Water Pump PUMP-EXT

13. Connections between "fanBoard" and "ESP32"

FunctionfanBoardESP32
power5V5V
groundGNDGND

14. Connections between "fanRelay" and "ESP32"

FunctionfanRelayESP32
powerVCC → ESP32-S3-DevKitC-1 N8R8 fan controller 5VEXT
groundGNDGND
digitalIN → ESP32-S3-DevKitC-1 N8R8 fan controller GPIO4EXT
dataNO → Pc Fan 12VEXT
dataNO → Pc Fan 12VEXT

15. Connections between "fanPulldown" and "ESP32"

FunctionfanPulldownESP32
digitalP1 → DFRobot DFR0017 relay module INEXT
groundP2GND

16. Connections between "fanSupply" and "ESP32"

FunctionfanSupplyESP32
power+12V → DFRobot DFR0017 relay module COMEXT
groundGNDGND

17. Connections between "fan1" and "ESP32"

Functionfan1ESP32
groundGNDGND
pwmPWM → Intentionally unconnected for full-speed operationEXT

18. Connections between "fan2" and "ESP32"

Functionfan2ESP32
groundGNDGND
pwmPWM → Intentionally unconnected for full-speed operationEXT

Deploy the firmware

#include <Arduino.h>
#include <Preferences.h>
Preferences settings;
bool fanMode=false;
void commands(){
 while(Serial.available()){
 char c=Serial.read();
 if(c=='F' || c=='W'){
 digitalWrite(4,LOW); digitalWrite(5,LOW);
 settings.putBool("fan",c=='F'); Serial.println("Role saved; restarting"); Serial.flush(); ESP.restart();
 }
 if(fanMode && c=='1'){digitalWrite(4,HIGH);Serial.println("Both fans ON");}
 if(fanMode && c=='0'){digitalWrite(4,LOW);Serial.println("Both fans OFF");}
 }
}
const int SOIL[2]={1,2}, RELAY[2]={4,5}, LEVEL=6;
// Calibrate each sensor with pumps disconnected, then set ENABLE_WATERING true.
const bool ENABLE_WATERING=false;
const int DRY_MV[2]={2500,2500}, WET_MV[2]={1100,1100};
const uint32_t PULSE_MS=3000, SOAK_MS=120000;
bool running[2]={false,false};
uint32_t stopped[2]={0,0}, started[2]={0,0}, goodSince=0;
int moisture[2]={0,0};
bool valid[2]={false,false};
void off(int i,uint32_t now){
 if(running[i]) {running[i]=false; stopped[i]=now;}
 digitalWrite(RELAY[i],LOW);
}
void setup(){
 for(int i=0;i<2;i++){digitalWrite(RELAY[i],LOW);pinMode(RELAY[i],OUTPUT);}
 pinMode(LEVEL,INPUT_PULLUP);
 analogReadResolution(12);
 Serial.begin(115200);
 settings.begin("role",false); fanMode=settings.getBool("fan",false);
 Serial.println("F = fan controller, W = watering controller (saved per board). Fan mode: 1 ON, 0 OFF.");
 if(fanMode){Serial.println("Fan controller: fans OFF at startup");return;}
 Serial.println("Calibration mode: pumps disabled. Close float contact only when water is adequate.");
}
void loop(){
 commands();
 if(fanMode){delay(5);return;}
 uint32_t now=millis();
 bool enough=digitalRead(LEVEL)==LOW;
 if(!enough){goodSince=now;for(int i=0;i<2;i++)off(i,now);}
 bool tankReady=enough && now-goodSince>=2000;
 static uint32_t sampled=0;
 if(now-sampled>=1000){
  sampled=now;
  for(int i=0;i<2;i++){
   uint32_t sum=0;for(int j=0;j<16;j++)sum+=analogReadMilliVolts(SOIL[i]);
   int mv=sum/16;
   valid[i]=mv>100 && mv<3100 && DRY_MV[i]>WET_MV[i];
   moisture[i]=constrain((DRY_MV[i]-mv)*100/(DRY_MV[i]-WET_MV[i]),0,100);
   Serial.printf("Zone %d: %d mV, %d%%, sensor %s; tank %s; pump %s\n",i+1,mv,moisture[i],valid[i]?"OK":"FAULT",tankReady?"OK":"LOW/not ready",running[i]?"ON":"OFF");
  }
 }
 for(int i=0;i<2;i++){
  if(!ENABLE_WATERING || !tankReady || !valid[i] || moisture[i]>=55 || (running[i] && now-started[i]>=PULSE_MS))off(i,now);
 }
 // Run only one pump at a time to limit supply loading.
 if(ENABLE_WATERING && tankReady && !running[0] && !running[1]){
  for(int i=0;i<2;i++)if(valid[i] && moisture[i]<35 && now-stopped[i]>=SOAK_MS){
   running[i]=true;started[i]=now;digitalWrite(RELAY[i],HIGH);break;
  }
 }
 delay(5);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik