Projects   /   Sensors & Temperature

DHT22 Low Cost Humidity Sensor using PIC18F25K20 with Proteus Simulation

Design and simulate a DHT22 temperature and humidity sensor using PIC18F25K20 in Proteus, displaying real-time data on a 16×2 LCD.

Published
Updated

At a glance

CategorySensors & Temperature
IncludesCode · Proteus · Download files
Reading time~4 min
Jump to a section
  1. Introduction
  2. How the Project Works (Overview)
  3. Block Diagram / Workflow Explanation
  4. Key Features
  5. Components Used
  6. Applications
  7. Explanation of the Code (High-Level)
  8. Source Code
  9. Complete Source Code
  10. Proteus Simulation
  11. (FAQs)
  12. 1. Why does the DHT22 need precise timing?
  13. 2. Can this project run on other PIC18 devices?
  14. 3. Why is Timer2 used instead of delays?
  15. 4. What causes checksum errors in Proteus?
  16. 5. Can I replace DHT22 with DHT11?
  17. 6. Is external crystal required?
  18. 7. Can this project be extended for IoT?
  19. Conclusion
  20. Complete File
  21. DHT22 Low Cost Humidity Sensor using PIC18F25K20 with Proteus Simulation
  22. Quick Solutions to Questions related to DHT22 Low Cost Humidity Sensor using PIC18F25K20 w
  23. Related projects

Summary of DHT22 Low Cost Humidity Sensor using PIC18F25K20 with Proteus Simulation

This project shows interfacing a DHT22 (RHT03) temperature and humidity sensor with a PIC18F25K20 in Proteus, reading 40-bit timed data via a single-wire protocol on RA0, decoding via Timer2 pulse-width measurement, validating with checksum, and displaying results on a 16×2 LCD using XC8 firmware and the PIC internal 4 MHz oscillator.

Parts used in the DHT22 Low Cost Humidity Sensor using PIC18F25K20 with Proteus Simulation:

  • PIC18F25K20 microcontroller
  • DHT22 (RHT03) temperature & humidity sensor
  • 16×2 character LCD (LM016L)
  • 4.7kΩ pull-up resistor
  • 5V power supply
  • Proteus simulation environment

Introduction

This microcontroller project demonstrates how to interface a DHT22 (RHT03) digital temperature and humidity sensor with a PIC18F25K20 using Proteus simulation.
The project reads real-time temperature and relative humidity data and displays it on a 16×2 LCD.
It’s a practical example of embedded systems communication, timing-critical digital sensors, and LCD interfacing.
Designed for learners and hobbyists, this setup is ideal for understanding single-wire sensor protocols in DIY electronics.
The complete firmware is written in MPLAB XC8, making it easy to compile and modify.

DHT22 humidity monitoring prototype
Illustrative View of the Concept.

How the Project Works (Overview)

The PIC18F25K20 communicates with the DHT22 sensor over a single data line connected to RA0.
The microcontroller sends a start signal, waits for the sensor response, and then reads 40 bits of data containing humidity, temperature, and checksum values.
A timer-based approach is used to measure pulse widths, which determines whether each received bit is a logical ‘0’ or ‘1’.
Valid sensor data is processed and displayed on a 16×2 LCD in human-readable form.

Block Diagram / Workflow Explanation

  1. PIC18F25K20 initializes internal oscillator and I/O pins

  2. Start signal sent to DHT22 via RA0

  3. DHT22 responds with timing-encoded digital data

  4. Timer2 measures pulse width for each bit

  5. 40-bit data frame decoded (Humidity, Temperature, Checksum)

  6. Checksum verified to ensure data integrity

  7. LCD displays temperature and humidity values

Key Features

  • Digital temperature and humidity measurement using DHT22

  • Single-wire sensor communication protocol

  • Timer-based pulse width detection

  • Real-time LCD data display

  • Checksum validation for reliable readings

  • Fully simulated in Proteus VSM

  • Uses internal oscillator (no external crystal required)

Components Used

  • PIC18F25K20 microcontroller

  • DHT22 (RHT03) temperature & humidity sensor

  • 16×2 character LCD (LM016L)

  • 4.7kΩ pull-up resistor

  • Power supply (5V)

  • Proteus simulation environment

Applications

  • Weather monitoring systems

  • Indoor climate monitoring

  • Smart home sensor nodes

  • Agricultural humidity tracking

  • Educational embedded systems labs

  • IoT sensor prototyping (with extensions)

