Description
The DS18B20 digital thermometer provides 9-bit to 12-bit temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points.
The c communicates over a 1-Wire® bus that requires only one data line (and ground) for communication with microcontroller. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.
Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microcontroller to control many DS18B20s distributed over a large area.
Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery.
Features
- Unique 1-Wire® interface requires only one port pin for communication
- Each device has a unique 64-bit serial code stored in an onboard ROM
- Can be powered from data line. Power supply range is 3.0V to 5.5V
- Measures temperatures from –55°C to +125°C
- Thermometer resolution is user-selectable from 9 to 12 bits
- User-definable nonvolatile (NV) alarm settings with Alarm search command identifies devices whose temperature is outside of programmed limits.
Size: 28mm X12mm X10mm
Working voltage: DC 5V
The main chip: 18B20 temperature sensor
1, resolution adjustment range: 9-12
2, with mounting holes for easy installation, pore size: 2.5
3, the temperature measurement accuracy: 0.5 centigrade
4, working voltage: DC5V
5, the temperature measurement range: -55~+125 centigrade
6, the digital signal output
Hardware required
- Arduino Uno
- jumpers wires
- DS18B20 digital temperature sensor
Connecting the Hardware
Upload the CODE
#include <OneWire.h>
#include <DallasTemperature.h>
const int ONE_WIRE_BUS = 2; // Define a pin for communicating to the DS18B20 device via the oneWire bus.
OneWire oneWireLocal(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with the DS18B20 device
DallasTemperature sensorsLocal(&oneWireLocal); // Pass this oneWire reference to DallasTemperature
float tempLocal = 0.0; // Variable for holding the temperature returned from the sensor
//===============================================================================
// Initialization
//===============================================================================
void setup()
{
Serial.begin (9600); // Set output window comm rate
sensorsLocal.begin();
}
//===============================================================================
// Main
//===============================================================================
void loop()
{
CheckTemps(); // Call the routine that actually does the work
Serial.print(“Current Temp: “); // Printout the results
Serial.println(tempLocal);
delay(1000);
}
//===============================================================================
// Subroutines
//===============================================================================
void CheckTemps()
{
sensorsLocal.requestTemperatures(); // Send command to get temperature from the DS18B20
// The sensor will return reading from previous request unless a delay is used to give it time to
// complete the reading request. If polling every second like we are doing here, the delay can be ignored.
delay(100);
tempLocal = sensorsLocal.getTempCByIndex(0); // There can be more than one device on this same bus
// so we need to use the first index of (0)
}