DS18B20 Arduino Example
DS18B20 is 1-Wire digital temperature sensor from Maxim IC. Reports degrees in Celsius from -55 to 125 ( /-0.5). Each sensor has a unique 64-Bit Serial number etched into it – allows for a huge number of sensors to be used on one data bus. To use the sensor, we need two libraries: OneWire.h and Arduino-Temperature-Control-Library-master. Pin OUT must be connected to a Vcc 10K ohm resistor, if you don’t do this your sensor will show -127 degrees Celsius.
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
- Requires no external components
- Can be powered from data line.
- Power supply range is 3.0V to 5.5V
- Measures temperatures from –55°C to 125°C (–67°F to 257°F)±0.5°C accuracy from –10°C to 85°C
- Thermometer resolution is user-selectable from 9 to 12 bits


Sketch 2 version:
Libraries:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/* * ForbiddenBit.com * * DS18B20 only Serial Monitor */ // First we include the libraries #include <OneWire.h> #include <DallasTemperature.h> #include <SPI.h> #include <Wire.h> /********************************************************************/ // Data wire is plugged into pin 2 on the Arduino #define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); /********************************************************************/ // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); void setup(void) { // start serial port Serial.begin(9600); Serial.println("ForbiddenBit.com"); sensors.begin(); } void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus /********************************************************************/ Serial.print(" Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperature readings Serial.println("DONE"); /********************************************************************/ Serial.print("Temperature is: "); Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? } |