// DHT11-Sensor mit 1-Draht-Datenprotokoll // ohne Bibliotheken abfragen // http://www.hjberndt.de/soft/arddht11.html // Reloaded 2023 für ATTiny85 und ATTinyCore #define DHT_PORT 3 // PB3 Pin 2 // TX_PIN 5 Serial default t85 int feuchte, temperatur; char sfeuchte[10],stemperatur[10]; void setup(){ Serial.begin(9600); // TX-Pin 5 Serial.println("DHT11 Messung."); delay(1000); } void loop() {dht11(DHT_PORT); Serial.print("DHT11 Luftfeuchte[%]/Temperatur[C]: "); Serial.print(sfeuchte); Serial.print("/");Serial.println(stemperatur); delay(1000); } void dht11(int pin) {int bitcnt=7,ix=0; uint8_t Byte[5]; for(int i=0;i<5;i++)Byte[i]=0; pinMode(pin, OUTPUT); // REQUEST SAMPLE digitalWrite(pin, LOW); delay(18); digitalWrite(pin, HIGH);delayMicroseconds(30); pinMode(pin, INPUT); pulseIn(pin,HIGH,200); // ACKNOWLEDGE ~ 70 us for (int i=0; i<40; i++) // READ OUTPUT - 40 BITS = 5 BYTE {if (pulseIn(pin,HIGH,200) > 40) Byte[ix] |= (1 << bitcnt); if (--bitcnt < 0)// next byte {bitcnt = 7; // restart ix++; } } feuchte = Byte[0]; //BYTE[1] bei DHT11 immer 0 temperatur = Byte[2]; //BYTE[3] bei DHT11 immer 0 if (Byte[4] != Byte[0]+Byte[2]){feuchte=66;temperatur=66;} itoa(feuchte,sfeuchte,9); itoa(temperatur,stemperatur,9); }