Projects / Custom characters and games on a 16×2 LCD

Custom characters and games on a 16×2 LCD

Beginner1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNOHelloPCF8574

    Wire the LCD and buttons

    LCD on A4 and A5, buttons on D2 and D3.

  2. UNO

    Draw your characters

    On graph paper, five columns by eight rows. Shade squares and write each row as 0b followed by five digits.

  3. UNO

    Load them

    createChar stores each into a slot from 0 to 7.

  4. UNO

    Run the game

    The runner on the bottom row and cactus scroll in from the right.

  5. UNO

    Jump

    Press the jump button to lift the runner for three frames.

  6. UNO

    Restart

    After Game over, press the restart button.

  7. UNO

    Make it your own

    Add a coin character or a second obstacle.

In short

How do you build a custom characters and games on a 16×2 LCD?

Design your own 5 × 8 characters to make a side-scrolling runner game on a plain LCD. You need Arduino Uno R3, 16x2 LCD with I2C backpack (PCF8574), Tactile push button 6 mm × 2, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). It takes 7 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
LCD SDA and SCLUno A4 and A5I2C display
LCD VCC and GNDUno 5V and GNDSupply
Jump buttonUno D2 and GNDMake the runner jump
Restart buttonUno D3 and GNDStart a new game

Code

Arduino IDE, board "Arduino Uno". Install "LiquidCrystal I2C". The LCD can store eight custom characters, here the runner, cactus and a spare heart. Design your own on graph paper as a grid of five columns by eight rows, and write each row as a 5-bit binary number.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
byte runner[8] = {0b01110, 0b01110, 0b00100, 0b11111, 0b00100, 0b01010, 0b10001, 0b00000};
byte cactus[8] = {0b00100, 0b10101, 0b10101, 0b10101, 0b11111, 0b00100, 0b00100, 0b00100};
byte heart[8]  = {0b00000, 0b01010, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000, 0b00000};
const byte JUMP = 2, RESTART = 3;
char world[17];                               // obstacles in the bottom row
byte jumpFrames = 0;
unsigned long score = 0, lastFrame = 0;
int frameMs = 250;
bool dead = false;

void newGame() {
  for (byte i = 0; i < 16; i++) world[i] = ' ';
  world[16] = 0; score = 0; frameMs = 250; dead = false; jumpFrames = 0;
}

void setup() {
  pinMode(JUMP, INPUT_PULLUP); pinMode(RESTART, INPUT_PULLUP);
  lcd.init(); lcd.backlight();
  lcd.createChar(0, runner); lcd.createChar(1, cactus); lcd.createChar(2, heart);
  randomSeed(analogRead(A0));
  newGame();
}

void loop() {
  if (dead) {
    if (digitalRead(RESTART) == LOW) newGame();
    return;
  }
  if (digitalRead(JUMP) == LOW && jumpFrames == 0) jumpFrames = 3;     // stay up for three frames

  if (millis() - lastFrame > frameMs) {
    lastFrame = millis();
    for (byte i = 0; i < 15; i++) world[i] = world[i + 1];              // scroll the world left
    world[15] = (random(5) == 0 && world[14] != 1 && world[13] != 1) ? 1 : ' ';
    if (jumpFrames) jumpFrames--;
    score++;
    if (frameMs > 90 && score % 20 == 0) frameMs -= 10;                  // gets faster

    lcd.clear();
    lcd.setCursor(1, jumpFrames ? 0 : 1); lcd.write(byte(0));            // runner in column 1
    for (byte i = 0; i < 16; i++) if (world[i] == 1) { lcd.setCursor(i, 1); lcd.write(byte(1)); }
    lcd.setCursor(10, 0); lcd.print(score);
    if (world[1] == 1 && jumpFrames == 0) {                              // hit a cactus
      dead = true;
      lcd.setCursor(0, 0); lcd.print("Game over  ");
    }
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
RunCactus scroll left and the score rises
Press jump in timeRunner clears the cactus
Hit a cactusGame over
RestartNew game with the speed reset

If it does not work

Characters look wrong

Check each row has exactly five bits, and createChar is called after lcd.init.

Screen flickers

lcd.clear() redraws everything. Fine for this demo, but update only changed cells for a bigger game.

Jump feels late

Read the button faster or lower frameMs.

LCD blank

Check I2C address and contrast.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the custom characters and games on a 16×2 LCD?

Arduino Uno R3, 16x2 LCD with I2C backpack (PCF8574), Tactile push button 6 mm × 2, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data).

How long does the custom characters and games on a 16×2 LCD take to build?

About 60 minutes for a beginner maker, in 7 steps.

How do I know the custom characters and games on a 16×2 LCD works?

Run: Cactus scroll left and the score rises. Press jump in time: Runner clears the cactus. Hit a cactus: Game over.

Characters look wrong: what should I check?

Check each row has exactly five bits, and createChar is called after lcd.init.

Screen flickers: what should I check?

lcd.clear() redraws everything. Fine for this demo, but update only changed cells for a bigger game.

Jump feels late: what should I check?

Read the button faster or lower frameMs.

LCD blank: what should I check?

Check I2C address and contrast.