Interfacing NOKIA5110 with arduino | AmazingMj

click here for video tutorial :-
https://youtu.be/5h2hL_w9mKc
Hello everyone, today i will so you how to interface graphical display Nokia 5110 with Arduino.The name “Nokia 5110” itself should have memories of the robust Nokia mobile phone which was very popular during the 90’s.

The nokia5110 display is compatible with Arduino by SPI communication
These LCD have black and white pixels of dimensions 84 × 48.
    Now we are making some projects with this display let’s interface this with ultrasonic sensor and print the distance on the display.

     For this the connections are pretty simple and straight forward to make. Once you are done with the connections your set-up would look like this. I don’t  want to connect this display every time  with  jumper wire so i make Arduino shield for that.
i connect the back light pin of the LCD to the Arduino so that we can control back light from code.

Lets move on to the coding part
First of all you need to install one library called nokia5110 _graph.h

code 1: for measuring distance
//SUBCRIBE TO AMAZING_MJ FOR VIDEO TUTORIAL
//Link : https://bit.ly/34BVDlI
//LCD module is connected to
//the following pins:
//      SCK  - Pin 8
//      MOSI - Pin 9
//      DC   - Pin 10
//      RST  - Pin 11
//      CS   - Pin 12

#include <LCD5110_Graph.h>

LCD5110 myGLCD(8, 9, 10, 11, 12);
int trigPin = 4;
int echoPin = 3;
long duration;
String cm;
int back_light = 2;
extern unsigned char SmallFont[];
extern unsigned char BigNumbers[];
extern unsigned char TinyFont[];
void setup()
{
  Serial.begin(9600);
  myGLCD.InitLCD();
  pinMode(back_light, OUTPUT);
  digitalWrite(back_light, 0); //on the backlight
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
void loop()
{
  // Measuring Distance
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  cm = (duration / 2) / 29.1;
  Serial.println(cm);

  Serial.println();
  //start for NOKIA5110 display
  myGLCD.setFont(SmallFont);
  myGLCD.print("Distance", CENTER, 3);
  myGLCD.update();
  int x = cm.toInt();
  myGLCD.setFont(BigNumbers);
  myGLCD.printNumI(x, 20, 15);
  myGLCD.update();
  if (cm.length() == 6) {
    myGLCD.setFont(SmallFont);
    myGLCD.print("CM", 65, 30);
    myGLCD.update();
    myGLCD.clrScr();
  }
  if (cm.length() == 5) {
    myGLCD.setFont(SmallFont);
    myGLCD.print("CM", 50, 30);
    myGLCD.update();
    myGLCD.clrScr();
  }
  if (cm.length() == 4) {
    myGLCD.setFont(SmallFont);
    myGLCD.print("CM", 35, 30);
    myGLCD.update();
    myGLCD.clrScr();
  }
  myGLCD.setFont(TinyFont);
  myGLCD.print("AMAZING MJ", CENTER, 42);
  delay(100);
}
// end of the code

code 2 : for dise

#include <LCD5110_Graph.h>
LCD5110 myGLCD(8, 9, 10, 11, 12);
int trigPin = 4;
int echoPin = 3;
long duration, cm;
int back_light = 2;
int x;
int y = 50;
extern unsigned char SmallFont[];
extern unsigned char BigNumbers[];
#include "number.h"
void setup()
{
  Serial.begin(9600);
  myGLCD.InitLCD();
  pinMode(back_light, OUTPUT);
  digitalWrite(back_light, 0);
  randomSeed(analogRead(A0));
}

void loop()
{
 
  while (1) {
    Run();
    myGLCD.clrScr();
    // Measuring Distance
    digitalWrite(trigPin, LOW);
    delayMicroseconds(5);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    cm = (duration / 2) / 29.1;
    Serial.println(cm);
    if (cm <= 10) {
      x = random(1, 7);
      Serial.println(x);
      switch (x) {
        case 1:
          one();
          break;
        case 2:
          two();
          break;
        case 3:
          three();
          break;
        case 4:
          four();
          break;
        case 5:
          five();
          break;
        case 6:
          six();
          break;
      }
      myGLCD.update();
      delay(2500);
    }
  }
}
//end of the code
here is the header file
 void one() {
  myGLCD.clrScr();
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 24, a);
  }
  myGLCD.setPixel(41, 23); myGLCD.setPixel(43, 23); myGLCD.setPixel(41, 25); myGLCD.setPixel(43, 25);
}
void two() {
  myGLCD.clrScr();
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 7, a);
  }
  myGLCD.setPixel(18, 6); myGLCD.setPixel(20, 6); myGLCD.setPixel(18, 8); myGLCD.setPixel(20, 8);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 40, a);
  }
  myGLCD.setPixel(64, 39); myGLCD.setPixel(66, 39); myGLCD.setPixel(64, 41); myGLCD.setPixel(66, 41);
}
void three() {
  myGLCD.clrScr();
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 24, a);
  }
  myGLCD.setPixel(41, 23); myGLCD.setPixel(43, 23); myGLCD.setPixel(41, 25); myGLCD.setPixel(43, 25);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 7, a);
  }
  myGLCD.setPixel(18, 6); myGLCD.setPixel(20, 6); myGLCD.setPixel(18, 8); myGLCD.setPixel(20, 8);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 40, a);
  }
  myGLCD.setPixel(64, 39); myGLCD.setPixel(66, 39); myGLCD.setPixel(64, 41); myGLCD.setPixel(66, 41);
}
void four() {
  myGLCD.clrScr();
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 7, a);
  }
  myGLCD.setPixel(18, 6); myGLCD.setPixel(20, 6); myGLCD.setPixel(18, 8); myGLCD.setPixel(20, 8);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 40, a);
  }
  myGLCD.setPixel(64, 39); myGLCD.setPixel(66, 39); myGLCD.setPixel(64, 41); myGLCD.setPixel(66, 41);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 7, a);
  }
  myGLCD.setPixel(64, 6); myGLCD.setPixel(66, 6); myGLCD.setPixel(64, 8); myGLCD.setPixel(66, 8);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 40, a);
  }
  myGLCD.setPixel(18, 39); myGLCD.setPixel(20, 39); myGLCD.setPixel(18, 41); myGLCD.setPixel(20, 41);
}
void five() {
  myGLCD.clrScr();
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 24, a);
  }
  myGLCD.setPixel(41, 23); myGLCD.setPixel(43, 23); myGLCD.setPixel(41, 25); myGLCD.setPixel(43, 25);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 7, a);
  }
  myGLCD.setPixel(18, 6); myGLCD.setPixel(20, 6); myGLCD.setPixel(18, 8); myGLCD.setPixel(20, 8);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 40, a);
  }
  myGLCD.setPixel(64, 39); myGLCD.setPixel(66, 39); myGLCD.setPixel(64, 41); myGLCD.setPixel(66, 41);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 7, a);
  }
  myGLCD.setPixel(64, 6); myGLCD.setPixel(66, 6); myGLCD.setPixel(64, 8); myGLCD.setPixel(66, 8);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 40, a);
  }
  myGLCD.setPixel(18, 39); myGLCD.setPixel(20, 39); myGLCD.setPixel(18, 41); myGLCD.setPixel(20, 41);
}
void six() {
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 7, a);
  }
  myGLCD.setPixel(18, 6); myGLCD.setPixel(20, 6); myGLCD.setPixel(18, 8); myGLCD.setPixel(20, 8);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 40, a);
  }
  myGLCD.setPixel(64, 39); myGLCD.setPixel(66, 39); myGLCD.setPixel(64, 41); myGLCD.setPixel(66, 41);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 7, a);
  }
  myGLCD.setPixel(64, 6); myGLCD.setPixel(66, 6); myGLCD.setPixel(64, 8); myGLCD.setPixel(66, 8);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 40, a);
  }
  myGLCD.setPixel(18, 39); myGLCD.setPixel(20, 39); myGLCD.setPixel(18, 41); myGLCD.setPixel(20, 41);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 7, a);
  }
  myGLCD.setPixel(41, 6); myGLCD.setPixel(43, 6); myGLCD.setPixel(41, 8); myGLCD.setPixel(43, 8);

  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 40, a);
  }
  myGLCD.setPixel(41, 39); myGLCD.setPixel(43, 39); myGLCD.setPixel(41, 41); myGLCD.setPixel(43, 41);
}

