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

Components Needed
- Temperature Sensor (e.g., DS18B20)
- Arduino
- Jumper Wires
Circuit Setup
- Connect the VCC pin of the temperature sensor to 5V on the Arduino.
- 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.

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
- Ensure proper connection to the data pin and that the sensor is in contact with the soil.
- If temperature readings are erratic, check for sensor wiring issues.