I connected the DHT11 Digital Humidity and Temperature Sensor to the Arduino. Sensor pin, VCC, and Ground from Left to Right. I installed the DHT.h library to the IDE. Download the latest copy. Unzip and copy to your IDE Library directory.
DHT11 Specifications:
- Operating Voltage: 3.5V to 5.5V.
- Operating current: 0.3mA (measuring) 60uA (standby)
- Output: Serial data.
- Temperature Range: 0°C to 50°C.
- Humidity Range: 20% to 90%
- Resolution: Temperature and Humidity both are 16-bit.
- Accuracy: ±1°C and ±1%
Arduino 4 Slave
#include <Wire.h> #include <DHT.h> #include <DHT.h> #define Type DHT11 int sensorPin = 8; DHT HumTemp(sensorPin, Type); float humidity; float tempC; float tempF; int setTime = 1000; void setup() { Serial.begin(9600); Wire.begin(0x4); // join i2c bus with address #4 Wire.onReceive(receiveEvent); // register event HumTemp.begin(); delay(setTime); } void loop() { humidity=HumTemp.readHumidity(); tempC=HumTemp.readTemperature(); tempF=HumTemp.readTemperature(true); Serial.print("Humidity: "); Serial.print(humidity); Serial.print("%"); Serial.print(" Temperature: "); Serial.print(tempC); Serial.print("C "); Serial.print(" Temperature: "); Serial.print(tempF); Serial.println("F "); delay(setTime); } // function that executes whenever data is received from master // this function is registered as an event, see setup() void receiveEvent(int howMany) { }