Soil temperature at three depths
Build it step by step
0 of 6 doneWire the bus
Connect three probes in parallel with the single 4.7 kΩ pull-up.
Identify the probes
Warm each in your hand while watching a scanner sketch, and label them.
Edit the order
Set ORDER so index 0 is the 5 cm probe, 1 the 15 cm and 2 the 30 cm.
Add the clock and card
Wire the DS3231 and SD module and check a line is written every 15 minutes.
Bury the probes
Push them to 5, 15 and 30 cm in the same soil, away from roots.
Log a day
After 24 hours plot the three columns in a spreadsheet.
How do you build a soil temperature at three depths?
Three DS18B20 probes on one wire sit 5, 15 and 30 cm deep and log how heat moves through soil over a day. You need Arduino Nano, DS18B20 waterproof probe × 3, Resistor 4.7 kΩ, MicroSD Card Module, DS3231 RTC module and Waterproof enclosure IP65 (junction box). It takes 6 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- PassivesBuyResistor 4.7 kΩ × 1
- InterfacesBuy
- SensorsBuy
- Mechanical & HardwareBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| All DS18B20 probe red wires | Nano 5V | Power |
| All DS18B20 probe black wires | Nano GND | Ground |
| All DS18B20 probe yellow wires | Nano D2 | One shared data line |
| 4.7 kΩ resistor | D2 and 5V | Pull-up for the bus |
| DS3231 SDA, SCL | Nano A4, A5 | I2C |
| DS3231 VCC, GND | Nano 5V, GND | Power |
| SD module CS | Nano D10 | Chip select |
| SD module MOSI, MISO, SCK | Nano D11, D12, D13 | SPI |
| SD module VCC, GND | Nano 5V, GND | Power |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "OneWire", "DallasTemperature" and "RTClib". Set the clock once with RTClib's ds3231 example. Keep the Nano, SD card and clock dry in the IP65 box and bring only the probe cables out through cable glands, sealed with silicone. Use the lead lengths the probes ship with, or extend with twisted-pair cable.
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).
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <RTClib.h>
#include <SD.h>
OneWire oneWire(2);
DallasTemperature sensors(&oneWire);
RTC_DS3231 rtc;
const byte SD_CS = 10;
const unsigned long INTERVAL_MIN = 15;
// Probe order on the bus (0, 1, 2). Run the bus scanner (one-wire-sensor-bus build), warm each probe,
// and edit this table so the probe at 5, 15 and 30 cm are in the right places.
const byte ORDER[3] = { 0, 1, 2 };
unsigned long lastMinute = 255;
void setup() {
Serial.begin(9600);
sensors.begin();
rtc.begin();
SD.begin(SD_CS);
File f = SD.open("SOIL.CSV", FILE_WRITE);
if (f) { f.println("time,t5cm,t15cm,t30cm"); f.close(); }
}
void loop() {
DateTime now = rtc.now();
if (now.minute() % INTERVAL_MIN == 0 && now.minute() != lastMinute) {
lastMinute = now.minute();
sensors.requestTemperatures();
File f = SD.open("SOIL.CSV", FILE_WRITE);
if (f) {
f.print(now.timestamp());
for (byte d = 0; d < 3; d++) {
DeviceAddress a;
sensors.getAddress(a, ORDER[d]);
f.print(','); f.print(sensors.getTempC(a), 2);
}
f.println();
f.close();
}
}
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 |
|---|---|
| Warm one probe in your hand | Only its column rises |
| Normal daytime | 5 cm probe swings most; 30 cm swings least |
| Midnight | 30 cm is warmer than 5 cm |
| Card in a PC | SOIL.CSV with a new line every 15 minutes |
If it does not work
Only zeros logged
The SD card did not start. Check FAT32 and wiring.
Reads -127
A probe or the pull-up is loose.
Depths mixed up
Warm each probe and fix the ORDER table.
Time stamps wrong
Set the DS3231 and check its coin cell.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the soil temperature at three depths?
Arduino Nano, DS18B20 waterproof probe × 3, Resistor 4.7 kΩ, MicroSD Card Module, DS3231 RTC module and Waterproof enclosure IP65 (junction box).
How long does the soil temperature at three depths take to build?
About 120 minutes for a intermediate maker, in 6 steps.
How do I know the soil temperature at three depths works?
Warm one probe in your hand: Only its column rises. Normal daytime: 5 cm probe swings most; 30 cm swings least. Midnight: 30 cm is warmer than 5 cm.
Only zeros logged: what should I check?
The SD card did not start. Check FAT32 and wiring.
Reads -127: what should I check?
A probe or the pull-up is loose.
Depths mixed up: what should I check?
Warm each probe and fix the ORDER table.
Time stamps wrong: what should I check?
Set the DS3231 and check its coin cell.
