002 Read DS18B20 temp. with Arduino language

1. Forewords

Again this is a simple example which come with the library

2. Set the board

Remove the LCD display and make the following wire connection:

Wire  connections
 ATmega pins
Peripheral pins
 Assigned name
 Digital 2
Connect the DS18B20 pin
one_wire pin

Then connect USB cable and write the following sketch in Arduino IDE:

3. The sketch

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

void setup(void)
  // start serial port
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library

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 temperatures
  //Serial.print("Temperature for the device 1 (index 0) is: ");
Then upload the sketch on your board and start the console.

4. Results

Click to zoom