PIC18F46K22 with Nokia 5110 LCD and DHT11 sensor | mikroC Projects

This post shows how to interface PIC18F46K22 microcontroller with DHT11 digital humidity and temperature sensor.
The PIC18F46K22 MCU reads temperature & humidity values from the DHT11 (RHT01) sensor and prints them (respectively in °C and RH%) on Nokia 5110 LCD (84×48 pixel resolution).
MikroC PRO for PIC compiler is used in this project.

To see how to interface PIC18F46K22 MCU with Nokia 5110 LCD using mikroC, visit this post:
Interfacing PIC MCU with Nokia 5110 LCD | mikroC Projects

Hardware Required:

  • PIC18F46K22 microcontroller   —->  datasheet
  • Nokia 5110 LCD module
  • DHT11 (RHT01) humidity and temperature sensor   —->  datasheet
  • AMS1117 3V3 voltage regulator
  • 10 uF capacitor
  • 100 nF ceramic capacitor
  • 5 x 3.3k ohm resistor
  • 5 x 2.2k ohm resistor
  • 4.7k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

PIC18F46K22 with DHT11 sensor and Nokia 5110 LCD

Interfacing PIC18F46K22 with DHT11 sensor and Nokia 5110 LCD circuit:
The following image shows project circuit diagram.

The DHT11 sensor has 4 pins (from left to right):
Pin 1 is power supply pin, connected to circuit +5V,
Pin 2: data output pin, connected to PIC18F46K22 pin RB0 (#33),
Pin 3: not connected pin,
Pin 4: GND (ground), connected to circuit ground.

PIC18F46K22 Nokia 5110 LCD DHT11 sensor circuit

All the grounded terminals are connected together.

The Nokia 5110 which is shown in the circuit diagram has 8 pins (from left to right): RST (reset), CE (chip enable), DC (or D/C: data/command), Din (data in), Clk (clock), VCC (3.3V), BL (back light) and Gnd (ground).

The Nokia 5110 LCD works with 3.3V only (power supply and control lines). The LCD module is supplied with 3.3V which comes from the AMS1117 3V3 voltage regulator, this regulator steps down the 5V into 3.3V (supplies the LCD controller PCD8544 with regulated 3V3).

All PIC18F46K22 microcontroller output pins are 5V, connecting a 5V pin directly to the Nokia 5110 LCD may damage its controller circuit!
To connect the PIC18F46K22 to the LCD module, I used voltage divider for each line. That means there are 5 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.

So, the Nokia 5110 LCD pins are connected to PIC18F46K22 MCU as follows (each one through voltage divider):
RST (reset) pin is connected to pin RD0 (#19)
CE (chip enable) pin is connected to pin RD1 (#20)
DC (data/command) pin is connected to pin RD2 (#21)
DIN (data in)  pin is connected to pin RD3 (#22)
CLK (clock) pin is connected to pin RD4 (#27)

VCC and BL are connected to AMS1117 3V3 regulator output pin and GND is connected to circuit ground (0V).

In this project the PIC18F46K22 microcontroller runs with its internal oscillator @ 16 MHz, MCLR pin is configured as an input pin.

PIC18F46K22 with DHT11 sensor and Nokia 5110 LCD C code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.2.0.

To be able to compile project C code, a driver for the Nokia 5110 LCD is required, download link is below. After you download the driver file which named NOKIA5110.C, add it to your project folder:
Nokia 5110 LCD library for mikroC compiler

The connection of the LCD pins with the microcontroller are defined in the C code as shown below:

And the DHT11 data pin is defined as:

Functions used in the code:
void Start_Signal(void): sends start signal to the DHT11 sensor.

char Check_Response(): checks response signal of the DHT11 sensor (after sending the start signal using the previous function), returns 1 if OK and 0 if error.

void Read_Data(unsigned short* dht_data): reads 1 byte from the DHT11 sensor which is saved to the variable dht_data.

If there is a problem with the DHT11 sensor (for example bad connection) the display will display Sensor (instead of the temperature value) Error! (instead of the humidity value), and if there is a check sum error (for example due to wrong data reading) the display will display Checksum (instead of the temperature value) Error! (instead of the humidity value).

Timer0 module is used to measure pulse widths (high and low), it’s configured to work as 8-bit timer/counter and prescaler = 4 (increment by 1 every 1 microsecond ==> clock input = 1MHz).
Timer0 clock input = Fosc/(4 x prescaler) = 16MHz/(4 x 4) = 1MHz.

Rest of code is described through comments.

Full mikroC code:

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