PIC16F877A with DHT11 sensor and SSD1306 OLED

This PIC16F877A project shows how build a small weather station for measuring and displaying temperature and relative humidity. The PIC16F877A microcontroller reads the values of the temperature and humidity from DHT11 sensor and display the results on SSD1306 OLED display (128×64 Pixel).

The SSD1306 OLED used in this 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 PIC16F877A with SSD1306 OLED display
Interfacing DHT11 sensor with PIC16F877A – CCS C compiler

Hardware Required:

  • PIC16F877A microcontroller
  • SSD1306 OLED display (128×64 Pixel)
  • DHT11 temperature and humidity sensor
  • 8MHz crystal oscillator
  • 2 x 22pF ceramic capacitor
  • 10k ohm resistor
  • 4.7k ohm resistor
  • 5V power source
  • Breadboard
  • Jumper wires

PIC16F877A with SSD1306 OLED display and DHT11 sensor

PIC16F877A with DHT11 sensor and SSD1306 OLED circuit:
The following image shows project circuit schematic diagram (hardware circuit).

PIC16F877A SSD1306 OLED DHT11 sensor

(All grounded terminals are connected together)

The PIC16F877A microcontroller has one hardware I2C module with SDA on pin RC4 (#23) and SCL on pin RC3 (#18). The SDA pin of the MCU is connected to the SDA pin of the display and the SCL pin of the MCU is connected to the SCL pin of the display.
The reset pin of the display is connected to pin RD4 (#27) of the microcontroller.

The SSD1306 OLED display DC pin is connected to VDD which means the I2C slave address of the display is 0x7A.

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 RD5 (#28). A pull-up resistor of 4.7k ohm is required for the data pin.

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 SSD1306.C, its download link is below:
SSD1306 OLED display driver

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

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:

PIC16F877A + SSD1306 OLED + DHT11 sensor Proteus simulation:
Proteus simulation file download link is below, use it with version 8.6 or higher:
PIC16F877A + SSD1306 OLED + DHT11

The following video shows my simulation result (simulation circuit is not the same as the hardware circuit, hardware circuit diagram is shown above!):


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

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

  1. I am puzzled as how do you determine the actual location for the OLED display, below is your codes for displaying of
    “DHT11 TEMPERATURE:” and “DHT11 HUMIDITY:” at Location XY(3, 1) and XY(5, 6) respectively:

    // clear the whole display
    SSD1306_ClearDisplay();

    SSD1306_GotoXY(3, 1);
    SSD1306_PutC(“DHT11 TEMPERATURE:”);
    SSD1306_GotoXY(5, 6);
    SSD1306_PutC(“DHT11 HUMIDITY:”);

    Based on 128 x 64 resolution of SSD1306 OLED Display module, the display location of “DHT11 HUMIDITY:” line should be XY(20, 40) as shown in the picture of your website.

    How do you determine the actual location for displaying of the message based on the 128 x 64 resolution?

    Thanks,
    Fu DF.

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