analog temperature sensor to digital sensor

Hi, i have this code that works well with an analog temperature sensor, but i only have a digital sensor temperatura, exactly the 18b20, how do i change the code? I try to use some parts of this code (http://www.superiorisesto.it/arduinoprog/archives/313) but I did not succeed. Thanks

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>

/* ***
COMPILARE CON ARDUINO 1.0 o successive
controllare un attuatore via web
con sensori di temperatura e luce
ARDUINO UNO
ETHERNET SHIELD
by GianniFavilli.it - www.giannifavilli.it
*** */

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac address
byte ip[] = { 192, 168,1, ***}; // ip arduino internet in
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

int outPin = 9; // pin attuatore
//char link[]="http://www.giannifavilli.it"; //link
String readString; //string
boolean LEDON = false; // flag status attuatore

/termistore/
float temp; // variabile da calcolare
float volt; // variabile da calcolare sul sensore di temperatura
float tempPin = 1; // pin analogico IN temperature sensor
int ledPintemp = 13; // pin led termistore
float tempreg = 25.0; // temperatura di controllo in celsius
/end termistore/

/fotoresistore/
int light; // variabile da calcolare
int ledPinlux = .12; // pin led fotoresistenza
int photoresistor = 0; // pin analogico IN fotoresistore
/end fotoresistore/

void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(outPin, OUTPUT);
pinMode(ledPinlux, OUTPUT);
Serial.begin(9600);
}

