DS18B20 thermometer and LPC1768 example

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 microprocessor. 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.

Features

Unique 1-Wire® Interface Requires Only One Port Pin for Communication
Reduce Component Count with Integrated Temperature Sensor and EEPROM
Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
±0.5°C Accuracy from -10°C to +85°C
Programmable Resolution from 9 Bits to 12 Bits
No External Components Required
Parasitic Power Mode Requires Only 2 Pins for Operation (DQ and GND)
Simplifies Distributed Temperature-Sensing Applications with Multidrop Capability
Each Device Has a Unique 64-Bit Serial Code Stored in On-Board ROM

Parts List

Label Part Type Properties
DS1 DS18B20 1-Wire Temperature Sensor
MBED1 mbed LPC1768
R1 4.7kΩ Resistor

Layout

 

mbed and ds18b20
mbed and ds18b20

Code

This uses the mbed library from https://os.mbed.com/components/DS1820/

[codesyntax lang=”cpp”]

#include "mbed.h"
#include "DS1820.h"

#define DATA_PIN        A5
 
DS1820 probe(DATA_PIN);
 
int main() 
{
    while(1) 
    {
        probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        printf("It is %3.1foC\r\n", probe.temperature());
        wait(1);
    }
}

[/codesyntax]

Testing

Using a terminal program such as Teraterm you should see something like this

It is 18.2oC
It is 18.4oC
It is 18.5oC
It is 18.6oC
It is 18.7oC
It is 18.8oC
It is 18.9oC
It is 18.9oC
It is 19.0oC
It is 19.0oC
It is 18.9oC

 

Links

DS18B20 – One Wire Digital Temperature Sensor

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :