Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
mdraber
Published © LGPL

How to use LCD 1602 display with Arduino

All methods for that LCD module explained with code examples

BeginnerFull instructions provided16,986
How to use LCD 1602 display with Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Connectivity

Code

Code example : lcd print, lcd.setCursor,

Arduino
#include <LiquidCrystal.h>

const int rs = 2, 
          en = 3, 
          d4 = 6, 
          d5 = 7, 
          d6 = 8, 
          d7 = 9;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
    lcd.setCursor(0, 0);
  lcd.print("Hello world");
}

Code example: lcd. autoscroll, lcd.noautoscroll

Arduino
#include <LiquidCrystal.h>

const int rs = 2, 
          en = 3, 
          d4 = 6, 
          d5 = 7, 
          d6 = 8, 
          d7 = 9;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
}

String Mario="Mario's Ideas                   ";

void loop() {
  lcd.clear() ; //d
  delay(3000);//d
   
   for(int i=0;i<Mario.length();i++){
    lcd.print(Mario.charAt(i));
    delay(200);
  } 
  lcd.setCursor(16, 1);
  lcd.autoscroll();
  for(int i=0;i<Mario.length();i++){
    lcd.print(Mario.charAt(i));
    delay(400);  
  }
  lcd.noAutoscroll(); 
  lcd.clear();
} 

Code example: lcd.scroll

Arduino
#include <LiquidCrystal.h>

const int rs = 2, 
          en = 3, 
          d4 = 6, 
          d5 = 7, 
          d6 = 8, 
          d7 = 9;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);



void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
  lcd.clear();
  delay(2000);
  lcd.print("PATREON");
}

void loop() {
  delay(4000);
  for (int pos = 0; pos < 23; pos++) {
     lcd.scrollDisplayRight();
     delay(250);
  }
  for (int pos = 0; pos < 23; pos++) {
     lcd.scrollDisplayLeft();
     delay(250);
  }
  
}

Code example: lcd.blink, lcd.noblink, lcd.clear

Arduino
#include <LiquidCrystal.h>

const int rs = 2, 
          en = 3, 
          d4 = 6, 
          d5 = 7, 
          d6 = 8, 
          d7 = 9;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
}


String Hello="Hello World!";

void loop() {
  lcd.clear(); //d
  delay(4000);//
  lcd.blink();
  lcd.setCursor(0, 0);
  delay(6000); //2000

  for(int i=0;i<Hello.length();i++){
    lcd.print(Hello.charAt(i));
    delay(400);
  }  
  delay(6000);//2000 
  lcd.noBlink();
  delay(3000);
  lcd.clear();
}

Code example: lcd.createChar - creating single custom character

Arduino
#include <LiquidCrystal.h>

const int rs = 2, 
          en = 3, 
          d4 = 6, 
          d5 = 7, 
          d6 = 8, 
          d7 = 9;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

byte bot[8] = {
  0b01110,
  0b01110,
  0b00100,
  0b11111,
  0b00100,
  0b00100,
  0b01010,
  0b10001
};


void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
 
  lcd.createChar(0,bot);
  lcd.clear();
  delay(2000);
 

}



void loop() {
  lcd.setCursor(0, 0);
  lcd.write(byte(0)); 
  delay(6000);
  for (int j=0;j<2;j++)
   for (int i=0;i<16;i++){
       lcd.setCursor(i, j);
       lcd.write(byte(0)); 
       delay(100);
   }

  }

Code example: lcd.createChar - creating composite clipart out of multiple custom characters

Arduino
#include <LiquidCrystal.h>

const int rs = 2, 
          en = 3, 
          d4 = 6, 
          d5 = 7, 
          d6 = 8, 
          d7 = 9;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

byte S1[8] = {
  0b00000,
  0b00000,
  0b00011,
  0b00100,
  0b01000,
  0b01000,
  0b10000,
  0b10000
};  

byte S2[8] = {
  0b00000,
  0b11111,
  0b00000,
  0b00000,
  0b00000,
  0b11011,
  0b11011,
  0b11011
};  

byte S3[8] = {
  0b00000,
  0b00000,
  0b11000,
  0b00100,
  0b00010,
  0b00010,
  0b00001,
  0b00001
}; 


byte S4[8] = {
  0b10000,
  0b10010,
  0b01001,
  0b01000,
  0b00100,
  0b00011,
  0b00000
};


byte S5[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b00000,
  0b00000,
  0b11111
};


byte S6[8] = {
0b00001,
0b01001,
0b10010,
0b00010,
0b00100,
0b11000,
0b00000
};

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
  lcd.begin(16, 2);

  // create a new character
  lcd.createChar(0,S1);
  // create a new character
  lcd.createChar(1,S2);
  // create a new character
  lcd.createChar(2,S3);
    // create a new character
  lcd.createChar(3,S4);
  // create a new character
  lcd.createChar(4,S5);
  // create a new character
  lcd.createChar(5,S6);
 lcd.clear();
 delay(3000);
}



void loop() {

// set the cursor to the top left
  lcd.setCursor(0, 0);
  lcd.write(byte(0)); 
  lcd.write((byte)1); 
  lcd.write((byte)2); 
  lcd.setCursor(0, 1);
  lcd.write((byte)3); 
  lcd.write((byte)4); 
  lcd.write((byte)5);

  }

Code example: lcd.lefttoRight, lcd.righttoLeft, lcd.home, lcd.display, lcd.nodisplay

Arduino
#include <LiquidCrystal.h>

const int rs = 2, 
          en = 3, 
          d4 = 6, 
          d5 = 7, 
          d6 = 8, 
          d7 = 9;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
}


String Hello="Hello World!";

void loop() {
  lcd.clear(); delay(4000);
  lcd.setCursor(7, 0);
  lcd.rightToLeft();
  lcd.print("TFEL-<"); 
  
  delay(4000);

  lcd.setCursor(7, 1);
  lcd.leftToRight();
  lcd.print("RIGHT->"); 
  
  delay(2000);
  
  lcd.blink();delay(4000);
  lcd.home();delay(4000);

  lcd.noDisplay(); delay(4000);
  lcd.display(); delay(4000);
  lcd.clear(); delay(4000);

}

Credits

mdraber
49 projects • 69 followers

Comments