The DHT11 temperature and humidity sensor features a temperature and humidity sensor
complex with a calibrated digital signal output. By using the exclusive digital-signal-acquisition
technique and temperature and humidity sensing technology, it ensures high reliability and
excellent long-term stability. This sensor includes a resistive-type humidity measurement
component
and an NTC temperature measurement component, and connects to a high
performance 8-bit micro-controller, offering excellent quality, fast
response, anti-interference
ability and cost-effectiveness.
Its standard TTL bi-directional I/O suitable for dsPIC30F2010 Interfacing and Programming. It needs only three wires, +5VDC, DATA and GND. Its DATA pin requires a weak pull up resistor with a resistance around 4.7k.
I use my dsPIC30F2010 DIY Prototype Board to test this program.
![]() |
DHT11 Humidity & Temperature Sensor |
Parameters
Relative Humidity
Resolution: 16Bit
Repeatability: ±1%RH
Accuracy: 25℃ ±5%RH
Interchangeability: Fully interchangeable
Response time: 1/e (63%)25℃ 6s
1m/s Air 6s
Hysteresis: <±0.3%RH
Long-term stability: <±0.5%RH/yr
Temperature
Resolution: 16Bit
Repeatability: ±1℃
Accuracy: 25℃ ±2℃
Response time: 1/e (63%) 10S
Electrical Characteristics
Power supply: DC 3.3~ 5.5V
Supply current: Measure 0.3mA Standby 60μA
Sampling period: Secondary Greater than 2 seconds
For more detail about interfacing this sensor with a micro-controller please see this post.
dsPIC30F2010 CCS PICC Programming
The newer version of CCS PICC (v5.119) has a C driver for the DHT-11 environmental sensor that could be called using a few lines of code. The "dht11.c" C driver locates in the drivers directory in program files. I use pin RB0 of dsPIC30F2010 to interface with this sensor.
The following example shows a simple sensor reading and data displaying over the RS-232.
- board.h
- #include <30F2010.h>
- #device ICSP=1
- #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
- #use delay(crystal=20000000)
- #define LED0 PIN_D0
- #define LED1 PIN_D1
- #define SW0 PIN_C13
- #define SW1 PIN_C14
- #define DELAY 500
- #use rs232(UART1, baud=9600, stream=UART_PORT1)
- main.c
- #include "board.h"
- #define PIN_DHT11_DATA PIN_B0
- #include <dht11.c>
- void main(){
- unsigned int8 relativeHumidity;
- unsigned int8 tempC;
- printf("\n\rdsPIC30F2010 Prototype Board.");
- printf("\n\rWednesday 25 September 2025");
- printf("\n\rDHT-11 Humidity Sensor Example\n\r");
- printf("\r\n\r\dht-11.c - DHT11 example starting\r\n\r\n");
- dht11_init();
- delay_ms(1000);
- while(1){
- dht11_read(&relativeHumidity, &tempC);
- printf("HUMIDITY=%03u%%, TEMPERATURE=%02uC\r\n", relativeHumidity, tempC);
- delay_ms(2000);
- }
- }
- Memory Use
- Serial Input/Output Monitor
Click here to download this example.
I add a 16x4 LCD (TC1604A-04) to display temperature and humidity data. Using a character LCD is very conventional for most small micro-controller programming and interfacing. I copied the "lcd.c" 16x2 LCD C driver to my project folder that I can modify it without changing the original file. I disable the LCD R/W pin (wire to GND) and I upgrade this LCD driver to a 16x4 LCD.
Its "board.h" header file remains the same to above example.
- main.c
- #include "board.h"
- #define PIN_DHT11_DATA PIN_B0
- #include <dht11.c>
- #define LCD_RS_PIN PIN_E4
- #define LCD_RW_PIN PIN_E5
- #define LCD_ENABLE_PIN PIN_E5
- #define LCD_DATA4 PIN_E0
- #define LCD_DATA5 PIN_E1
- #define LCD_DATA6 PIN_E2
- #define LCD_DATA7 PIN_E3
- #include "lcd.c"
- #define lcd_clear() lcd_putc('\f')
- #define lcd_home() lcd_putc('\a')
- /*For 16x4 LCD Only*/
- #define line_1() lcd_send_byte(0,0x80);
- #define line_2() lcd_send_byte(0,0xC0);
- #define line_3() lcd_send_byte(0,0x90);
- #define line_4() lcd_send_byte(0,0xD0);
- void main(){
- unsigned int8 relativeHumidity;
- unsigned int8 tempC;
- printf("\n\rdsPIC30F2010 Prototype Board.");
- printf("\n\rFriday 26 September 2025");
- printf("\n\rDHT-11 Humidity Sensor Example\n\r");
- printf("\r\n\r\dht-11.c - DHT11 example starting\r\n\r\n");
- dht11_init();
- lcd_init();
- printf(LCD_PUTC,"dsPIC30F2010 LCD");
- line_2();
- printf(LCD_PUTC,"DHT-11 Sensor");
- line_3();
- printf(LCD_PUTC,"Example Using");
- line_4();
- printf(LCD_PUTC,"CCS PICC v5.119");
- delay_ms(5000);
- lcd_clear();
- while(1){
- dht11_read(&relativeHumidity, &tempC);
- printf("HUMIDITY=%03u%%, TEMPERATURE=%02uC\r\n", relativeHumidity, tempC);
- lcd_home();
- printf(LCD_PUTC," DHT-11 Sensor");
- line_2();
- printf(LCD_PUTC," Reading:");
- line_3();
- printf(LCD_PUTC,"Humidity: %03u%%",relativeHumidity);
- line_4();
- printf(LCD_PUTC,"Temperature:%02u%cC",tempC,0xDF);
- delay_ms(1000);
- }
- }
The TC1604A-04 works fine even it's too old.
![]() |
Start-Up Screen |
![]() |
DHT-11 Sensor Reading and Displaying |
Click here to download this example.
No comments:
Post a Comment