PIC18F4550 with SSD1306 OLED and DHT11 sensor

In the last PIC18F4550 project I have successfully connected this microcontroller with SSD1306 OLED display (project link is below), and now I am going to build a relative humidity and temperature measurements station using the PIC18F4550 microcontroller and DHT11 digital humidity and temperature sensor where all data are displayed on the SSD1306 display.

The SSD1306 OLED used in this post project is configured to work in I2C mode, some SSD1306 OLED boards may require a small hardware modifications (to select between SPI mode or I2C mode) such as soldering, placing jumpers …

Related Projects:
The following topics may contain some useful information about the current project.
Interfacing PIC18F4550 with SSD1306 OLED
Interfacing PIC18F4550 with DHT11 humidity and temperature sensor

Hardware Required:

  • PIC18F4550 microcontroller
  • SSD1306 OLED display (128×64 Pixel)
  • DHT11 temperature and humidity sensor
  • 4.7k ohm resistor
  • 5V power source
  • Breadboard
  • Jumper wires

PIC18F4550 with SSD1306 OLED display and DHT11 sensor

PIC18F4550 with SSD1306 OLED and DHT11 sensor circuit:
The image below shows project circuit diagram.

PIC18F4550 SSD1306 DHT11 sensor circuit

(All grounded terminal are connected together)

There are 3 wires between the PIC18F4550 microcontroller and the SSD1306 OLED display: SDA (serial data), SCL (serial clock) and reset. SDA and SCL (SCK) pins of the display are connected respectively to pin RB0 (#33) and pin RB1 (#34) of the microcontroller, these pins are hardware I2C module SDA and SCL pins.
The reset pin (RES) of the display is connected to pin RB2 (#35) of the microcontroller.

The SSD1306 OLED display DC pin is connected to VDD which means the I2C slave address of the display is 0x7A. There is no need to use this pin if your display module doesn’t have a reset pin.

The DHT11 sensor has 4 pins (from left to right): VCC (+5V), data pin, NC (not connected pin) and GND. The data pin is connected to pin RB3 (#36). A pull-up resistor of 4.7k ohm is required for the data pin.

In this project the PIC18F4550 runs with its internal oscillator and MCLR pin function is disabled.

The Code:
The C code below is for CCS C compiler, it was tested with version 5.051.

To be able to compile the C code below with no error, a driver for the SSD1306 OLED display is required, it’s name is SSD1306OLED.C, for more information about this driver, visit the following post:
SSD1306 OLED Library for CCS C compiler

It can be downloaded also from the link below:
SSD1306 OLED Library download

after the download, add the driver file to project folder or CCS C compiler drivers folder.

If there is a connection problem or checksum error the display will give “EE.E°C” and “EE.E %” instead of the temperature and humidity values as shown in the simulation video below.

Functions used in the code:
Start_Signal(): this function sends the start signal to the sensor, it sends a logic low for 25 ms and a logic high for 30 us.

Check_Response(): this function checks if there is a response from the sensor (after sending the start signal using the previous function), returns 1 (true) if ok and 0 (false) if error (for example a connection problem).

Read_Data(*dht_data): this function reads temperature and humidity data from the sensor (4 bytes), it also reads an other byte (5th byte) which is used as a checksum. This function returns 0 (false) if data read was ok and 1 (true) if there was a time out problem.

CCS C code:

Finally I made a simulation of the project using Proteus software, simulation file can be downloaded from the link below, use Proteus version 8.6 or higher to open it:
PIC18F4550 + SSD1306 + DHT11

simulation result is shown in this video:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

1 thought on “PIC18F4550 with SSD1306 OLED and DHT11 sensor”

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