How to Display Custom Character on LCD Arduino Easily
To display a custom character on an Arduino LCD, use the
createChar() function to define the character's pixel pattern, then use lcd.write() to show it. First, create a byte array for the character, load it into the LCD's memory, and finally print it by its index.Syntax
The main functions to display a custom character on an Arduino LCD are:
lcd.createChar(location, charmap): Defines a custom character at a memory location (0-7) using an 8-byte charmap array.lcd.write(location): Displays the custom character stored at the given location.
The charmap is an array of 8 bytes, each byte representing a row of 5 pixels (bits 0-4) on the LCD character cell.
arduino
byte smiley[8] = { 0b00000, 0b01010, 0b01010, 0b00000, 0b10001, 0b01110, 0b00000, 0b00000 }; lcd.createChar(0, smiley); lcd.setCursor(0, 0); lcd.write(byte(0));
Example
This example shows how to create a smiley face custom character and display it on the LCD at position (0,0).
arduino
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); byte smiley[8] = { 0b00000, 0b01010, 0b01010, 0b00000, 0b10001, 0b01110, 0b00000, 0b00000 }; void setup() { lcd.begin(16, 2); lcd.createChar(0, smiley); // Store custom char at location 0 lcd.setCursor(0, 0); lcd.write(byte(0)); // Display custom char lcd.print(" Hello!"); } void loop() { // Nothing here }
Output
A smiley face character appears at the top-left corner of the LCD followed by the text " Hello!"
Common Pitfalls
- Not using
byte()cast inlcd.write(): You must cast the location number tobyteto display the custom character correctly. - Defining more than 8 custom characters: The LCD only supports 8 custom characters (locations 0-7).
- Incorrect pixel pattern: Each byte must only use the lower 5 bits for pixels; higher bits are ignored.
- Not calling
lcd.createChar()beforelcd.write(): The character must be loaded into LCD memory first.
arduino
/* Wrong way: Missing byte cast */ lcd.write(0); // May print wrong character /* Right way: Use byte cast */ lcd.write(byte(0)); // Correct display
Quick Reference
| Function | Purpose | Notes |
|---|---|---|
| lcd.createChar(location, charmap) | Define custom character at location 0-7 | charmap is 8 bytes, each byte 5 pixels wide |
| lcd.write(byte(location)) | Display custom character stored at location | Must cast location to byte |
| lcd.setCursor(col, row) | Set cursor position on LCD | Before printing characters |
| lcd.print(text) | Print text on LCD | Can mix with custom chars |
Key Takeaways
Use lcd.createChar() with a byte array to define custom characters before displaying.
Only 8 custom characters (locations 0-7) can be stored at once on the LCD.
Always cast the location to byte in lcd.write() to show the custom character correctly.
Each custom character is an 8-row, 5-pixel wide pattern defined by bytes.
Set the cursor position before printing custom characters or text.