Introduction
This experiment demonstrates how to use a temperature sensor to measure the temperature of water using an Arduino.

Components Needed
- Temperature Sensor (e.g., DS18B20)
- Arduino
- Jumper Wires
Circuit Setup
- Connect the temperature sensor’s VCC and GND pins to the 5V and GND pins on the Arduino.
- Connect the data pin of the sensor to a digital pin on the Arduino (e.g., D2).
The temperature sensor measures the temperature of the water, and the Arduino processes this value to give the water temperature.

Code for Water Temperature Measurement
Upload the following code to your Arduino to measure water temperature:
#include
#include
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.print("Water Temperature: ");
Serial.println(temp);
delay(1000);
}
Explanation
The sensor reads the temperature of the water and sends this value to the Arduino, which processes it and outputs the result to the Serial Monitor.
Troubleshooting
- If no readings are displayed, ensure that the sensor is properly connected to the Arduino.
- Make sure the sensor is fully submerged in water for accurate readings.