sensor-experiments

Introduction

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

Components Needed

No Ads Available.

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.

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

Contact Us

If you have any questions or inquiries, feel free to reach out to us at Microautomation.no@icloud.com .

Follow our Socials for the newest updates!