FiveFeet

Here is a OneWire with DallasTemperature displaying the temperature on a 16x2 LCD Display.

 

 

 

 

 

 

 

Here is a sample code for it:


// include the library code:
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// initialize the library with the numbers of the interface pins
int RS = 8;
int E = 7;
int D4 = 6;
int D5 = 5;
int D6 = 4;
int D7 = 2;
int backlight = 3; //the pin the backlight LED is connected to

// setup for LCD
LiquidCrystal lcd(RS, E, D4, D5, D6, D7);

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(12);

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

//PhotoResistor Pin
int lightPin = 0; //the analog pin the photoresistor is connected to

// RGB LED
int RED = 9;
int GREEN = 10;
int BLUE = 11;

void setup() {
Serial.begin(9600); // used for testing
lookUpSensors(); // used for testing, putting data out to serial

// output pins
pinMode(backlight, OUTPUT); // backlight to lcd
pinMode(RED, OUTPUT); // show when temp is in hot range
pinMode(GREEN, OUTPUT); // show when temp is in normal range (what is normal anyway?)
pinMode(BLUE, OUTPUT); // show when temp is in cold range

// set up the LCD's number of rows and columns:
lcd.begin(16, 2);

// Initialize sensors for oneWire
sensors.begin();
}

void loop() {
sensors.requestTemperatures(); // get temperatures

// set the cursor
lcd.setCursor(10, 0);
lcd.print(sensors.getTempFByIndex(0));

lcd.setCursor(10, 1);
lcd.print(sensors.getTempFByIndex(1));

lcd.setCursor(0, 0);
lcd.print(sensors.getTempFByIndex(2));

lcd.setCursor(0, 1);
lcd.print(sensors.getTempFByIndex(3));

int lightLevel = analogRead(lightPin); //Read the lightlevel
lightLevel = map(lightLevel, 100, 900, 0, 255);
//adjust the value 0 to 900 to
//span 0 to 255
lightLevel = constrain(lightLevel, 0, 255);//make sure the
//value is betwween
//0 and 255
analogWrite(backlight, 255-lightLevel); //write the value

if (lightLevel > 50) {
if (sensors.getTempFByIndex(2) <= 68) {
digitalWrite(BLUE, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(RED, LOW);
} else if (sensors.getTempFByIndex(2) > 68 && sensors.getTempFByIndex(2) < 76) {
digitalWrite(BLUE, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);
} else if (sensors.getTempFByIndex(2) >= 76 && sensors.getTempFByIndex(2) < 80) {
digitalWrite(BLUE, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(RED, HIGH);
} else if (sensors.getTempFByIndex(2) >= 80) {
digitalWrite(BLUE, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(RED, HIGH);
}
} else {
digitalWrite(BLUE, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(RED, LOW);
}

delay(5000); // wait a little time
}

void lookUpSensors() {
byte address[8];
int i=0;
int x=0;
byte ok = 0, tmp = 0;
//start the search
Serial.println("--Search started--");

while (oneWire.search(address)) {
tmp = 0;
//0x10 = DS18S20
if (address[0] == 0x10) {
Serial.print("Device is a DS18S20 : ");
tmp = 1;
} else {
//0x28 = DS18B20
if (address[0] == 0x28) {
Serial.print("Device is a DS18B20 : ");
tmp = 1;
}
}

//display the address, if tmp is ok
if (tmp == 1) {
if (OneWire::crc8(address, 7) != address[7]) {
Serial.println("but it doesn't have a valid CRC!");
} else {
//all is ok, display it
for (i=0;i<8;i++) {
if (address[i] < 9) {
Serial.print("0");
}
Serial.print(address[i],HEX);
if (i<7) {
Serial.print("-");
}
}
Serial.print(" : ");
Serial.print(sensors.getTempFByIndex(x));
Serial.println("");
x++;
ok = 1;
}
}//end if tmp
}//end while
if (ok == 0){
Serial.println("No devices were found");
}
Serial.println("--Search ended--");
}