728x90

728x90

Friday, September 26, 2025

dsPIC30F2010 and DHT-11 Environmental Sensor Interfacing

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.

dsPIC30F2010 and DHT-11 Environmental Sensor Interfacing

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. 

PIC16F84A DHT11 Temperature And Humidity Sensor And Character LCD Interfacing Using XC8
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 
  1. #include <30F2010.h>
  2. #device ICSP=1
  3. #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
  4. #use delay(crystal=20000000)

  5. #define LED0 PIN_D0
  6. #define LED1 PIN_D1
  7. #define SW0 PIN_C13
  8. #define SW1 PIN_C14

  9. #define DELAY 500

  10. #use rs232(UART1, baud=9600, stream=UART_PORT1)

 

  •  main.c
  1. #include "board.h"

  2. #define PIN_DHT11_DATA PIN_B0
  3. #include <dht11.c>

  4. void main(){
  5. unsigned int8 relativeHumidity;
  6. unsigned int8 tempC;
  7. printf("\n\rdsPIC30F2010 Prototype Board.");
  8. printf("\n\rWednesday 25 September 2025");
  9. printf("\n\rDHT-11 Humidity Sensor Example\n\r");
  10. printf("\r\n\r\dht-11.c - DHT11 example starting\r\n\r\n");
  11. dht11_init();
  12. delay_ms(1000);
  13. while(1){
  14. dht11_read(&relativeHumidity, &tempC);
  15. printf("HUMIDITY=%03u%%, TEMPERATURE=%02uC\r\n", relativeHumidity, tempC);
  16. delay_ms(2000);
  17. }
  18. }

 

  • 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

 

  1. #include "board.h"

  2. #define PIN_DHT11_DATA PIN_B0
  3. #include <dht11.c>

  4. #define LCD_RS_PIN PIN_E4
  5. #define LCD_RW_PIN PIN_E5
  6. #define LCD_ENABLE_PIN PIN_E5
  7. #define LCD_DATA4 PIN_E0
  8. #define LCD_DATA5 PIN_E1
  9. #define LCD_DATA6 PIN_E2
  10. #define LCD_DATA7 PIN_E3

  11. #include "lcd.c"

  12. #define lcd_clear() lcd_putc('\f')
  13. #define lcd_home() lcd_putc('\a')
  14. /*For 16x4 LCD Only*/
  15. #define line_1() lcd_send_byte(0,0x80);
  16. #define line_2() lcd_send_byte(0,0xC0);
  17. #define line_3() lcd_send_byte(0,0x90);
  18. #define line_4() lcd_send_byte(0,0xD0);


  19. void main(){
  20. unsigned int8 relativeHumidity;
  21. unsigned int8 tempC;
  22. printf("\n\rdsPIC30F2010 Prototype Board.");
  23. printf("\n\rFriday 26 September 2025");
  24. printf("\n\rDHT-11 Humidity Sensor Example\n\r");
  25. printf("\r\n\r\dht-11.c - DHT11 example starting\r\n\r\n");
  26. dht11_init();
  27. lcd_init();
  28. printf(LCD_PUTC,"dsPIC30F2010 LCD");
  29. line_2();
  30. printf(LCD_PUTC,"DHT-11 Sensor");
  31. line_3();
  32. printf(LCD_PUTC,"Example Using");
  33. line_4();
  34. printf(LCD_PUTC,"CCS PICC v5.119");
  35. delay_ms(5000);
  36. lcd_clear();
  37. while(1){
  38. dht11_read(&relativeHumidity, &tempC);
  39. printf("HUMIDITY=%03u%%, TEMPERATURE=%02uC\r\n", relativeHumidity, tempC);
  40. lcd_home();
  41. printf(LCD_PUTC," DHT-11 Sensor");
  42. line_2();
  43. printf(LCD_PUTC," Reading:");
  44. line_3();
  45. printf(LCD_PUTC,"Humidity: %03u%%",relativeHumidity);
  46. line_4();
  47. printf(LCD_PUTC,"Temperature:%02u%cC",tempC,0xDF);
  48. delay_ms(1000);
  49. }
  50. }

 The TC1604A-04 works fine even it's too old.

dsPIC30F2010 and DHT-11 Environmental Sensor Interfacing
Start-Up Screen


dsPIC30F2010 and DHT-11 Environmental Sensor Interfacing
DHT-11 Sensor Reading and Displaying

Click here to download this example.
 


No comments:

Post a Comment

320x50

Search This Blog

tyro-728x90