DHT12 temperature sensor and Chipkit Max32 example

This article shows how to connect a DHT12 to a Chipkit Max32

The DHt12 is an upgraded version of the classic DHT11 humidity temperature sensor, it is fully downward compatible, more precise and adds an I2C interface.

Features:

compact size
low power consumption
low voltage operation
Standard I2C and 1-wire interface.

Sensing range
Temperature: -20 ~ +60 C
Humidity: 20-95 RH
Humidity:
Resolution: 0.1%RH
Repeat: -+ 1%RH
Precision 25C @ -+5RH
Temperature:
Resolution: 0.1C
Repeat: -+0.2C
Precision: 25C @ -+0.5C
Power: DC 2.7-5.5V
Normal current 1mA
Standby current 60uA
Sample cycle: > 2 seconds

Pin interface: 1. VDD 2. SDA 3. GND 4. SCL (connect to GND when use as 1-wire)

 

Layout

This shows how to connect the DHT12 to an Arduino Uno

chipkit and DHT12 connection

 

Code

This is from https://github.com/dplasa/dht

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <dht.h>

dht12 DHT(0x5c);

void setup()
{
  Serial.begin(9600);
  Serial.println(F("DHT12 TEST PROGRAM"));
}

void loop()
{
  unsigned long b = micros();
  dht::ReadStatus chk = DHT.read();
  unsigned long e = micros();

  Serial.print(F("Read sensor: "));
  switch (chk)
  {
    case dht::OK:
      Serial.print(F("OK, took "));
      Serial.print (e - b); Serial.print(F(" usec, "));
      break;
    case dht::ERROR_CHECKSUM:
      Serial.println(F("Checksum error"));
      break;
    case dht::ERROR_TIMEOUT:
      Serial.println(F("Timeout error"));
      break;
    case dht::ERROR_CONNECT:
      Serial.println(F("Connect error"));
      break;
    case dht::ERROR_ACK_L:
      Serial.println(F("AckL error"));
      break;
    case dht::ERROR_ACK_H:
      Serial.println(F("AckH error"));
      break;
    default:
      Serial.println(F("Unknown error"));
      break;
  }

  Serial.print(F("Humidity: "));
  Serial.print((float)DHT.getHumidity()/(float)10);
  Serial.print(F("%, "));

  Serial.print(F(". Temperature (degrees C): "));
  Serial.print((float)DHT.getTemperature()/(float)10);

  Serial.print(F(", Dew Point (degrees C): "));
  Serial.println(DHT.dewPoint());

  delay(4000);
}

[/codesyntax]

 

Output

Open the serial monitor and you should see something like this

DHT12 TEST PROGRAM
Read sensor: OK, took 8555 usec, Humidity: 61.90%, . Temperature (degrees C): 23.60, Dew Point (degrees C): 15.86
Read sensor: OK, took 8000 usec, Humidity: 62.00%, . Temperature (degrees C): 23.60, Dew Point (degrees C): 15.88
Read sensor: OK, took 8000 usec, Humidity: 62.10%, . Temperature (degrees C): 23.60, Dew Point (degrees C): 15.91
Read sensor: OK, took 8000 usec, Humidity: 62.10%, . Temperature (degrees C): 23.60, Dew Point (degrees C): 15.91
Read sensor: OK, took 8000 usec, Humidity: 62.20%, . Temperature (degrees C): 23.50, Dew Point (degrees C): 15.84
Read sensor: OK, took 8000 usec, Humidity: 62.20%, . Temperature (degrees C): 23.50, Dew Point (degrees C): 15.84
Read sensor: OK, took 8000 usec, Humidity: 62.30%, . Temperature (degrees C): 23.60, Dew Point (degrees C): 15.96
Read sensor: OK, took 8000 usec, Humidity: 62.40%, . Temperature (degrees C): 23.60, Dew Point (degrees C): 15.99
Read sensor: OK, took 8000 usec, Humidity: 62.40%, . Temperature (degrees C): 23.50, Dew Point (degrees C): 15.89

Link

Under $1 for one of these sensors

1pcs DHT-12 DHT12 sensor Digital output Temperature and Humidity Sensor high quality

Related posts

Chipkit Max32 and ADXL335 accelerometer example

Chipkit Max32 and LSM303 Accelerometer example

Chipkit Max32 and LSM303 Magnetometer example

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More