Features:
- Temperature Measurement Range: -55 ℃ ~ + 125 ℃.
- Range Accuracy: ±0.5℃.
- Working Power Supply: DC 3 ~ 5V.
- Measurement results in 9 ~ 12 digital quantity way serial transmission.
Pins: (The pins silk print could be different from the picture, but it works the same.)
- Y(S) - Arduino D12
- G(-) - Arduino GND
- R(+) - Arduino Power (3.3V/5V)
Dimensions:
- L 20 x W 11 x H 12mm
Package Includes
-
1 x DS18B20 Temperature Sensor Module
Workshop:
The example will demonstrate the use of an Arduino UNO in requesting and interpreting data from a DS18b20 sensor. Once connected and the program loaded, the serial monitor will display a live temperature readout. This will use the OneWire library created by Paul Stoffregen and the DallasTemperature library created by Miles Burton.
Components
- 1pcs Arduino UNO or Compatible
- 1pcs DS18B20 Temperature Sensor Module
- 3pcs Male to Female Jumper Cables
Wiring
Wire the components together as can be seen in the image below, taking care to match the pin numbers.
Coding
The code consists of the an include, definition, launch, setup and loop. First the OneWire library and the DallasTemperature library are linked to the code. The sensor pin is defined followed by the OneWire library and DallasTemperature library instances established. The setup launches the serial connection and sensor connection. The loop contains the control program that will run continuously after the setup. It begins by requesting the information from the sensor instance. It then prints the value to the serial monitor.
Load the code below into the Arduino IDE and upload it to your board.
/*
A simple program designed to setup and demonstrate the DallasTemperature library and
DS18b20 Temperature probe - BDAA100019
The program uses the OneWire and DallasTemperature libraries to request and
output temperatures from a DS18b20 sensor to the serial monitor.
modified 24 October 2019
by Sebastian Karam - Flux Workshop
The OneWire library created by Paul Stoffregen
https://github.com/PaulStoffregen/OneWire
The DallasTemperature library created by Miles Burton
https://github.com/milesburton/Arduino-Temperature-Control-Library
*/
#include <OneWire.h>
#include <DallasTemperature.h>
// Define the pin that the sensor pin
#define ONE_WIRE_BUS 2
// Establish a oneWire instance
OneWire oneWire(ONE_WIRE_BUS);
// Establish Dallas Temperature instance
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(9600); // Open a serial communication line
sensors.begin(); // Start up the DallasTemperature library
}
void loop(void){
sensors.requestTemperatures(); // Request temperatures from the sensors instance
Serial.print("Temperature (Celsius): "); // Print to the serial monitor
Serial.print(sensors.getTempCByIndex(0)); // Print the temperature from the library to serial monitor
Serial.print("\n"); // Print to the serial monitor
delay(1000); // Pause before restarting the loop
}
Running
With the board is loaded with the program and all the connections made the module will begin to output a temperature in celcius. The animation below shows a brief loop of the sensor being placed beside a cold cup of water then above a a hot cup of water and then back to the cold.
Â