Soil Temperature Detection

Introduction

This experiment shows how to measure the temperature of the soil using a temperature sensor.

Soil Temperature Sensor

Components Needed

Circuit Setup

  1. Connect the VCC pin of the temperature sensor to 5V on the Arduino.
  2. Connect the sensor’s data pin to a digital pin (e.g., D2) on the Arduino.

The sensor will measure the soil temperature and send data to the Arduino.

Soil Temperature Circuit Setup

Code for Soil Temperature Detection

Upload the following code to your Arduino to measure soil temperature:


#include 
#include 

OneWire oneWire(2); // Pin where sensor is connected
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600);
  sensors.begin();
}

void loop() {
  sensors.requestTemperatures();
  float temperature = sensors.getTempCByIndex(0);
  Serial.print("Soil Temperature: ");
  Serial.println(temperature);
  delay(1000);
}
            

Explanation

The DS18B20 temperature sensor detects the temperature of the soil and sends it to the Arduino for display on the Serial Monitor.

Troubleshooting