In this article, we are going to interface the Nokia 5110 LCD with Arduino. You will learn the Nokia 5110 Arduino interfacing with the help of two examples. First, we will simply show some data on the screen and in the second example; we will read from the DHT22 temperature and humidity sensor and will show the readings on the Nokia 5110 LCD screen.
The Nokia 5110 LCD is a great choice when it comes to display data. It is cheaper and very easy to use with the micro-controllers. You just have to connect some wires and you are ready to go.
For Custom Projects, hire me at https://www.freelancer.com/u/Muhammadaqibdutt
Before going into the examples, first take a look at the pin out of the Nokia 5110 LCD.
PIN OUTThe pin out of the Nokia 5110 LCD is as follows
RST: Reset Pin
SCE: chip select Pin
D/C: (Data/Command): This is the mode select pin. Low means command mode and high means Data mode.
DN (Data Pin): Serial Data In
SCLK: Serial Clock
VCC: Input voltage is from 2.7 to 3.3V
LED: This LED is the backlight LED. Input voltage is 3.3V
GND: Ground
The required components for the Nokia 5110 Arduino are as follows
- Nokia 5110 LCD
- Arduino Uno
- DHT22 temperature and Humidity Sensor
- 1K potentiometer
- 4 X 10K resistors
- 1K resistor
- 330 ohm resistor
In the first example, we will simply print the data on the Nokia 5110 LCD. The circuit diagram for Nokia 5110 Arduino interfacing is shown below. The Nokia 5110 LCD requires 3.3V to operate, so we will have to use resistors to convert the 5V into 3.3V. If you will operate the Nokia 5110 Arduino without the resistors, then it will work but the life span of the LCD will decrease.
- Connect the pin 1 (RST Pin) to the pin 6 of Arduino through the 10K resistor.
- Connect the pin 2 (SCE Pin) to the pin 7 of Arduino through the 1K resistor.
- Connect the pin 3 (D/C Pin) to the pin 5 of Arduino through the 10K resistor.
- Connect the pin 4 (DIN Pin) to the pin 4 of Arduino through the 10K resistor.
- Connect the pin 5 (CLK Pin) to the pin 3 of Arduino through the 10K resistor.
- Connect the pin 6 (VCC Pin) to the 3.3V pin of Arduino.
- Connect the pin 7 (LED Pin) to the middle pin of 1k potentiometer through 330 ohm resistor and connect the other two pins to the VCC and the ground.
- Connect the pin 8 (GND Pin) to the GND of Arduino.
The potentiometer connected is used to increase or decrease the backlight of the LCD. You can connect it to 3.3V, if you want the backlight to always high or you can connect it to ground if you do not want backlight.
Download the Nokia 5110 library from the following link
#include <PCD8544.h>
PCD8544 lcd;
void setup() {
lcd.begin(84, 48);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print(" WELCOME ");
lcd.setCursor(0, 1);
lcd.print(" To");
lcd.setCursor(0,2);
lcd.print("ElectronicsHobbyists.com");
delay(200);
}
Code ExplanationFirst of all, we have included the library for the Nokia 5110 LCD. The library will include all the commands that we will require for the Nokia 5110 LCD. Then, we have declared a variable named ‘lcd’ of type PCD8544.
#include <PCD8544.h>
PCD8544 lcd;
Then in the setup function, we have set the resolution for the Nokia 5110 LCD. The Nokia5110 LCD has 84X48 resolutions, so we have set the 84X48 resolution in the Arduino IDE.
lcd.begin(84, 48);
Then in the loop function, first we have set the cursor at first line and printed the ‘Welcome there’. Then we moved to second line and printed ‘To’ there and then on the third line, we printed ‘ElectronicsHobbyists.com’.
lcd.setCursor(0, 0);
lcd.print(" WELCOME ");
lcd.setCursor(0, 1);
lcd.print(" To");
lcd.setCursor(0,2);
lcd.print("ElectronicsHobbyists.com");
delay(200);
Example 2In the second example, we will connect the DHT22 temperature and humidity sensor with the Arduino and will read the temperature, humidity and the heat index using the DHT22. Then we will show these on the Nokia 5110 LCD.
The circuit diagram for Nokia 5110 Arduino and DHT22 interfacing is as below
The connections of the Nokia 5110 LCD with Arduino are explained in the first example. Connect the pins of the DHT22 sensor with the Arduino as below
- Pin 1 of DHT22 to 5V of Arduino.
- Pin 2 of DHT22 to pin 8 of Arduino.
- Pin 4 of DHT22 to GND pin of Arduino.
If you want to read more about the DHT interfacing with Arduino, then read this tutorial |Temperature and Humidity Sensor DHT22 Arduino Interfacing
CodeDownload the Nokia 5110 LCD and DHT22 library from the following link
#include <PCD8544.h>
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT22
PCD8544 lcd;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
lcd.begin(84, 48);
dht.begin();
}
void loop() {
lcd.clear();
float hum = dht.readHumidity();
float temp = dht.readTemperature(); //Reading the temperature in degrees
float fah = dht.readTemperature(true); //Reading the temperature in fahrenheit
if (isnan(hum) || isnan(temp) || isnan(fah)) { //Checking if the arduino have recieved the values or not
lcd.println("Failed to read from DHT sensor!");
return;
}
float heat_index = dht.computeHeatIndex(fah, hum); //Reading the heat index in fahrenheit
float heat_indexC = dht.convertFtoC(heat_index); //Reading the heat index in degrees
lcd.setCursor(0, 0);
lcd.print("Humi: ");
lcd.print(hum);
lcd.print(" %\t");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" *C ");
lcd.setCursor(0,2);
lcd.print("Temp: ");
lcd.print(fah);
lcd.print(" *F\t");
lcd.setCursor(0,3);
lcd.print("Hi: ");
lcd.print(heat_indexC);
lcd.print(" *C ");
lcd.setCursor(0,4);
lcd.print("Hi: ");
lcd.print(heat_index);
lcd.println(" *F ");
delay(2000);
}
Code ExplanationFirst of all, we have included the libraries for the Nokia 5110 LCD and the DHT22 temperature and humidity sensor. After that, we have initialized pin 8 for the DHT22 (DHTPIN 8) and have define the type of DHT sensor. There are also other models of DHT sensors available but we have used the DHT22 because of its high accuracy. Then, we declared a variable ‘lcd’ of type PCD8544 for the LCD and a variable ‘dht’ of type DHT for the DHT22 sensor.
#include <PCD8544.h>
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT22
PCD8544 lcd;
DHT dht(DHTPIN, DHTTYPE);
Then in the setup function, we have set the resolution of the for the Nokia 5110 LCD. The Nokia5110 LCD has 84X48 resolutions, so we have set the 84X48 resolution in the Arduino IDE. After that, we started to receive data from the DHT22 sensor by using the ‘dht.begin()’ command.
lcd.begin(84, 48);
dht.begin();
In the loop function, we read the values of the humidity, temperature and heat index from the DHT22 and stored in the variables. In the end, we printed these on the Nokia 5110 LCD screen.
float hum = dht.readHumidity();
float temp = dht.readTemperature();
float fah = dht.readTemperature(true);
.
.
.
lcd.setCursor(0,4);
lcd.print("Hi: ");
lcd.print(heat_index);
lcd.println(" *F ");
VideoIf you have any questions, then feel free to ask us in the comment section.
Comments