Projects / Soil temperature at three depths

Soil temperature at three depths

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. NANODS18B2027.2°C

    Wire the bus

    Connect three probes in parallel with the single 4.7 kΩ pull-up.

  2. NANODS18B2027.2°C

    Identify the probes

    Warm each in your hand while watching a scanner sketch, and label them.

  3. NANODS18B2027.2°C

    Edit the order

    Set ORDER so index 0 is the 5 cm probe, 1 the 15 cm and 2 the 30 cm.

  4. NANOMICROSDS323120:10

    Add the clock and card

    Wire the DS3231 and SD module and check a line is written every 15 minutes.

  5. NANODS18B2027.2°C

    Bury the probes

    Push them to 5, 15 and 30 cm in the same soil, away from roots.

  6. NANO

    Log a day

    After 24 hours plot the three columns in a spreadsheet.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
All DS18B20 probe red wiresNano 5VPower
All DS18B20 probe black wiresNano GNDGround
All DS18B20 probe yellow wiresNano D2One shared data line
4.7 kΩ resistorD2 and 5VPull-up for the bus
DS3231 SDA, SCLNano A4, A5I2C
DS3231 VCC, GNDNano 5V, GNDPower
SD module CSNano D10Chip select
SD module MOSI, MISO, SCKNano D11, D12, D13SPI
SD module VCC, GNDNano 5V, GNDPower

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.

CheckExpected
Warm one probe in your handOnly its column rises
Normal daytime5 cm probe swings most; 30 cm swings least
Midnight30 cm is warmer than 5 cm
Card in a PCSOIL.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 →

Ask Lark AI

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.