Interfacing PIC MCU with DHT11 sensor – mikroC Projects

This topic shows how to interface Microchip PIC16F887 microcontroller with DHT11 (RHT01) relative humidity and temperature sensor (digital sensor) where the compiler used in this project is MikroElektronika mikroC Pro for PIC.

Related Projects:
DHT22 Sensor interface with PIC microcontroller – mikroC Projects
Interfacing PIC16F887 with DHT11 sensor – CCS C compiler

Hardware Required:

  • PIC16F887 microcontroller   —> datasheet
  • DHT11 Sensor (RHT01)    —>  datasheet
  • 16×2 LCD screen
  • 10k variable resistor (or potentiometer)
  • 4.7k ohm resistor
  • 5V Power source
  • Breadboards
  • Jumper wires
  • PIC MCU Programmer (PICkit 3, PICkit 4…)

Interfacing PIC MCU with DHT11 sensor circuit:
Circuit diagram is shown below.

mikroc dht11 sensor circuit with PIC16F887

(All grounded terminals are connected together).
The DHT11 sensor has four pins (from left to right):
Pin 1: VCC pin, connected to circuit VCC (+5V).
Pin 2: data pin, connected to PIC16F887 microcontroller RB0 pin.
Pin 3: not connected pin.
Pin 4: GND pin, connected to circuit ground.

The 1602 LCD screen (2 rows and 16 columns) is used to display the RMS value of the applied voltage, it is connected to the PIC18F46K22 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.

The internal oscillator of the microcontroller is used and MCLR pin function is disabled.

Interfacing PIC MCU with DHT11 sensor mikroC Pro for PIC code:
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 DHT11 sensor.
unsigned short Check_Response(): used to detect the response signal which comes from the DHT11 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).

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 “Interfacing PIC MCU with DHT11 sensor – mikroC Projects”

  1. Hello thank you for your effort, i would like to know why do i get time out! message on my lcd display, and how to fix that.
    I would be grateful

    1. The resolution of the DHT11 sensor is 1°C which means there is no decimal part (because the second byte of the temperature is always 0).
      DHT22 Provides a resolution of 0.1°C, that means always there is one number after the decimal point.

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