book collections email follower instructable user

Step 4: DS18B20 Digital Temperature Sensor

Learning objectives

  • To measure temperature.
  • To plot the heating curve of a pure substance.
  • To study how the temperature of two substances in thermal contact changes.
  • To analyze how the amount of infrared radiation absorbed by an object is affected by its color.

The DS18B20 digital temperature sensor is a cheap and easy to program device that measures temperatures in the range of −55 ºC to 125 ºC. Its precision is 0.5 ºC for temperatures between −10 ºC and 85 ºC, and 2 ºC for other temperatures.

This sensor uses the 1-Wire protocol for communication with the microcontroller. As each DS18B20 has its own unique serial number, you can connect several sensors to one Arduino pin.

We'll use the waterproof version of this sensor because it can be used to measure temperature in liquids.

Datasheet

https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

Connecting the sensor

The DS18B20 sensor has three pins: two of them are used to power the sensor and the third one to read the data. In the waterproof version the pins can be identified by the color of the wire: red is for positive power (VDD), black for ground (GND) and yellow for data. So the connections to the Arduino board are as follows:

  • Red wire (positive power): +5V
  • Black wire (negative power): GND
  • Yellow wire (data): any digital pin in Arduino

But this time there's one more thing to connect: the 1-Wire bus requires a 4.7 kOhm pull-up resistor between the positive power pin and the data pin. Use a breadboard to make the connections (see the attached images).

Reading the sensor

To use the DS18B20 sensor you need to add two libraries to the Arduino IDE: OneWire, for the communication between the sensor and Arduino, and DallasTemperature, that carries out the calculations in the sensor. You can download them from these links:

Add both libraries to your IDE. Again, to test the sensor you can try an example sketch. In File > Examples, open the Simple sketch in the DallasTemperature examples. Connect the sensor, upload this sketch to your board, open the serial monitor and read the temperatures.

Analyzing the data

If you only want a qualitative analysis of how temperature changes over time, instead of reading the data in the serial monitor you can visualize them in the serial plotter. To do so, go to Tools > Serial Plotter and you'll see the real-time graph of temperature versus time.

You may need to further analyze the data in a spreadsheet. In this case, instead of the example sketch you can use this program that measures temperature approximately every second:

#include <OneWire.h>
#include <DallasTemperature.h>

const int BUS = 2;	// The sensor is connected to digital pin 2
OneWire oneWire(BUS);
DallasTemperature sensor(&oneWire);

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

void loop() {
  sensor.requestTemperatures();
  Serial.println(sensor.getTempCByIndex(0));
  delay(1000);
}

When you run this sketch, the measured temperatures will appear in a column in the serial monitor. So when you have finished taking the measurements, just copy these values and paste them in a spreadsheet.

Activities for students

1. Take two identical empty soda cans. Paint one of them in white, and the other in black. On a sunny day, pour the same amount of tap water in both cans, and introduce a waterproof temperature sensor in each of them. Leave them in the sun for at least half an hour. After this time, check the temperature of the water in the cans. How does the temperature in both of them compare? Can you explain why?

2. Put a small amount of cold water inside a beaker. In a smaller beaker (or plastic cup), pour hot water. With two different sensors, measure the temperature of the water in each beaker. Now carefully introduce the smaller beaker into the beaker with cold water, and record how the temperature in each beaker changes over time, until thermal equilibrium is achieved. Plot the temperature-time graph of the water in both beakers.

3. Heating curve of water (this activity should be carried out as a demonstration by the teacher, for it involves boiling water). Put some water at room temperature in a container, and heat it until it boils. Record the temperature every few seconds. Plot the graph of temperature versus time to obtain the heating curve of water.

Again good ideas, but your target audience is wrong. These demonstrations might be useful in a grade school or primary general science curriculum, not in a physics class.