DS18B20 Sensor Based Thermometer with Nokia 5110 LCD display
Hi guys welcome to this tutorial. Today we will be building a simple temperature monitor using the DS18B20 sensor with a Nokia 5110 LCD Display and an Arduino mega.
The DS18B20 digital temperature sensor gives a 9-bit to 12-bit Celsius temperature readings and also has an alarm function with nonvolatile user-programmable upper and lower trigger points. The sensor communicates via the 1-Wire communication protocol and thus by definition requires only one data line (and ground) for communication with a central microprocessor. Among the special features of this sensor, is an operational mode in which it can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply line.
Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to work on the same 1-Wire bus. Thus, it is simple to use one micro-controller to control many DS18B20s distributed over a large area. Some applications that can benefit from this capability include HVAC systems, temperature monitoring systems inside buildings, equipment, or machines, and process monitoring and control systems.
The Nokia 5110 was used to provide a feedback on the temperature values to the user but the Arduino serial monitor may also be used for those who do not have the display and the code for this is also included.
A more detailed tutorial on using the Nokia 5110 LCD display can be found here.
The following components with links attached to where they can be bought are needed for this project:
Connect all the components as shown in the schematics below.
For clarity, the pin connections are also described below.
DS18b20 - Arduino Mega VCC - 3.3v GND - GND SIG - D7 The other part of the schematic is only needed by those who have the Nokia 5110 display. Nokia 5110 - Arduino Display - Arduino Pin 1(RST) – D12 Pin 2(CE) – D11 Pin 3(DC) – D10 Pin 4(DIN) – D9 Pin 5(CLK) – D8 Pin 6(VCC) - VCC Pin 7(LIGHT) - GND Pin 8(GND) - GND
In order to use this sensor, we need to download three libraries;
- One-Wire Arduino Library
- Arduino Temperature control library
- Nokia 5110 LCD Library (This is only needed if you will be using the LCD)
The first library is the one-wire Arduino library. The one-wire Arduino Library allows one-wire enabled devices to communicate over the one-wire protocol with Arduino microcontrollers. On the 1-wire network which is also referred to as a “MicroLan” (trademark), a single “master” device communicates with one or more 1-Wire “slave” devices over a single data line, with an added perk of the same data line serving as power line for the sensor in a mode known as “parasitic” Mode. This means that we can connect multiple DS18B20 temperature sensor on the same Arduino pin (saving a whole lot of IOs).
The second library we will need is the Miles Burton Arduino temperature control library.
The Arduino temperature control library was created to make it easy to get temperature information from the Maxim Integrated temperature sensor.
Install these libraries with the Arduino by unzipping and copying to the location on your PC location where you have the Arduino libraries.
With this done, we are then ready to program our Arduino to read the temperature sensor.
We will be making two codes available for this project;
The first one (SerialTemperature.ino) displays the data over the Arduino serial monitor so that people who do not have the Nokia 5110 LCD display can also follow the tutorial by viewing the temperature data via the serial communication port.
The second code (TemperatureNokia5110.ino) is for those who have the Nokia 5110 lcd display.
Each of the codes will be explained differently to cover all the angles involved.
Let’s start with the first one.
The first thing we do is include the libraries we downloaded earlier.
Next we declare the pin to which our temperature sensor’s signal pin is connected, after which, the one wire method is called.
Next we need to declare the variables for holding the temperatures both in farenheit(TempF) and in degrees(TempC).
With this done, we then move to the setup function and startup the serial monitor with 9600 as the baud rate and also issue the command sensors.begin, which starts up communication with the temperature sensor via 1-wire.
Next we go into the void loop function. The void loop function contains three main lines. The first line reads the temperature from the temperature sensor. using the sensor.requestTemperatures() function. After this, the temperature in degrees Celsius is acquired using the second line. The index “0” is what needs to be changed to either 1 or 2 or N when you have multiple sensors on the 1-wire line.
With the temperature in Celsius gotten, the next line of code then obtains the temperature in Fahrenheit and its all then formatted to be nicely displayed by the printTemperature() function.
The remaining part of the code represents the print temperature function.
So for those without the Nokia 5110 LCD, here is the full code.
Copy, paste in the Arduino IDE and upload to your board. You should see outputs on your serial monitor like the image below.
All done, it is time to take a look at the code for those who have the Nokia 5110 LCD display.
Temperature with Nokia 5110 LCD Code
There are two sides to the code for this. The first one is the temperatureIcon.c file which is essentially the binary data representing the Icon that was used on the LCD.
The second file is the TemperatureNokia5110.ino file which contains the actual arduino code which I am about to explain.
Just like for the serial version of this code, we import the necessary libraries. In this case, we have to add the LCD library.
with this done, a 1-wire object is created and other variable declarations needed for both the screen and the sensor are handled.
With this done, we then proceed to the setup function where we, initialized the LCD, set its display font and then start communication with the sensor.
Setup all done? we then move to the Loop section. The first function in the loop section clears the LCD screen, after which the Icon is drawn using the draw bitmap function. After the bitmap is drawn, then the all familiar functions to read the temperature both in Celsius and Farenheit and display on the LCD.
The last part of the code is the function to convert readings to string.
The full code for this route is available below, and also available for download at the end of the tutorial page.
That’s it guys, you know the drill. Copy and paste in the Arduino IDE and upload to your board. You should see an output like what is in the Image below.
That’s it guys, thanks for sticking around for this one. If you have questions or comments, do drop them in the comment section and I will respond as soon as possible.
The youtube video for this tutorial can also be found here.
Till Next time.