Explanation of the Code (High-Level)

  • Initialization section configures oscillator, I/O pins, interrupts, and Timer2

  • Start signal function triggers communication with the DHT22

  • Response check routine confirms sensor presence

  • Byte reading function decodes each bit using pulse width timing

  • Interrupt service routine handles timeout conditions

  • Main loop continuously reads sensor data and updates the LCD

  • Checksum logic ensures data accuracy before display

PIC18F25K20 with DHT22 and 16×2 LCD in Proteus simulation.

Source Code

Download
C source
#include 
#include 
#include "lcd.h"

#define _XTAL_FREQ   4E6

#pragma config IESO = OFF, FOSC = INTIO67, FCMEN = OFF
#pragma config BOREN = OFF, PWRT = OFF
#pragma config WDTEN = OFF
#pragma config CCP2MX = PORTC, PBADEN = OFF, MCLRE = ON
#pragma config DEBUG = OFF, STVREN = ON, XINST = OFF, LVP = OFF

⬇ Download file

Complete Source Code

Proteus Simulation

In Proteus VSM, the PIC18F25K20 executes the XC8 firmware while the DHT22 model generates digital pulse sequences.
The logic analyzer confirms correct timing behavior, and the LCD updates in real time with temperature and humidity values.
This allows complete verification without physical hardware.

(FAQs)

1. Why does the DHT22 need precise timing?

Because data bits are encoded using pulse width, accurate timers are essential.

2. Can this project run on other PIC18 devices?

Yes, with minor pin and configuration changes.

3. Why is Timer2 used instead of delays?

Timer-based measurement ensures accurate bit detection.

4. What causes checksum errors in Proteus?

Incorrect timing, missing pull-up resistor, or wrong clock frequency.

5. Can I replace DHT22 with DHT11?

Yes, but data format and resolution will differ.

6. Is external crystal required?

No, the internal 4 MHz oscillator is sufficient.

7. Can this project be extended for IoT?

Yes, by adding UART, Wi-Fi, or GSM modules.

Conclusion

This project is a clean, real-world example of sensor interfacing, timing-critical communication, and LCD control using a PIC microcontroller.
It’s perfect for anyone learning embedded systems through Proteus simulation and practical electronics.
By studying and modifying this design, you gain hands-on experience with firmware timing, digital sensors, and reliable data handling.

Complete File

⬇ Download file

DHT22 Low Cost Humidity Sensor using PIC18F25K20 with Proteus Simulation

  • Why does the DHT22 need precise timing?
    Because data bits are encoded using pulse width, accurate timers are essential.
  • Can this project run on other PIC18 devices?
    Yes, with minor pin and configuration changes.
  • Why is Timer2 used instead of delays?
    Timer-based measurement ensures accurate bit detection.
  • What causes checksum errors in Proteus?
    Incorrect timing, missing pull-up resistor, or wrong clock frequency.
  • Can I replace DHT22 with DHT11?
    Yes, but data format and resolution will differ.
  • Is external crystal required?
    No, the internal 4 MHz oscillator is sufficient.
  • Can this project be extended for IoT?
    Yes, by adding UART, Wi-Fi, or GSM modules.
  • Where is the sensor data displayed?
    On a 16×2 LCD in human-readable form.
Sensors & Temperature

Spectrum Analyzer using TMS320F28023DA with Proteus Simulation

Introduction This project demonstrates a real-time audio spectrum analyzer using the TMS320F28023DA Piccolo microcontroller, simulated in Proteus VSM. The system captures an...

Sensors & Temperature

Crafting a Microcontroller-Based Temperature Monitoring System

Abstract As technological advancements progress, processes become increasingly intricate, demanding a corresponding expansion in the parameters necessary for efficient analysis. Data acquisition,...

Sensors & Temperature

Automated Room Temperature Monitoring System using Microcontrollers

Abstract Monitoring the temperature within a computer server room stands as a crucial responsibility to uphold the server's performance amidst potential disruptions...

Sensors & Temperature

Innovative Approaches to Control System Design for 100KV Impulse Generators

1. INTRODUCTION An impulse generator is an electrical device designed to generate short-duration surges of high voltage or high current. Impulse signals...

Sensors & Temperature

Smart Baby Incubator: Enhancing Care with PIC Microcontrollers

INTRODUCTION Within the effective Baby Incubator system, the incubator serves as an infant-stimulation apparatus designed for the intensive care of newborns, particularly...

Sensors & Temperature

Microcontroller-Based Laser Pulse Code Detection: Harnessing Pulse Repetition Frequency

This paper presents an enhanced system for detecting and tracking laser-guided weapons through a microcontroller-based decoding mechanism. The system utilizes a 4-quadrant...

Ibrar Ayyub

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough...