Arduino Code for a Nokia 5110 LCD Screen
In this tutorial, we will explore how to use the Nokia 5110 LCD screen with an Arduino to display various graphics and text. The project will demonstrate how to draw lines, circles, rectangles, and even display text inside those shapes. By the end, you'll have a better understanding of how to interact with this LCD using Arduino code.

To provide clearer guidance, I encourage you to watch the associated video for a visual representation of the wiring and code implementation (in video at 00:00).
Hardware Explained
The Nokia 5110 LCD is a compact graphical display that operates on the SPI protocol, enabling efficient communication with the Arduino. It features a resolution of 84x48 pixels, which is sufficient for displaying basic graphics and text. The display requires only a few pins to operate, making it a great choice for projects with limited I/O options.
In addition to the LCD, you will need an Arduino board, typically an Arduino Uno or similar, a breadboard, and some jumper wires. The wiring is straightforward, and the LCD is powered by connecting its VCC pin to the Arduino's 5V output.
Datasheet Details
| Manufacturer | Philips |
|---|---|
| Part number | PCD8544 |
| Logic/IO voltage | 3.3 V |
| Supply voltage | 3.3 – 5.0 V |
| Max current | 200 µA |
| Screen resolution | 84 x 48 pixels |
| Interface | Serial (SPI) |
| Package | Module |
- Use a current-limiting resistor for the LED pin to prevent damage.
- Ensure connections to VCC and GND are secure to avoid display issues.
- Double-check SPI pin connections: SCE, RST, D/C, DN, and SCLK.
- Keep the contrast setting within the recommended range (40-60).
- Update the display after drawing graphics to see changes.
Wiring Instructions

To wire the Nokia 5110 LCD to your Arduino, follow these connections:
- Connect the LCD's
VCCpin to the Arduino's5Vpin. - Connect the
GNDpin on the LCD to one of the Arduino'sGNDpins. - Connect the
SCEpin on the LCD to pin7on the Arduino. - Connect the
RSTpin to pin6. - Connect the
D/Cpin to pin5. - Connect the
DN (MOSI)pin to pin11. - Connect the
SCLKpin to pin13. - Finally, connect the
LEDpin to pin9through a 330-ohm resistor.
These connections will allow the Arduino to communicate with the LCD effectively. If you need to adjust the wiring for your specific setup, ensure that the SPI pins remain consistent.
Code Examples & Walkthrough
The following code snippet initializes the LCD and sets the contrast:
void setup() {
Serial.begin(9600);
lcdBegin(); // Initialize the LCD
setContrast(40); // Set contrast level
delay(2000);
clearDisplay(BLACK); // Clear the display
updateDisplay(); // Update the display
}
In this snippet, the lcdBegin() function sets up the necessary pins for the LCD, while setContrast(40) adjusts the display's contrast. After a brief delay, the display is cleared to prepare for new content.

Next, we can draw a line on the display:
setLine(1, 4, 70, 4, BLACK); // Draw a horizontal line
updateDisplay(); // Make the line visible
This line of code uses the setLine() function, which takes the starting and ending coordinates along with a color parameter. After drawing, it's essential to call updateDisplay() to reflect the changes on the screen.
Finally, we can display text within a rectangle:
setRect(10, 10, 70, 40, 1, BLACK); // Draw a filled rectangle
setStr("Robojax ", 15, 20, WHITE); // Display text inside
updateDisplay(); // Update to show the changes
Here, setRect() creates a rectangle, while setStr() places text inside it. The color parameters define how the rectangle and text appear on the screen.
Demonstration / What to Expect
Upon running the code, you should see a series of graphics displayed on the Nokia 5110 LCD, including lines, circles, rectangles, and text. Ensure your wiring is correct to avoid issues like reversed polarity or floating inputs, which could prevent the display from functioning (in video at 02:30).
Video Timestamps
- 00:00 - Introduction to the project
- 01:30 - Wiring instructions
- 03:00 - Code setup and explanation
- 05:00 - Displaying graphics and text
- 07:30 - Conclusion and further modifications
/*
* This is Arduino code to use a dual-axis XY joystick with a Nokia 5110 LCD.
* It also reads a switch.
* Other Arduino libraries and videos: https://robojax.com
* Watch the video for this code to learn it fully.
* Watch the video here: https://youtu.be/Pk5Wig5EO0s
*
* Get this code and other Arduino codes from Robojax.com.
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. Purchase my course on Udemy.com: http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon: http://robojax.com/L/?id=63
or make a donation using PayPal: http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact. *
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Nokia 5110 LCD Example Code
Graphics driver and PCD8544 interface code for SparkFun's
84x48 Graphic LCD.
https://www.sparkfun.com/products/10168
Original source code:
https://github.com/sparkfun/GraphicLCD_Nokia_5110
This stuff could all be put into a library, but we wanted to
leave it all in one sketch to keep it as transparent as possible.
Hardware: (Note: most of these pins can be swapped)
Graphic LCD Pin ---------- Arduino Pin
1-VCC ---------------- 5V
2-GND ---------------- GND
3-SCE ---------------- 7
4-RST ---------------- 6
5-D/C ---------------- 5
6-DN(MOSI) ---------------- 11
7-SCLK ---------------- 13
8-LED - 330 Ohm res -- 9
The SCLK, DN(MOSI), must remain where they are, but the other
pins can be swapped. The LED pin should remain a PWM-capable
pin. Don't forget to stick a current-limiting resistor in line
between the LCD's LED pin and Arduino pin 9!
Modified by Ahmad S. for Robojax.com
on Mar 11, 2018 at 20:49 in Ajax, Ontario, Canada
*/
#include <SPI.h>
#include "robojax-nokia5110.h"
void setup()
{
Serial.begin(9600);
lcdBegin(); // This will setup our pins, and initialize the LCD
//updateDisplay(); // with displayMap untouched, SFE logo
setContrast(40); // Good values range from 40-60
delay(2000);
clearDisplay(BLACK);
updateDisplay();
}
void loop()
{
// setPixel takes 2 to 3 parameters. The first two parameters
// are x and y variables. The third optional parameter is
// a "color" boolean. 1 for black, 0 for white.
// setPixel() with two variables will set the pixel with
// the color set to black.
// clearPixel() will call setPixel with the color set to
// white.
// setPixel(random(0, LCD_WIDTH), random(0, LCD_HEIGHT));
// After drawing something, we must call updateDisplay()
// to actually make the display draw something new.
//invertDisplay(); // This will swap all bits in our display
// setLine(x0, y0, x1, y1, bw) takes five parameters. The
// first four are coordinates for the start and end of the
// line. The last parameter is the color (1=black, 0=white).
setLine(1, 4, 70, 4, BLACK);
updateDisplay();
delay(2000);
//analogWrite(blPin, i); // blPin is connected to BL LED
/* setRect Example */
clearDisplay(WHITE); // Start fresh
// setCircle takes 5 parameters -- x0, y0, radius, bw, and
// lineThickness. x0 and y0 are the center coordinates of the circle.
// radius is the...radius. bw is the color (0=white, 1=black)
// lineThickness is the line width of the circle, 1 = smallest
// thickness moves in towards the center.
setCircle(20, 30, 20, BLACK, 2);
updateDisplay();
delay(2000);
clearDisplay(WHITE);
setStr("Welcome to ", 0, 0, BLACK);
updateDisplay();
delay(100);
setLine(0, 9, 70, 9, BLACK);
updateDisplay();
delay(100);
setStr("Robojax ", 20, 20, BLACK);
updateDisplay();
delay(2000);
clearDisplay(WHITE);
// setRect takes six parameters (x0, y0, x1, y0, fill, bw)
// x0, y0, x1, and y0 are the two diagonal corner coordinates
// fill is a boolean, which determines if the rectangle is
// filled in. bw determines the color 0=white, 1=black.
setRect(10, 10, 70, 40, 1, BLACK);
setStr("Robojax ", 15, 20, WHITE);
updateDisplay();
delay(2000);
/* setCircle Example */
clearDisplay(WHITE);
}
|||您可能需要的东西
-
亚马逊从亚马逊购买XY摇杆amzn.to
-
亚马逊从亚马逊购买诺基亚5110 LCDamzn.to
资源与参考
尚无可用资源。
文件📁
Fritzing 文件
-
Nokia 5110 LCD
Nokia_5110_LCD.fzpz0.03 MB -
Black Joystick KY-023
Black Joystick KY-023.fzpz0.02 MB