General Description

The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central micro-processor. 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 microprocessor 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, and process monitoring and control systems.

Applications

  1. Thermostatic Controls
  2. Industrial Systems
  3. Consumer Products
  4. Thermometers
  5. Thermally Sensitive Systems

Specifications

The module uses a single-bus digital temperature sensor DS18B20, the external power supply voltage Range is 3.0 V to 5.5 V, No standby power. Measurement temperature range of -55 ° C to +125 ℃, Fahrenheit equivalent 67 ° F to 257 ° F, -10 °C to +85 ° C range accuracy of ± 0.5 ° C.
The temperature sensor is a programmable resolution of 9 to 12 temperature conversion to 12-bit digital format With a maximum of read rate 750 milliseconds with User definable nonvolatile temperature alarm settings. each DS18B20 contains a unique serial number, can be with a plurality ds18b20s Exists in a bus. Temperature sensor can be placed at different places to measure temperature.

Components Required

  1. Arduino controller × 1
  2. DS18B20 Temperature Sensor Module × 1
  3. USB data cable × 1
  4. download and install the OneWire libary
  5. Data sheet DS18B20 pdf

Arduino Connections with KY-001 Temperature Sensor Module

Pin (-) = connect to Arduino GND
Pin (middle) = connect to arduino +5V
Pin (S) = Signal, in this example connect to Arduino Digital port 2
When everything is properly connected, there is a led on the module that blinks when the sensor is read.

Arduino Code for KY-001 Temperature Sensor Module

//Steps2Make.com
#include <OneWire.h>

// DS18S20 Temperature chip i/o
OneWire ds(2); // on pin 2

void setup(void) {
// initialize inputs/outputs
// start serial port at baud rate of 9600
Serial.begin(9600);
}

void loop(void) {
//For conversion of raw data to C
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;

byte i;
byte present = 0;
byte data[12];
byte addr[8];

//Find all devices connected on oneWire Bus
if ( !ds.search(addr)) {
Serial.print("No more addresses.\n");
ds.reset_search();
return;
}

Serial.print("R=");
for( i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}

if ( addr[0] == 0x10) {
Serial.print("Device is a DS18S20 family device.\n");
}
else if ( addr[0] == 0x28) {
Serial.print("Device is a DS18B20 family device.\n");
}
else {
Serial.print("Device family is not recognized: 0x");
Serial.println(addr[0],HEX);
return;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratch pad

Serial.print("P=");
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print( OneWire::crc8( data, 8), HEX);
Serial.println();

//Conversion of raw data to C
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25

Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;

Serial.print("Temprature:");
if (SignBit) // If its negative
{
Serial.print("-");
}
Serial.print(Whole);
Serial.print(".");
if (Fract < 10)
{
Serial.print("0");
}
Serial.print(Fract);

Serial.print("\n");
//End conversion to C
}

Results on Serial Monitor

If everything is okay you should see the temperature being measured and showed in the Serial monitor.

R=28 FF 54 87 36 16 4 B5 Device is a DS18B20 family device.
P=1 5C 1 4B 46 7F FF C 10 D7 CRC=D7
Temperature: 21.75
No more addresses.
R=28 FF 54 87 36 16 4 B5 Device is a DS18B20 family device.
P=1 5C 1 4B 46 7F FF C 10 D7 CRC=D7
Temperature: 21.81
No more addresses.

Responses