Temperature monitor with PIC16F877A, SSD1306 and DS18B20 sensor

This topic shows how to connect PIC16F877A microcontroller with SSD1306 OLED display and DS18B20 temperature sensor. The DS18B20 sensor provides 9-bit to 12-bit Celsius temperature measurement resolution (programmable resolution). The default resolution is 12-bit which is used in this project.

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 PIC16F877A with DS18B20 temperature sensor

Hardware Required:

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

PIC16F877A SSD1306 DS18B20 snesor, temperature monitor project

PIC16F877A with SSD1306 and DS18B20 circuit:
Project circuit schematic diagram is shown below.

PIC16F877A SSD1306 DS18B20 temperature 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 DS18B20 temperature sensor has 3 pins: VCC (+5V), data and GND. The data pin is connected to PIC16F877A pin RD5 (#28).

PIC16F877A with SSD1306 and DS18B20 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:
int1 ds18b20_start(): used to know if the DS18B20 sensor is correctly connected to the circuit, returns TRUE (1) if OK and FALSE (0) if error.
void ds18b20_write_bit(int1 value): writes (sends) 1 bit to the DS18B20 sensor, the bit is ‘value’ which may be 1 or 0.
void ds18b20_write_byte(int8 value): writes 1 byte (8 bits) to the DS18B20 sensor, this function is based on the previous function. This function writes LSB (Least Significant Bit) first.
int1 ds18b20_read_bit(void): reads 1 bit from the DS18B20 sensor, returns the read value (1 or 0).
int8 ds18b20_read_byte(void): reads 1 byte (8 bits) from the DS18B20 sensor, this function is based on the previous function. This function reads LSB first.
int1 ds18b20_read(int16 *raw_temp_value): reads the temperature raw data which is 16-bit long (two 8-bit registers), the data is stored in the variable raw_temp_value, returns TRUE if OK and FALSE if error.

The value of the temperature in degree Celsius is equal to the raw value divided by 16 (in case of 12-bit resolution). The default resolution of the DS18B20 is 12 bits.

Rest of code is described through comments.

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

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.

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