#include #include #include #define DHTPIN 10 // what digital pin we're connected to OneWire ds(2); //pin für ds1820 #define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 // to 3.3V instead of 5V! // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); pinMode(13,OUTPUT); Serial.println("Uebertragnung-Gestartet"); dht.begin(); } void loop() { // Wait a few seconds between measurements. digitalWrite(13,HIGH); delay(5000); digitalWrite(13,LOW); delay(5000); float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // Compute heat index in Celsius (isFahreheit = false) Serial.print("Luftfeuchte: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperatur: "); Serial.print(t); Serial.print(" *C "); } //DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen) DeviceAddress sensor1 = { 0x28, 0xFF, 0x86, 0x2E, 0x74, 0x16, 0x3, 0xAF }; DeviceAddress sensor2 = { 0x28, 0xFF, 0x5, 0x72, 0x74, 0x16, 0x3, 0xE0 }; DeviceAddress sensor3 = { 0x28, 0xFF, 0x2B, 0x3F, 0x73, 0x16, 0x5, 0x60 }; DeviceAddress sensor4 = { 0x28, 0xFF, 0xC5, 0x11, 0x73, 0x16, 0x5, 0x7D }; DeviceAddress sensor5 = { 0x28, 0xFF, 0xC, 0x68, 0x74, 0x16, 0x3, 0x30 }; char sensor1Name[] = "Temp1: "; char sensor2Name[] = "Temp2: "; char sensor3Name[] = "Temp3: "; char sensor4Name[] = "Temp4: "; char sensor5Name[] = "Temp5: "; void loop() { 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(2500); } 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]; if (address[0] == 0x10) // DS18S20 { //check for negative temperature if (data[1] > 0x80) { tr = !tr + 1; //two’s complement adjustment tr = tr * -1; //flip value negative. } //drop bit 0 tr = tr >> 1; //COUNT PER Celsius degree (10h) int cpc = data[7]; //COUNT REMAIN (0Ch) int cr = data[6]; float temp1 = getTemperature(sensor1); float temp2 = getTemperature(sensor2); float temp3 = getTemperature(sensor3); float temp4 = getTemperature(sensor4); float temp5 = getTemperature(sensor5); Serial.print("sensor1Name"); Serial.print(temp1); Serial.println(" C"); Serial.print(sensor2Name); Serial.print(temp2); Serial.println(" C"); Serial.print(sensor3Name); Serial.print(temp3); Serial.println(" C"); Serial.print(sensor4Name); Serial.print(temp4); Serial.println(" C"); Serial.print(sensor5Name); Serial.print(temp5); Serial.print(" C"); return tr - (float)0.25 + (cpc - cr)/(float)cpc; } else // DS18B20 { return ((data[1] << 8) + tr) * (float)0.0625; } return; }