Wednesday, December 1, 2010

Two DS18B20 Temp Sensors on LCD Display!

We are finally posting our multi DS18B20 Temp Sensor LCD project. Right now we are monitoring two sensors on one data pin, but could add many such sensors. Just need to add the additional chip id numbers to the code. We will experiment with wire length and outdoor mounting in the near future. Please review and comment.

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

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

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int backLight = 13; // pin 13 will control the backlight

// Data wire is plugged into pin 8 on the Arduino
#define ONE_WIRE_BUS 8

// 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);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x3C, 0xF2, 0xA7, 0x02, 0x00, 0x00, 0xCB };
DeviceAddress outsideThermometer = { 0x28, 0x20, 0x04, 0xA8, 0x02, 0x00, 0x00, 0x4D };

void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);

pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
}

void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
} else {
lcd.print(tempC);
lcd.print("/");
lcd.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop(void)
{
delay(2000);
sensors.requestTemperatures();
lcd.setCursor(0,0);
lcd.print("In: ");
printTemperature(insideThermometer);
lcd.setCursor(0,1);
lcd.print("Out: ");
printTemperature(outsideThermometer);
}

4 comments:

  1. Steve - great work on this. There is a lot of work on the internet about the DS18B20's, but little on simple applications on getting them to perform for the non-technical makers that have no engineering or programing backgrounds. This is important work, so please keep it up. This is a awesome IC that will have a big impact once the power of them are unleashed in simple to follow projects that are replicable by the average maker!!!

    ReplyDelete
  2. Thanks for this info, I've been looking everywhere for info on using multiple DS18B20s as I was struggling with assigning the different IDs to user variables, your post helped loads, thanks

    ReplyDelete
  3. Hi, please where can I find OneWire.h,
    DallasTemperature.h
    and LiquidCrystal.h files?
    Thanks

    ReplyDelete
  4. OneWire.h and DallasTemperature.h are available at http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html. LiquidCrystal.h is included in the Arduino IDE.

    ReplyDelete