pia-468x60

pia-728x90

Showing posts with label Environment Sensor. Show all posts
Showing posts with label Environment Sensor. Show all posts

Monday, December 29, 2025

PIC18F4550 DHT-11 LCD CCS Example

The DHT-11 is an environmental sensor converting surrounding temperature and humidity data. It send these data via its digital bi-directional I/O pin. This sensor has only three pins, VCC(+5VDC), Data and GND. Its data pin is an open-drain output that need an external pullup resistor between 4.7kOhm to 10kOhm.

PIC18F4550 DHT-11 LCD CCS Example

It's very popular due to its low cost and ease of use. Many micro-controller can communicate with this device using its digital I/O pin with software bit-banging for data transmission and reception. Many C compiler including Arduino has a variety libraries for this sensor. CCS PICC also has its driver for communicating with this device using a few line of code. Its new compiler version includes the "dht11.c" driver.

Some good programmers use the Assembly language or even XC compiler to write their own routine communicating with this sensor.

PIC18F4550 DHT-11 LCD CCS Example
Proteus Simulation #1

PIC18F4550 DHT-11 LCD CCS Example
Proteus Simulation #2

Proteus has a model for this sensor that we can easily test our program without wiring all components on breadboard.


  1. #include <18F4550.h>
  2. #DEVICE ADC = 10
  3. #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
  4. #use delay(clock=48000000)
  5. #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
  6. #define LCD_ENABLE_PIN PIN_D3
  7. #define LCD_RS_PIN PIN_D2
  8. #define LCD_DATA4 PIN_D4
  9. #define LCD_DATA5 PIN_D5
  10. #define LCD_DATA6 PIN_D6
  11. #define LCD_DATA7 PIN_D7
  12. #include "lcd.c"
  13. #include <dht11.c>
  14. #define lcd_clear() lcd_putc('\f')
  15. void main(){
  16. unsigned int8 relativeHumidity;
  17. unsigned int8 tempC;
  18. printf("\n\rPIC18F4550 DIY USB Prototype Board.");
  19. printf("\n\rWednesday 23 September 2025");
  20. printf("\n\rDHT-11 Humidity Sensor Example\n\r");
  21. printf("\r\n\r\dht-11.c - DHT11 example starting\r\n\r\n");
  22. dht11_init();
  23. lcd_init();
  24. lcd_clear();
  25. printf(LCD_PUTC,"PIC18F4550 LCD\nDHT-11 Example");
  26. delay_ms(5000);
  27. lcd_clear();
  28. while(1){
  29. dht11_read(&relativeHumidity, &tempC);
  30. printf("HUMIDITY=%03u%%, TEMPERATURE=%02uC\r\n", relativeHumidity, tempC);
  31. lcd_gotoxy(1,1);
  32. printf(LCD_PUTC, "Humidity: %03u%%\nTemperature:%02u%cC",relativeHumidity,tempC,223);
  33. delay_ms(2000);
  34. }
  35. }

PIC18F4450 read, displays the environmental data on LCD and sending it over serial port every two seconds. I use its maximum 48MHz clock frequency to get a precise timing.

PIC18F4550 DHT-11 LCD CCS Example
Experiment On Bread Board

This PCB is offered by PCBWay since it's a sponsor project. PCBWay is a long term and well known one-stop service provider including PCB fabrication, PCB assembling (PCBA) etc. Their service and price are reasonable. Beside their standard PCB they offer advanced PCB, flex PCB, CNC parts and 3D printing parts.

DIY PIC18F4550 Prototype Board



Most of PCBs are fabricated within 24 hours with a few days of delivery time. All PCB are checked and verify before sending to fabrication process (pre-production check). Their engineer contact us very soon if their are any problem or doubt.

PCBWay also offer a low cost PCB fabrication of the size 10cmx10cm. We can order it between 5 and 10 units for only 5USD. They are standard double sided PCB with solder mask, silkscreen, circuit testing etc.

