DHT22 Sensor interface with PIC microcontroller – mikroC Projects

Interfacing DHTxx sensors with Microchip PIC microcontroller is so easy as what was done in the last project where PIC16F887 microcontroller is used to read relative humidity and temperature data from DHT11 sensor. Now this topic shows how to interface the PIC16F887 microcontroller with DHT22 sensor with mikroC Pro for PIC compiler.

Related Projects:
Interfacing PIC MCU with DHT11 sensor – mikroC
PIC16F887 Microcontroller with DHT22 digital sensor – CCS C

Hardware Required:

  • PIC16F887 microcontroller
  • DHT22 sensor (AM2302 – RHT03)  —  datasheet
  • 16×2 LCD screen
  • 10k variable resistor (or potentiometer)
  • 4.7k ohm resistor
  • 5V Power source
  • Breadboards
  • Jumper wires

Interfacing PIC microcontroller with DHT22 (AM2302 – RHT03) sensor circuit:
Circuit diagram is shown below.

mikroC DHT22 sensor with PIC microcontroller (AM2302 RHT03)

(All grounded terminals are connected together)

The DHT22 sensor has 4 pins connected to the circuit as (from left to right):
VCC pin connected to +5V,
Data pin connected to PIC16F887 microcontroller RB0 pin (#33),
Not connected pin,
GND pin connected to circuit ground.

The 1602 LCD screen (2 rows and 16 columns) is used to display temperature (in °C) and relative humidity values (in %), it is connected to the PIC16F887 MCU as follows:
RS —> pin RD0
E   —> pin RD1
D4 —> pin RD2
D5 —> pin RD3
D6 —> pin RD4
D7 —> pin RD5
VSS, RW, D0, D1, D2, D3, and K are connected to circuit ground
VEE to the variable resistor (or potentiometer) output
VDD to +5V and A to +5V through 330 ohm resistor.
VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

In this example the PIC16F887 microcontroller runs with its internal oscillator (@ 8MHz) and MCLR pin is configured as digital input pin.

Interfacing PIC microcontroller with DHT22 sensor mikroC code:
mikroC configuration words are:
CONFIG1 : 0x2CD4
CONFIG2 : 0x0700

The configuration words can be changed from: Project –> Edit Project …

Functions used in the code:
void Start_Signal(void): used to send start signal to the DHT22 sensor.
unsigned short Check_Response(): used to detect the response signal which comes from the DHT22 sensor, this function returns 1 if OK and 0 if error.
unsigned short Read_Data(unsigned short* dht_data): this function reads 1 byte (8 bits) from the sensor, data are saved in the variable dht_data. Returns 0 if OK and 1  if error (time out error).

Rest of code is described through comments.

The video below shows a Proteus simulation of the project:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

6 thoughts on “DHT22 Sensor interface with PIC microcontroller – mikroC Projects”

  1. I have the same problem and not only with this exercise but also with other tutorials, I looked online some other they are much better

  2. hi

    could you help me please, i apply every steps but still showing ”No response from the sensor” and i try try try to solve this issue but still same error

  3. Change RB0_bit to RA0_bit
    Change TRISB0_bit to TRISA0_bit
    And connect the DHT22 to the appropriate PORTS pins.
    You’ll also need to change ANSELH = 0 to reference PORTA, you can find the correct code statement in the PIC datasheet.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top