// Start I2C transmission
Wire.beginTransmission(DHT12_ADDRESS);
Wire.write(0x00); // Send the command to read from register 0x00
Wire.endTransmission();
// Request 5 bytes of data from DHT12
Wire.requestFrom(DHT12_ADDRESS, 5);
if (Wire.available() == 5) {
for (int i = 0; i < 5; i++) {
data[i] = Wire.read();
}
// Check the checksum
if (data[4] == (data[0] + data[1] + data[2] + data[3])) {
float humidity = data[0] + data[1] * 0.1;
float temperature = data[2] + (data[3] & 0x7F) * 0.1;
if (data[3] & 0x80) temperature = -temperature;