DS18S20 DOUBLE

DS18S20Bdouble

#include <OneWire.h>
int DS18S20_Pin1 = 2; //DS18S20 Signal pin on digital 2
int DS18S20_Pin2 = 3;
//Temperature chip i/o
OneWire ds1(DS18S20_Pin1); // on digital pin 2
OneWire ds2(DS18S20_Pin2);
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
float temperature1 = getTemp1();
float temperature2 = getTemp2();
Serial.print(temperature1);
Serial.print(” “);
Serial.println(temperature2);

delay(100); //just here to slow down the output so it is easier to read

}
float getTemp1(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data1[12];
byte addr1[8];
if ( !ds1.search(addr1)) {
//no more sensors on chain, reset search
ds1.reset_search();
return -1000;
}
if ( OneWire::crc8( addr1, 7) != addr1[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}
if ( addr1[0] != 0x10 && addr1[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}
ds1.reset();
ds1.select(addr1);
ds1.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds1.reset();
ds1.select(addr1);
ds1.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data1[i] = ds1.read();
}

ds1.reset_search();

byte MSB = data1[1];
byte LSB = data1[0];
float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

float getTemp2(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data2[12];
byte addr2[8];
if ( !ds2.search(addr2)) {
//no more sensors on chain, reset search
ds2.reset_search();
return -1000;
}
if ( OneWire::crc8( addr2, 7) != addr2[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}
if ( addr2[0] != 0x10 && addr2[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}
ds2.reset();
ds2.select(addr2);
ds2.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds2.reset();
ds2.select(addr2);
ds2.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data2[i] = ds2.read();
}

ds2.reset_search();

byte MSB = data2[1];
byte LSB = data2[0];
float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}