Bird
0
0
Arduinoprogramming~5 mins

Custom characters on LCD in Arduino

Choose your learning style9 modes available
Introduction

Sometimes the built-in characters on an LCD are not enough. Custom characters let you show your own shapes or symbols.

You want to display a smiley face or a heart on the LCD.
You need special icons like arrows or battery levels.
You want to create a small game or animation on the LCD.
You want to show letters or symbols not included in the LCD's default set.
Syntax
Arduino
byte customChar[8] = {
  B00000,
  B01010,
  B10101,
  B10001,
  B10101,
  B01010,
  B00000,
  B00000
};

lcd.createChar(location, customChar);
lcd.write(byte(location));

byte customChar[8] holds 8 rows of 5 pixels each (bits 0-4 used).

location is a number from 0 to 7 to store the custom character.

Examples
This creates a smiley face and shows it on the LCD at position 0.
Arduino
byte smiley[8] = {
  B00000,
  B01010,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
  B00000
};
lcd.createChar(0, smiley);
lcd.write(byte(0));
This creates a heart shape and displays it using location 1.
Arduino
byte heart[8] = {
  B00000,
  B01010,
  B11111,
  B11111,
  B11111,
  B01110,
  B00100,
  B00000
};
lcd.createChar(1, heart);
lcd.write(byte(1));
Sample Program

This program shows the word "Hello" followed by a smiley face on the LCD.

Arduino
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte smiley[8] = {
  B00000,
  B01010,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
  B00000
};

void setup() {
  lcd.begin(16, 2);
  lcd.createChar(0, smiley);
  lcd.print("Hello ");
  lcd.write(byte(0));
}

void loop() {
  // Nothing here
}
OutputSuccess
Important Notes

You can only store up to 8 custom characters at a time (locations 0-7).

Each character is 5 pixels wide and 8 pixels tall.

Use lcd.write(byte(location)) to display your custom character.

Summary

Custom characters let you add your own symbols to the LCD.

Define 8 rows of pixels using bytes with bits 0-4 for each row.

Store and show them using createChar and write.