This is an old revision of the document!
Table of Contents
Day 2: Sensors and Communication
Welcome to day two of our IoT workshop series! Today we will read a value from a soil moisture sensor, see it in the Serial Monitor, connect our board to WiFi, and finally send a message to an MQTT broker.
We are using the Arduino framework inside PlatformIO throughout this workshop.
1. How a Capacitive Soil Moisture Sensor Works
A capacitive soil moisture sensor measures how much water is in the soil by detecting changes in capacitance around its probe. Water and dry soil store electrical charge differently, so as the soil gets wetter, the capacitance the sensor measures changes. The sensor turns this into an analog voltage: drier soil and wetter soil produce different voltage levels, which our ESP32 can read.
Unlike older resistive sensors, the capacitive type has no exposed metal electrodes touching the soil. This means it does not corrode nearly as quickly, making it much better suited for long-term use.
We are using the DFRobot Analog Capacitive Soil Moisture Sensor.
๐ท PLACEHOLDER โ Insert a photo of the DFRobot capacitive soil moisture sensor here.
2. Connecting the Sensor to the DOIT ESP32
The sensor has three wires:
| Sensor Pin | Connects to ESP32 | Purpose |
|---|---|---|
| VCC (red) | VIN (5V) or 3V3 | Power |
| GND (black) | GND | Ground |
| AOUT (blue) | An analog-capable GPIO (e.g. GPIO34) | Analog signal out |
A few notes:
- The signal wire goes to an analog input pin. On the DOIT ESP32 DevKit, pins like GPIO34, GPIO35, GPIO32, GPIO33 work well for analog reading.
- The sensor can run on either 3V3 or 5V. The VIN pin on the DOIT ESP32 provides 5V (when the board is powered over USB).
- Important: the ESP32's analog pins can only safely read up to ~3.3V. If you power the sensor from 5V, its output range is higher, so be aware the readings will scale differently โ and never feed more than 3.3V into a GPIO pin.
- Double-check GND is shared between the sensor and the board.
<wrap em>๐ท PLACEHOLDER โ Insert the wiring diagram / photo showing