Software & Tools
Arduino IDE
Project description
Code
Interface a 16x2 Character LCD
arduino
1//Interface a 16x2 character LCD in 4-bit mode 2 3#include <LiquidCrystal.h> 4 5const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7; 6LiquidCrystal lcd(RS,EN,D4,D5,D6,D7); //set Uno pins that are connected to LCD, 4-bit mode 7//LiquidCrystal lcd(RS,EN,D1,D2,D3,D4,D5,D6,D7); //set Uno pins that are connected to LCD, 8-bit mode 8 9//create custom character, each character is 5x8 (WxH) pixels 10byte thumbsup0[8] = {B00100,B00011,B00100,B00011,B00100,B00011,B00010,B00001}; 11byte thumbsup1[8] = {B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00011}; 12byte thumbsup2[8] = {B00000,B00000,B00000,B00000,B00000,B00000,B00001,B11110}; 13byte thumbsup3[8] = {B00000,B01100,B10010,B10010,B10001,B01000,B11110,B00000}; 14byte thumbsup4[8] = {B00010,B00010,B00010,B00010,B00010,B01110,B10000,B00000}; 15byte thumbsup5[8] = {B00000,B00000,B00000,B00000,B00000,B10000,B01000,B00110}; 16 17void setup() { 18 lcd.begin(16,2); //set 16 columns and 2 rows of 16x2 LCD 19 //lcd.begin(20,4); //set 20 columns and 4 rows of 20x4 LCD 20 21} 22 23void loop() { 24 lcd.print("Hello World"); //print "Hello World" on first row 25 delay(3000); //delay 3 seconds 26 lcd.clear(); //clear display, sets cursor back to home 27 lcd.print("Fuel Your Creativity"); //notice how "Creativity" does not wrap around to next line 28 delay(3000); 29 lcd.clear(); 30 lcd.print("Fuel Your"); 31 lcd.setCursor(0,1); //set cursor to column 0, row 1 (rows and columns start from 0) 32 lcd.print("Creativity"); 33 delay(3000); 34 lcd.clear(); 35 lcd.cursor(); //show visible cursor below next char that will be printed 36 delay(3000); 37 lcd.noCursor(); //turns cursor off 38 delay(3000); 39 lcd.blink(); //similar to lcd.cursor but creates blinking block cursor 40 delay(3000); 41 lcd.noBlink(); //turn blinking cursor off 42 delay(3000); 43 lcd.print("Fuel Your Creativity"); 44 delay(3000); 45 lcd.scrollDisplayLeft(); //moves "Fuel Your Creativity" to the left by one character 46 delay(1000); 47 lcd.scrollDisplayLeft(); 48 delay(1000); 49 lcd.scrollDisplayLeft(); 50 delay(1000); 51 lcd.scrollDisplayLeft(); 52 delay(1000); 53 lcd.scrollDisplayRight(); //moves "Fuel Your Creativity" to the right by one character 54 delay(1000); 55 lcd.scrollDisplayRight(); 56 delay(1000); 57 lcd.scrollDisplayRight(); 58 delay(1000); 59 lcd.scrollDisplayRight(); 60 delay(3000); 61 lcd.clear(); 62 63 //display thumbsup character 64 lcd.createChar(0, thumbsup0); 65 lcd.createChar(1, thumbsup1); 66 lcd.createChar(2, thumbsup2); 67 lcd.createChar(3, thumbsup3); 68 lcd.createChar(4, thumbsup4); 69 lcd.createChar(5, thumbsup5); 70 lcd.setCursor(2,1); 71 lcd.write((uint8_t)0); 72 lcd.setCursor(2,0); 73 lcd.write(1); 74 lcd.setCursor(3,1); 75 lcd.write(2); 76 lcd.setCursor(3,0); 77 lcd.write(3); 78 lcd.setCursor(4,1); 79 lcd.write(4); 80 lcd.setCursor(4,0); 81 lcd.write(5); 82 delay(3000); 83 lcd.clear(); 84 85}
Downloadable files
Interfacing the LCD to the Arduino Uno
Interfacing the LCD to the Arduino Uno

Interfacing the LCD to the Arduino Uno
Interfacing the LCD to the Arduino Uno

Comments
Only logged in users can leave comments