Skip to content
Menu
Schubert Codes
  • About
Schubert Codes
November 29, 2026November 29, 2026

Four pots, one ESP32: wiring four soil sensors, a light sensor and a DHT11 (and the ADC2 trap)

In my first build-log post I described the grow chamber I’d like to build, and in my last one I wired a single soil moisture sensor to an ESP32 with my five-year-old. This post scales that up. It’s the hardware on my windowsill now: four pots, four soil sensors, a room thermometer and a light sensor, all run from one small board.

It’s deliberately a hardware-and-wiring post. Where the readings go once they leave the board (a .NET API and a MySQL database on a Ubuntu Linux home server running k3s) is the next one, and after that I’ll show what the data actually said about my plants and some hard lessons about growing plants. For now: what’s on the sill, how it’s wired, and the one trap that cost me an evening.

What’s on the windowsill

By mid-September I had four pots of seedlings, and I wanted to measure each of them. Here’s the sensor list:

– 4 × capacitive soil moisture sensors, one per pot. Capacitive, not the cheaper “fork” type: the fork ones pass a current through the soil and the metal corrodes within weeks. The capacitive ones have no exposed metal in the soil, so they last.

– 1 × DHT11 for room temperature and humidity: the little blue box on the breadboard. It’s not a precise sensor, but for “is the room roughly 19 degrees and roughly 60% humid” it’s fine.

– 1 × light-dependent resistor (LDR) in a voltage divider with a 10k resistor, as a rough light meter. It won’t tell me lux, but it tells me how many hours sunlight this setup gets, which is one of the question I actually have.

– An ESP32 dev board on a screw-terminal breakout board. The screw terminals mean no soldering, and swapping a wire on a Saturday morning takes seconds.

– Two lever connectors (the orange-tabbed blocks) to share power and ground.

That last item is worth a paragraph, because it’s the least glamorous and the most useful. Each soil sensor needs 3.3 V, ground and a signal wire, and the ESP32 only has a few 3V3 and GND pins. A lever connector takes one wire in and gives you five out with no soldering. One block for 3V3, one for ground, and the four sensors plug into those. It’s a tiny thing, but it turned a bird’s nest into something I could pick up and move without everything falling apart.

The pin map

The ESP32’s analogue pins aren’t all equal, so I’ll give the map first and then explain the choices

SensorESP32 PinNotes
Soil Moisture Sensor 1GPIO 32ADC1
Soil Moisture Sensor 2GPIO 33ADC1
Soil Moisture Sensor 3GPIO 34ADC1
Soil Moisture Sensor 4GPIO 25ADC2
LDRGPIO 35ADC1
DHT11GPIO 13Digital

In the firmware it’s just a block of definitions at the top of the sketch:

// Sensor pin definitions

#define DHTPIN    13

#define DHTTYPE   DHT11

#define SOIL1_PIN 32

#define SOIL2_PIN 33

#define SOIL3_PIN 34

#define SOIL4_PIN 25   // ADC2 -- read this BEFORE WiFi starts

#define LDR_PIN   35

GPIO 34 and 35 are input-only pins on the ESP32, which is exactly what you want for a sensor that only ever reports a voltage, so they’re a good home for the third soil sensor and the light sensor. The soil sensors are the three-wire kind: red to the 3V3 lever block, black to the ground block, and the signal wire straight to its own GPIO.

The LDR works differently, because a bare LDR doesn’t output a voltage: it’s just a resistor that changes with light. Put it in series with a fixed 10k resistor between 3V3 and ground, and the midpoint becomes a voltage that moves with the light. That midpoint goes to GPIO 35. With the LDR on the 3V3 side, brighter light gives a higher number and darkness gives a number near zero.

The ADC2 trap

Here’s the one that cost me an evening. I ran out of ADC1 pins, so the fourth soil sensor ended up on GPIO 25, which belongs to the ESP32’s second analogue converter, ADC2. And ADC2 is shared with the WiFi radio. The moment WiFi is switched on, `analogRead()` on an ADC2 pin stops returning anything sensible.

The symptom is nasty because nothing is obviously broken: the sensor is wired correctly, it reads fine on a quick test without WiFi, and then in the real firmware it gives nonsense, but only that one sensor, and only when WiFi is connected.

