Eight-point soil moisture map
Build it step by step
0 of 7 doneWire the multiplexer
Connect S0 to S3, SIG, power and enable.
Test one sensor
Print raw values for channel 0.
Wire all eight
Connect each AOUT to its channel and the sensor power.
Calibrate each sensor
Note the dry air and water readings with CALIBRATE true.
Enter the numbers
Fill the DRY and WET arrays.
Turn calibration off
Show percentages on the display.
Install
Seal the boards and place one in each bed.
How do you build an eight-point soil moisture map?
Eight capacitive soil sensors through a 16-channel multiplexer show which beds in a garden are dry on one screen. You need Arduino Nano, CD74HC4067 16-channel mux module, Capacitive Soil Moisture Module × 8, 20x4 LCD with I2C backpack and Multi-core shielded cable 4-core. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 5
Parts list
- Development BoardsBuyArduino Nano × 1
- Integrated CircuitsBuy
- SensorsBuy
- DisplaysBuy
- Cables & Wires
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Mux module VCC | Nano 5V | Power |
| Mux module GND | Nano GND | Ground |
| Mux module EN | Nano GND | Enabled |
| Mux module S0 to S3 | Nano D2, D3, D4, D5 | Channel address bits |
| Mux module SIG | Nano A0 | Selected sensor signal |
| Sensors 1 to 8 AOUT | Mux channels C0 to C7 | One sensor per channel |
| Sensor VCC and GND (all) | Nano 5V and GND | Sensor power |
| LCD 20x4 I2C SDA and SCL | Nano A4 and A5 | Display |
| LCD VCC and GND | Nano 5V and GND | Power |
Code
Capacitive sensors read lower when wetter, so the percentage maps the dry reading to 0 and the wet reading to 100. Every sensor differs, so calibrate each one: with CALIBRATE set to true, hold each sensor in dry air and note the number, then stand the sensing part (not the electronics) in a glass of water up to the line and note the number again, and enter both in the arrays. Seal the top of each sensor board with epoxy or hot glue so water cannot get to the electronics, and use shielded cable for long runs. The display marks beds below 30 percent with an exclamation mark. Note how many hours each bed takes to dry after watering, which tells you the right watering interval. Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Library: LiquidCrystal_I2C. Eight capacitive soil sensors on a 16-channel multiplexer.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
const byte S[4] = {2, 3, 4, 5};
const byte SIG = A0;
const byte N = 8;
int DRY[N] = {600, 600, 600, 600, 600, 600, 600, 600}; // reading in dry air, set per sensor
int WET[N] = {300, 300, 300, 300, 300, 300, 300, 300}; // reading in water, set per sensor
const bool CALIBRATE = false; // true: print raw values only
int readSensor(byte ch) {
for (byte i = 0; i < 4; i++) digitalWrite(S[i], (ch >> i) & 1);
delayMicroseconds(200);
analogRead(SIG); // discard the first reading after switching
long sum = 0;
for (byte i = 0; i < 8; i++) sum += analogRead(SIG);
return sum / 8;
}
void setup() {
for (byte i = 0; i < 4; i++) pinMode(S[i], OUTPUT);
Serial.begin(9600);
lcd.init(); lcd.backlight();
}
void loop() {
for (byte ch = 0; ch < N; ch++) {
int raw = readSensor(ch);
int pct = constrain(map(raw, DRY[ch], WET[ch], 0, 100), 0, 100);
if (CALIBRATE) { Serial.print(raw); Serial.print("\t"); continue; }
byte row = ch / 2, col = (ch % 2) * 10;
lcd.setCursor(col, row);
char b[11];
sprintf(b, "%d:%3d%%%s ", ch + 1, pct, pct < 30 ? "!" : " "); // ! marks a dry bed
lcd.print(b);
}
if (CALIBRATE) Serial.println();
delay(2000);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Dry air | 0 percent |
| Sensor in water to the line | 100 percent |
| Watered bed | Percentage rises within minutes |
| Dry bed | Exclamation mark below 30 percent |
If it does not work
All sensors show the same
Check the address wires S0 to S3.
Readings jump
Add a short delay or more averaging and check the 5 V supply.
A sensor reads zero
Check its wiring and that the channel is the one you think.
LCD blank
Try address 0x3F.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the eight-point soil moisture map?
Arduino Nano, CD74HC4067 16-channel mux module, Capacitive Soil Moisture Module × 8, 20x4 LCD with I2C backpack and Multi-core shielded cable 4-core.
How long does the eight-point soil moisture map take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the eight-point soil moisture map works?
Dry air: 0 percent. Sensor in water to the line: 100 percent. Watered bed: Percentage rises within minutes.
All sensors show the same: what should I check?
Check the address wires S0 to S3.
Readings jump: what should I check?
Add a short delay or more averaging and check the 5 V supply.
A sensor reads zero: what should I check?
Check its wiring and that the channel is the one you think.
LCD blank: what should I check?
Try address 0x3F.
