Hallo zusammen
Habe ein paar fragen zu DS 18b20 Bekomme falsche Werte
Garten: 48.94 Celsius
Wohnzimmer: 40.88 Celsius
Heizkeller: 42.00 Celsius
Aquarium: 43.19 Celsius
Garten müsste 22 Grad haben
habe einen Arduino Mega 2560
Es sind anlegefühler
Habe den sketch von Fluuux habe nur die Sensoradressen eingegeben
Pin 2 und 4,7k nach +5v
Arduino – gezielt einen ds1820 Temperatur-Sensor auslesen
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ds(2); //pin für ds1820
//DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
DeviceAddress sensor1 = { 0x28, 0x7C, 0x97, 0xC7, 0x4, 0x0, 0x0, 0x3C };
DeviceAddress sensor2 = { 0x28, 0x5, 0xC5, 0xAC, 0x4, 0x0, 0x0, 0x20 };
DeviceAddress sensor3 = { 0x28, 0xD6, 0xBA, 0xC8, 0x4, 0x0, 0x0, 0x21 };
DeviceAddress sensor4 = { 0x28, 0x55, 0x14, 0xA8, 0x4, 0x0, 0x0, 0x93 };
//DeviceAddress sensor5 = { 0x28, 0x9A, 0x6C, 0xC8, 00x4, 00x0, 00x0, 0xEB };
char sensor1Name[] = "Garten: ";
char sensor2Name[] = "Wohnzimmer: ";
char sensor3Name[] = "Heizkeller: ";
char sensor4Name[] = "Aquarium: ";
void setup(void)
{
Serial.begin(9600);
}
void writeTimeToScratchpad(byte* address)
{
//reset the bus
ds.reset();
//select our sensor
ds.select(address);
//CONVERT T function call (44h) which puts the temperature into the scratchpad
ds.write(0x44,1);
//sleep a second for the write to take place
delay(1000);
}
void readTimeFromScratchpad(byte* address, byte* data)
{
//reset the bus
ds.reset();
//select our sensor
ds.select(address);
//read the scratchpad (BEh)
ds.write(0xBE);
for (byte i=0;i<9;i++){
data[i] = ds.read();
}
}
float getTemperature(byte* address)
{
int tr;
byte data[12];
writeTimeToScratchpad(address);
readTimeFromScratchpad(address,data);
//put in temp all the 8 bits of LSB (least significant byte)
tr = data[0];
//check for negative temperature
if (data[1] > 0x80)
{
tr = !tr + 1; //two's complement adjustment
tr = tr * -1; //flip value negative.
}
//COUNT PER Celsius degree (10h)
int cpc = data[7];
//COUNT REMAIN (0Ch)
int cr = data[6];
//drop bit 0
tr = tr >> 1;
return tr - (float)0.25 + (cpc - cr)/(float)cpc;
}
void loop(void)
{
float temp1 = getTemperature(sensor1);
float temp2 = getTemperature(sensor2);
float temp3 = getTemperature(sensor3);
float temp4 = getTemperature(sensor4);
Serial.print(sensor1Name);
Serial.print(temp1);
Serial.println(" Celsius");
Serial.print(sensor2Name);
Serial.print(temp2);
Serial.println(" Celsius");
Serial.print(sensor3Name);
Serial.print(temp3);
Serial.println(" Celsius");
Serial.print(sensor4Name);
Serial.print(temp4);
Serial.println(" Celsius");
Serial.println();
delay(1000);
}
bye juergen