look at this example
#include <OneWire.h>
#include <LiquidCrystal.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library
LiquidCrystal lcd(12, 11, 9, 8, 7, 6);
int backLight = 13; // pin 13 will control the backlight
OneWire ds(10); // on pin 10 (a 4.7K resistor is necessary)
void setup(void)
{
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(2,16); // rows, columns. use 2,16 for a 2x16 LCD, etc.
lcd.clear(); // start with a blank screen
Serial.begin(115200);
}
void loop(void)
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr))
{
lcd.clear();
lcd.setCursor(0,0); // set cursor to column 0, row 0
lcd.print("No more addrs");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
lcd.clear();
lcd.setCursor(i,0);
lcd.print("ROM =");
//lcd.write(' ');
//lcd.print(addr[i], HEX);
//lcd.setCursor(i+1,0);
delay(600);
Serial.print("ROM =");
for( i = 0; i < 8; i++)
{
Serial.write(' ');
Serial.print(addr[i], HEX);
}
lcd.setCursor(0,1);
lcd.print(addr[1], HEX);
lcd.setCursor(2,1);
lcd.print(addr[2], HEX);
lcd.setCursor(4,1);
lcd.print(addr[3], HEX);
lcd.setCursor(6,1);
lcd.print(addr[4], HEX);
lcd.setCursor(8,1);
lcd.print(addr[5], HEX);
lcd.setCursor(10,1);
lcd.print(addr[6], HEX);
lcd.setCursor(12,1);
lcd.print(addr[7], HEX);
lcd.setCursor(14,1);
delay(700);
if (OneWire::crc8(addr, 7) != addr[7])
{
lcd.clear();
lcd.print("CRC not valid!");
delay(700);
lcd.clear();
Serial.println("CRC is not valid!");
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
// lcd.clear();
// lcd.setCursor(0,0);
// lcd.print("Chip = DS18B20 ");
// delay(1000);
// lcd.clear();
// lcd.setCursor(0,0);
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = ");
Serial.print(present, HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
// lcd.setCursor(0,0);
// lcd.print(data[i], HEX);
// lcd.print(" ");
// delay(2000);
Serial.print(data[i], HEX);
Serial.print(" ");
}
// lcd.setCursor(0,0);
// lcd.print(" CRC=");
// lcd.print(OneWire::crc8(data, 8), HEX);
delay(700);
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Temperature = ");
//lcd.setCursor(0,1);
//lcd.print(celsius);
//lcd.print(" Celsius, ");
delay(700);
lcd.setCursor(0,1);
lcd.print(fahrenheit);
lcd.print(" Fahrenheit");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
Serial.print(" Temp: ");
//Serial.print(celsius);
//Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
}
Look at the example above.
READ YOUR ORIGINAL POST
DOES YOUR ORIGNAL POST SAY ANYTHING AT ALL ABOUT WHAT YOU HAVE DONE, WHAT WORKS , WHAT DOESN'T WORK,
WHETHER OR NOT YOU CAN READ TEMP, WHETHER OR NOT YOUR SWITCH CODE IS WORKING ?
IN FACT DOES IT SAY ANYTHING AT ALL BESIDES "I NEED HELP?"
How are we supposed to help you if you don't follow instructions ?
WHAT DOES THIS SAY ?
SITREP
The first thing we need is a SITREP (Mil-Speak for Situation Report)
We need to know exactly what steps you have taken toward reaching your objective.
In your case you project involves a DS18B20 temp sensor.
We need to know exactly how much you know about this sensor you have.
We need to see you post the datasheet as proof that you have seen it.
We need you to describe how you intend to connect this sensor to your arduino UNO (or have already done so).
We need to know what you have done toward getting the sensor to read data in to the arduino, specifically whether or not you have read in any temperatures. Nothing further will happen on your project until we get the SITREP.