DIY PIC18F4550 Prototype Board


For a large scale demand we can order their PCB assembly service at reasonable price for any projects.

DIY PIC18F4550 Prototype Board

Click here to download its source file.





Sunday, July 3, 2022

Arduino Uno Temperature and Humidity Reading with DHT-11 Sensor

DHT-11 is a temperature and humidity sensor module. It use a serial data transmission between the module and the controller. It has the following features:

  • Operating Voltage: 3.5V to 5.5V
  • Operating current: 0.3mA (measuring) 60uA (standby)
  • Output: Serial data
  • Temperature Range: 0°C to 50°C
  • Humidity Range: 20% to 90%
  • Resolution: Temperature and Humidity both are 16-bit
  • Accuracy: ±1°C and ±1%

Arduino Uno Temperature and Humidity Reading with DHT-11 Sensor
A simple DHT-11 Sensor
It's suitable for in-house temperature controlling, or the irrigation system. This module is very popular to apply with the Arduino. The DATA pin of this module is the serial data I/O pin. It requires an additional pull up resistor, typically a 5kOhm resistor.

Arduino Uno Temperature and Humidity Reading with DHT-11 Sensor
Typical connection
In this example, the Arduino Uno will read the environmental data from this module, and it will show on a character display. The LCD I use here is a 16x2 character LCD. I use an additional PCF8574T I2C to parallel I/O to the LCD.

Arduino Uno Temperature and Humidity Reading with DHT-11 Sensor
Arduino running program

The pull up resistor I used here is 10kOhm.

  1. //Two-Wire library
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. //DHT-11 Sensor Library
  5. #include <SimpleDHT.h>
  6.  
  7. //Default address 0x27, LCD is 16x4
  8. LiquidCrystal_I2C lcd(0x27,16,4);
  9.  
  10. //DHT-11 connects to pin A0
  11. SimpleDHT11 dht11(A0);
  12.  
  13. void setup(){
  14. //Initialize the LCD
  15. lcd.init();
  16. //Turn on the backlight
  17. lcd.backlight();
  18.  
  19. //show some information
  20. lcd.print("BTE Technician");
  21. lcd.setCursor(0,1);
  22. lcd.print("Arduino Uno And");
  23. lcd.setCursor(-4,2);
  24. lcd.print("DHT-11 Sensor");
  25. lcd.setCursor(-4,3);
  26. lcd.print("LCD Example");
  27. delay(3000);
  28. lcd.clear();
  29. }
  30.  
  31. byte temperature,humidity;
  32.  
  33. void loop(){
  34. //Get temperature, humidity, and no raw data
  35. dht11.read(&temperature,&humidity,NULL);
  36.  
  37. lcd.setCursor(0,0);
  38. lcd.print("Temperature:");
  39.  
  40. lcd.setCursor(3,1);
  41. lcd.print(String(temperature,DEC)+" "+char(223)+"C");
  42.  
  43. lcd.setCursor(-4,2);
  44. lcd.print("Humidity:");
  45.  
  46. lcd.setCursor(-1,3);
  47. lcd.print(String(humidity,DEC)+" %RH");
  48. delay(3000);
  49. }

Its wiring diagram is shown below.

Arduino Uno Temperature and Humidity Reading with DHT-11 Sensor
Wiring diagram

Click here to download its source file.

Labels

ADC (11) Analog (15) Arduino (12) Atmega16 (19) Audio (2) AVR (20) CCS PICC (3) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) DHT11 (1) Digital I/O (23) Display (37) ds18B20 (1) EEPROM (2) Environment Sensor (2) esp8266 (2) Experiment Board (12) I2C (4) Interrupt (8) LCD (3) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (32) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) pic18 microcontrollers (2) PIC18F4550 (3) PLC (35) PWM (11) Regulator (1) RTC (3) Sensor (9) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (2) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)