void Run() {
  delay(y);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 24, a);
  }
  myGLCD.setPixel(41, 23); myGLCD.setPixel(43, 23); myGLCD.setPixel(41, 25); myGLCD.setPixel(43, 25);

  myGLCD.update(); delay(y);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 40, a);
  }
  myGLCD.setPixel(64, 39); myGLCD.setPixel(66, 39); myGLCD.setPixel(64, 41); myGLCD.setPixel(66, 41);
  myGLCD.update(); delay(y);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(65, 7, a);
  }
  myGLCD.setPixel(64, 6); myGLCD.setPixel(66, 6); myGLCD.setPixel(64, 8); myGLCD.setPixel(66, 8);
  myGLCD.update(); delay(y);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 40, a);
  }
  myGLCD.setPixel(18, 39); myGLCD.setPixel(20, 39); myGLCD.setPixel(18, 41); myGLCD.setPixel(20, 41);
  myGLCD.update(); delay(y);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 7, a);
  }
  myGLCD.setPixel(41, 6); myGLCD.setPixel(43, 6); myGLCD.setPixel(41, 8); myGLCD.setPixel(43, 8);
  myGLCD.update(); delay(y);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(42, 40, a);
  }
  myGLCD.setPixel(41, 39); myGLCD.setPixel(43, 39); myGLCD.setPixel(41, 41); myGLCD.setPixel(43, 41);
  myGLCD.update(); delay(y);
  for (int a = 0; a < 5; a++) {
    myGLCD.drawCircle(19, 7, a);
  }
  myGLCD.setPixel(18, 6); myGLCD.setPixel(20, 6); myGLCD.setPixel(18, 8); myGLCD.setPixel(20, 8);
  myGLCD.update(); delay(y);
}
//end of the file

by-Mj

 note:-(till 550 subcribers)

If you wanna display your image in this display than

you need to follow this steps
1- first you need to subscribe my channel
2- follow amazing_mj_official on instagram and send me your image or whatever you want to display.
3-share your displayed image on your social media account
five lucky subcriber have chance to see their image in my next video.

Comments