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 terminal 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!):

Leave a Reply

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