[vc_row][vc_column width=”1/1″][vc_column_text]DHT11 Temperature and Humidity Sensor features a calibrated digital signal output with the temperature and humidity sensor complex,ensureing the high reliability and excellent long-term stability. A high-performance 8-bit microcontroller is connected. This sensor includes a resistive element and a sense of wet NTC temperature measuring devices. It has excellent quality, fast response, anti-interference ability and high cost performance advantages.
DHT11 pin explanation:
[table]
Pin, Name, Comments
1,VDD, Suppy 3-5.5V
2, DATA, Single wire serial data
3, NC, floating
4, GND, Ground
[/table]
[/vc_column_text][vc_tour][vc_tab title=”BOM” tab_id=”1384469281-1-13″][vc_column_text]1. pcDuino experiment platform
2. 1 x RED LED
3. 1 x Yellow LED
4. 2 x resistors of 220 ohm
5. 1 x resistor of 10K ohm
6. Jump wire[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1384469281-2-47″][vc_column_text][/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1384469693949-2-10″][vc_column_text]The full code can be downloaded from here ( DHT11).
Copy the directory named ‘dht’ to directory /home/ubuntu/Arduino/libraries on pcDuino.
Restart the application Arduino IDE:
The main code is as following:
#include <core.h>
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 7
int H_Led = 2;
int T_Led = 3;
void setup()
{
pinMode(H_Led,OUTPUT);
pinMode(T_Led,OUTPUT);
printf("DHT11 Monitoring\n");
}
void loop()
{
int val = DHT11.read(DHT11PIN);
printf("Read sensor: %d\n", val);
switch (val)
{
case DHTLIB_OK:
printf("OK \n");
break;
case DHTLIB_ERROR_CHECKSUM:
printf("Checksum error\n");
break;
case DHTLIB_ERROR_TIMEOUT:
printf("Time out error\n");
break;
default:
printf("Unknown error\n");
break;
}
printf("Humidity (%): %f", (float)DHT11.humidity);
if((DHT11.humidity<=40)||(DHT11.humidity>=60))
digitalWrite(H_Led,HIGH);
else
digitalWrite(H_Led,LOW);
printf("Temperature (oC): %f", (float)DHT11.temperature);
if((DHT11.temperature<=18)||(DHT11.temperature>=25))
digitalWrite(T_Led,HIGH);
else
digitalWrite(T_Led,LOW);
delay(2000);
}
[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1384469855497-3-0″][vc_column_text]The LED will turn yellow when the temperature feel good, and turn red when it is not suitable.
Leave a Reply
You must be logged in to post a comment.