The fix is purely ordering: read every sensor first, then connect to WiFi. In my firmware all the reads happen at the top of `setup()`, and WiFi doesn’t start until every value is already sitting in a variable:

// 1. Read everything while the radio is still off

int soil1 = analogRead(SOIL1_PIN);

int soil2 = analogRead(SOIL2_PIN);

int soil3 = analogRead(SOIL3_PIN);

int soil4 = analogRead(SOIL4_PIN);   // ADC2: only valid before WiFi

int ldrValue = analogRead(LDR_PIN);

// 2. ...only now bring the radio up

connectToWiFi();

If you ever see one analogue sensor reading rubbish only when WiFi is connected, check which ADC its pin is on before you blame the sensor.

Two small details that saved me

The DHT11 needs a moment. After the board wakes, the DHT11’s electronics need a couple of seconds to settle. Read it too early and you get `NaN` instead of a temperature. So the first thing the sketch does is wait:

delay(2500);   // let the DHT11 settle after boot / wake-up

dht.begin();

float humidity    = dht.readHumidity();

float temperature = dht.readTemperature();

if (isnan(humidity) || isnan(temperature)) {

  humidity = -1.0; temperature = -1.0;   // easy to spot later

}

The board sleeps almost all the time. It’s going to live on a windowsill for months, so it doesn’t sit awake reading sensors. It wakes, reads, reports, and goes back into deep sleep for 15 minutes. This is done to better simulate power conservation when traveling in Space, but even to save power whilst on Earth:

#define TIME_TO_SLEEP  900            // 15 minutes, in seconds

#define uS_TO_S_FACTOR 1000000ULL

esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

// ...read, send...

esp_deep_sleep_start();

That has one odd consequence: after deep sleep the ESP32 boots from scratch as if you’d pressed reset, so everything happens in `setup()` and `loop()` is empty on purpose.

What the light sensor sees

Here’s the cheap LDR doing its job: a week of its readings (23 to 29 Nov) from my own dashboard.

You can see each day as a hump. At night the reading sits at or near zero. In the morning it climbs, and on bright days it peaks above 3,000: the highest point I hovered over was 3,182 at 12:34 on 26 Nov. Duller days top out nearer 2,500. The jagged bits are the light changing through the day.

It’s a raw 12-bit number from the ESP32 (0 to 4095), not lux, and a basic LDR isn’t linear, so I don’t read much into the exact values. What it gives me is a clean “is it day or night, and how bright was today”, which is all I wanted from it.

How to read the numbers

The soil sensor reports a raw number from the ESP32’s 12-bit converter (0 to 4095), and higher means drier, which catches everyone out the first time. From calibrating with my son in the previous post: in open air mine read about 2,450 to 2,500, and dipped in water about 580 to 715. As a rule of thumb, above about 2,000 is dry and below about 1,000 is wet. Every sensor differs slightly, so calibrate each of your own, in air and in water, before you trust it.

What I’d do differently

– Plan your pins around the ADC split before you wire. I’d have saved the ADC2 evening if I’d looked at which converter each pin sits on when I first drew the pin map.

– Lever connectors from day one. I wired the first version with loose jumper wires, and every touch broke something.

– Label the sensors. Four identical sensors and four identical wires is a recipe for swapping two pots when you re-plug them. A strip of tape on each lead would have fixed it.

What’s next

The board now wakes every 15 minutes and holds seven numbers in memory, and then they have to go somewhere. In the next post I’ll show how they travel: the JSON payload, the .NET API that receives it, and why the first version of my database table lasted exactly one day. After that, the interesting bit: the chart of what the soil moisture sensors actually showed over the weeks, and what it taught me about overwatering.

Happy coding!

Search

.Net 6 .NetCore Angular Angular CLI Application Pool AR Arduino Async Augmented Reality C# C/C++ Client Certificates CSR Dependency Injection DHCP DHT11 DNS ElasticSearch ESP32 Firewall gardening IIS Inspiring IoT kids LDR Network Networking Node.js OpenSSL Polly QR Code Rate-limiting Repository Pattern science Self-signed certificate SemaphoreSlim Soil Moisture Sensor SSL Settings Tasks Tech Challenge TLS Unity VS Code WebAPI

Twitter feed is not available at the moment.

If I have seen further it is by standing on the shoulders of Giants

Isaac Newton
©2026 Schubert Codes | Powered by WordPress and Superb Themes!