void loop(){

/inizio calcolo temperatura/
temp = ((5 * analogRead(tempPin) * 100.0 ) / 1024) - 50; // Codice ottimizzato

/*
(grazie giulio400 e jumpjack)
volt = ( analogRead(tempPin) * 5) / 1024; // calcolo il valore letto e lo trasformo in valore di tensione
temp = (volt - 0.5) * 100; // conversione MCP9700A
*/
/fine calcolo temperatura/

/inizio luce/
light = analogRead(photoresistor);
light = constrain(light, 0, 1023); // limiti dei valori tra 0 e 100
light = map(light, 0, 150, 255, 0);
/fine luce/

/inizio client/
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c); //store characters to string
//if HTTP request has ended
if (c == '\n' && currentLineIsBlank) {
Serial.print(readString);
if(readString.indexOf("L=1") > 0) {// lettura del valore se il LED si deve accendere
// il led sarà acceso
digitalWrite(outPin, HIGH); // accendo il led
LEDON = true;
Serial.print("ON pin ");
Serial.println(outPin);
}
else
{
//il led sarà spento
digitalWrite(outPin, LOW); //sengo il led
LEDON = false;
Serial.print("OFF pin ");
Serial.println(outPin);
}

// COSTRUZIONE PAGINA HTML
client.println("HTTP/1.1 200 OK.....");
client.println("Content-Type: text/html");
client.println();
// inizializzo pagina (da togliere se uso ajax)
client.print("ARDUINO Controllo Led via WEB");
//inizai il body
client.println("

"); //risoluzione per nokia 5800 640x360
client.println("

STATUS SENSORI


");
//Scrive sul browser il valore del termistore
client.println("

TEMPERATURA = ");
client.print(temp);
client.println(" C

"); if (temp < tempreg) { // scrive sul web freddo se il valore del termistore è basso client.print("

FREDDO

"); } else { // scrive sul web caldo se il valore del termistore è alto client.print("

CALDO

"); }

//Scrive sul browser il valore della fotoresistenza
client.println("

LUCE = ");
client.print(analogRead(light));
client.println("

"); if (light < 150) { // scrive sul web luce se il valore della fotoresistenza è alto client.print("

LUCE

"); } else { // scrive sul web buio se il valore della fotoresistenza è basso client.print("

BUIO

"); } // link per aggiornare pagina e valori client.print("

AGGIORNA SENSORI: CHECK


");

client.println("

CONTROLLO ATTUATORI via internet

");
client.println("
");
client.print("

PIN control n. ");
client.print(outPin);
client.println("

");
client.println("
");
//scrivo il LED status
client.print("PIN status: ");
if (LEDON) {
client.println("ON");
}
else
{
client.println("OFF");
}
client.print("

ACCENDI | SPEGNI

");

// firma
client.println("


");
client.print("

Visita www.giannifavilli.it

");
client.println("
");

// chiudo il div
client.println("

");
// chiudo pagina da togliere se uso ajax
client.println("");

// pulisco la stringa per la successiva lettura
readString="";
//fermo il client
client.stop();

} //if c == /n
} // if client available
} // while client connesso
} // FINE if client

if (temp < tempreg) { // accende o spengo un led se la temperatura è più bassa di quella di controllo
digitalWrite(ledPintemp, HIGH); //accendo
Serial.print("ON pin "); //scrivo in console
Serial.println(ledPintemp); //scrivo in console
}
else {
digitalWrite(ledPintemp, LOW); //spengo
Serial.print("OFF pin "); //scrivo in console
Serial.println(ledPintemp); //scrivo in console
}

if (light < 150) { // accende o spengo un led se la c'è luce
digitalWrite(ledPinlux, HIGH); // accendo
Serial.print("ON pin "); //scrivo in console
Serial.println(ledPinlux); //scrivo in console
}
else {
digitalWrite(ledPinlux, LOW); //spengo
Serial.print("OFF pin "); //scrivo in console
Serial.println(ledPinlux); //scrivo in console
}

} // fine loop

how do i change the code?

Edit the parts that are not right.

I try to use some parts of this code ... but I did not succeed.

That code does something. You want it to do something. If those two somethings were the same thing, I assume that you would not have posted that you have a problem. So, it is probably a safe assumption that the two somethings are not the same. What either one is, though, is a mystery.

Have a look at http://www.arduino.cc/playground/Learning/OneWire.

Note this bit:

To use the sample code with the newer DS18B20 sensor, you'd check for a family code of 0x28, instead, and for the DS1822 you'd check for 0x22.

I want only temperature and pin 9 (relay) , i have tried so..the code is correct but not work

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac address
byte ip[] = { 192, 168,1, 177 }; // ip arduino internet in
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

int outPin = 9; // pin attuatore
//char link[]="http://www.giannifavilli.it"; //link
String readString; //string
boolean LEDON = false; // flag status attuatore

float Temperatura;

void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(outPin, OUTPUT);
Serial.begin(9600);
sensors.begin();

}

void loop(){

sensors.requestTemperatures();
Temperatura = sensors.getTempCByIndex(0);

/inizio client/
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c); //store characters to string
//if HTTP request has ended
if (c == '\n' && currentLineIsBlank) {
Serial.print(readString);
if(readString.indexOf("L=1") > 0) {// lettura del valore se il LED si deve accendere
// il led sarà acceso
digitalWrite(outPin, HIGH); // accendo il led
LEDON = true;
Serial.print("ON pin ");
Serial.println(outPin);
}
else
{
//il led sarà spento
digitalWrite(outPin, LOW); //sengo il led
LEDON = false;
Serial.print("OFF pin ");
Serial.println(outPin);
}

// COSTRUZIONE PAGINA HTML
client.println("HTTP/1.1 200 OK.....");
client.println("Content-Type: text/html");
client.println();
// inizializzo pagina (da togliere se uso ajax)
client.print("ARDUINO Controllo Led via WEB");
//inizai il body
client.println("

"); //risoluzione per nokia 5800 640x360
client.println("

STATUS SENSORI


");
//Scrive sul browser il valore del termistore
client.println("

TEMPERATURA = ");
client.print(sensors.getTempCByIndex(0));
client.println(" C

");

}

}
// link per aggiornare pagina e valori
client.print("

AGGIORNA SENSORI: CHECK


");

client.println("

CONTROLLO ATTUATORI via internet

");
client.println("
");
client.print("

PIN control n. ");
client.print(outPin);
client.println("

");
client.println("
");
//scrivo il LED status
client.print("PIN status: ");
if (LEDON) {
client.println("ON");
}
else
{
client.println("OFF");
}
client.print("

ACCENDI | SPEGNI

");

// firma
client.println("


");
client.print("

Visita www.giannifavilli.it

");
client.println("
");

// chiudo il div
client.println("

");
// chiudo pagina da togliere se uso ajax
client.println("");

// pulisco la stringa per la successiva lettura
readString="";
//fermo il client
client.stop();

} //if c == /n
} // if client available
} // while client connesso

i have tried so..the code is correct but not work

If it doesn't work, how can it be correct? What does it do? What do you want it to do?

I said that is correct because when i click on verify there are no problems. When i open the internet page there aren't information that i want. Arduino con controllo remoto via HTTP | GianniFavilli.it
i want to see the temperature and turn on and turn off a relay

If you want to find how to read the temperature then put that sketch to one side and write a new test sketch that only reads and prints the temperature. There are loads of examples of how to do that for the sensor you're using. Once you have the code for that working, it's just a matter of adding that working function to your original sketch and calling it in the right place. But trying to debug that while you're mucking about with Ethernet and so on is a waste of time.

it's just a matter of adding that working function to your original sketch and calling it in the right place. Why??

I've have got already the code that only reads and prints the temperature with a IC2 lcd display. Is this:

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

#define ONE_WIRE_BUS 2
#define TMIN 24
#define ISTERESI 2
int Relay = 5;

LiquidCrystal_I2C lcd(0x27,16,2);
// Data wire is plugged into pin 2 on the Arduino

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

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

float Temperatura;

void setup(void)
{
// start serial port
lcd.init();
lcd.backlight();
lcd.print("TEMPERATURA");
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
pinMode(Relay, OUTPUT);

}

void loop(void)
{
sensors.requestTemperatures();
Temperatura = sensors.getTempCByIndex(0);

if (Temperatura < TMIN)
digitalWrite(Relay, HIGH);
lcd.setCursor(0,1);
lcd.print(sensors.getTempCByIndex(0));
lcd.print(" C");

if (Temperatura >= TMIN+ISTERESI)
digitalWrite(Relay, LOW);
lcd.setCursor(0,1);
lcd.print(sensors.getTempCByIndex(0));
lcd.print(" C");

delay(1000);

}

it's just a matter of adding that working function to your original sketch and calling it in the right place. Why??

Sorry i was wrong.. How?? not Why??