Digital Thermometer with DS18B20 Sensor & Nokia LCD | mikroC Projects

This PIC project shows how to implement a simple temperature measurement station (digital thermometer) using PIC18F46K22 microcontroller and DS18B20 temperature sensor.
The PIC18F46K22 MCU reads temperature from the DS18B20 sensor and print its value (in °C) on Nokia 5110 monochrome LCD display (84×48 pixel resolution).
MikroC PRO for PIC compiler is used in this project.

To see how to interface PIC18F46K22 MCU with Nokia 5110 LCD using mikroC, visit this post:
Interfacing PIC MCU with Nokia 5110 LCD | mikroC Projects

About the DS18B20 sensor:
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 master device (microprocessor, microcontroller ….). Each DS18B20 device has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus and controlled with one master device.
The DS18B20 sensor provides 9-bit to 12-bit Celsius temperature measurement resolution (programmable resolution).
The DS18B20 sensor is available in 8-Pin SO (150 mils), 8-Pin μSOP, and 3-Pin TO-92 Packages. DS18B20 pin configurations is shown below:

ds18b20 pin configurations

Hardware Required:

  • PIC18F46K22 microcontroller   —->  datasheet
  • Nokia 5110 LCD module
  • DS18B20 temperature sensor    —->   datasheet
  • AMS1117 3V3 voltage regulator
  • 10 uF capacitor
  • 100 nF ceramic capacitor
  • 5 x 3.3k ohm resistor
  • 5 x 2.2k ohm resistor
  • 4.7k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

PIC18F46K22 with Nokia 5110 LCD and DS18B20 sensor circuit:
The image below shows project circuit diagram.

The DS18B20 temperature sensor has 3 pins (from left to right): GND, data and VCC where:
GND is connected to circuit ground (0V),
Data pin is connected to pin RB0 (#33) of the PIC18F46K22,
VCC is connected to +5V.

The 4.7k ohm resistor is required because the DS18B20 output is open drain.

PIC18F46K22 Nokia 5110 LCD DS18B20 sensor

All the grounded terminals are connected together.

The Nokia 5110 which is shown in the circuit diagram has 8 pins (from left to right): RST (reset), CE (chip enable), DC (or D/C: data/command), Din (data in), Clk (clock), VCC (3.3V), BL (back light) and Gnd (ground).

The Nokia 5110 LCD works with 3.3V only (power supply and control lines). The LCD module is supplied with 3.3V which comes from the AMS1117 3V3 voltage regulator, this regulator steps down the 5V into 3.3V (supplies the LCD controller PCD8544 with regulated 3V3).

All PIC18F46K22 microcontroller output pins are 5V, connecting a 5V pin directly to the Nokia 5110 LCD may damage its controller circuit!
To connect the PIC18F46K22 to the LCD module, I used voltage divider for each line. That means there are 5 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.

So, the Nokia 5110 LCD pins are connected to PIC18F46K22 MCU as follows (each one through voltage divider):
RST (reset) pin is connected to pin RD0 (#19)
CE (chip enable) pin is connected to pin RD1 (#20)
DC (data/command) pin is connected to pin RD2 (#21)
DIN (data in)  pin is connected to pin RD3 (#22)
CLK (clock) pin is connected to pin RD4 (#27)

VCC and BL are connected to AMS1117 3V3 regulator output pin and GND is connected to circuit ground (0V).

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

PIC18F46K22 with DS18B20 sensor and Nokia 5110 LCD 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 project C code, a driver for the Nokia 5110 LCD is required, download link is below. After you download the driver file which named NOKIA5110.C, add it to your project folder:
Nokia 5110 LCD library for mikroC compiler

The connection of the LCD pins with the microcontroller are defined in the C code as shown below:

Function used in the C code:
unsigned int ds18b20_read(): reads temperature from the DS18B20 sensor, returns the value of the temperature as unsigned 16-bit number.

The resolution of this thermometer is 0.0625°C.
Rest of code is described through comments.

Full mikroC code:

The following picture shows my protoboard circuit:

PIC18F46K22 MCU with DS18B20 sensor and Nokia 5110 LCD

Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

1 thought on “Digital Thermometer with DS18B20 Sensor & Nokia LCD | mikroC Projects”

  1. Cannot understand why dont supply all with 3.3v, 18f46k22 work from 2v to 5v ds18b20 also, from 3v to 5v and display work to 3.3v, you use a resistive divisor when is not needed if use AMS1117 regulator 3.3v 1100ma.

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