Interface PIC MCU with DS18B20 sensor and SSD1306 | mikroC Projects

This project shows how to connect PIC16F887 microcontroller with SSD1306 OLED display (128×64 pixel) and DS18B20 digital 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 DS18B20 sensor is a 3-pin electronic component (like a simple transistor) from Maxim (formerly Dallas) which uses 1-wire protocol to communicate with the master device (microprocessor, microcontroller ….).
The compiler used in this project is mikroElektronika mikroC PRO for PIC.

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 and I2C mode) such as soldering, placing jumpers …

Related Projects:
Interfacing PIC microcontroller with SSD1306 OLED | mikroC Projects
Interfacing DS18B20 sensor with PIC microcontroller | mikroC Projects

Hardware Required:

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

Interfacing PIC16F887 MCU with DS18B20 sensor and SSD1306 OLED circuit:
The following image shows project circuit diagram.

PIC16F887 with DS18B20 sensor and SSD1306 OLED - DS18B20 SSD1306

(All grounded terminals are connected together)

The PIC16F887 microcontroller has one hardware I2C module (MSSP 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 (default address).

The DS18B20 sensor has 3 pins (from left to right): GND, data and VCC (+5V). The data pin is connected to PIC16F887 pin RD5.

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

The 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 the C code below with no error, a driver (& library) for the SSD1306 OLED display is required, it’s full name is SSD1306.C, download link is below:
SSD1306 OLED display driver for mikroC compiler

after the download, add the driver file (SSD1306.C) to project folder.

MikroC PRO for PIC compiler has a built-in one-wire protocol library which makes the interfacing more easier.

The default resolution of DS18B20 is 12-bit which means the step of the temperature is 0.0625°C. The datasheet of the device contains more details about that. Rest of code is described through comments.

Full mikroC code:
Configuration words:
CONFIG1 = 0x2CD4
CONFIG2 = 0x0700

The simulation of this project using Proteus should be similar to what’s shown in the following video where PIC16F877A microcontroller is used:

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