Introduction
This is the latest DS18B20 1-Wire digital temperature sensor from Dallas. The DS18B20 Digital Thermometer provides 9 to 12-bit (configurable) temperature readings which measure the temperature.
Because each DS18B20 contains a unique silicon serial number, multiple DS18B20s can exist on the same 1-Wire bus. This allows for placing temperature sensors in many different places.
Features
Unique 1-Wire interface requires only one port pin for communication
Multi drop capability simplifies distributed temperature sensing applications
Requires no external components
Can be powered from data line. Power supply range is 3.0V to 5.5V
Zero standby power required
Measures temperatures from -55°C to +125°C. Fahrenheit equivalent is -67°F to +257°F
±0.5°C accuracy from -10°C to +85°C
Thermometer resolution is programmable from 9 to 12 bits
Converts 12-bit temperature to digital word in 750 ms (max)
User-definable, nonvolatile temperature alarm settings
Alarm search command identifies and addresses devices whose temperature is outside of programmed limits (temperature alarm condition)
Application
HVAC environmental controls
sensing temperatures inside buildings
equipment or machinery
process monitoring
Usage
[code]
#include <OneWire.h>
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2
void setup(void) {
Serial.begin(9600); //Set the serial baud rate at 9600
}
void loop(void) {
float temperature = getTemp(); //will take about 750ms to run
Serial.println(temperature);
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(750); // Wait for temperature conversion to complete
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
[/code]
Resource