16x2 LCD Simulator for Arduino
Run LiquidCrystal or LiquidCrystal_I2C code and watch a 16x2, 20x4 or other HD44780 character display respond, custom characters and scrolling included. Or type the text row by row and get the sketch. Everything runs in your browser.
Type up to one row of text per box and press Generate sketch: the code below is replaced with a complete sketch, and a typed ° is turned into the LCD's own degree character.
The display redraws half a second after you stop typing. A missing lcd object is created for you, so a few loose lcd.print() lines work too.
Test LCD code before you wire anything
Nearly every 16x2 and 20x4 character LCD sold for Arduino is driven by the same chip, the Hitachi HD44780 or a clone of it. This simulator runs your LiquidCrystal or LiquidCrystal_I2C sketch against a model of that chip, so the screen behaves the way the real module does: text that runs off the edge disappears, rows on a 20x4 continue in the order the memory dictates, and custom characters live in the same eight slots.
How to use it
- Pick an example, paste your own sketch, or type into the row boxes and press Generate sketch.
- The size comes from your code:
LiquidCrystal_I2C lcd(0x27, 20, 4);orlcd.begin(16, 2);. Without either, the size selector is used. setup()runs once andloop()after it.delay()moves a virtual clock forward, so counters, scrolling text and progress bars play back at their real speed.- Warnings and errors appear under the display with a line number. Click the number to jump to that line.
How the HD44780 stores text
The controller keeps 80 characters of display memory (DDRAM), split into two lines of 40. The first line starts at address 0x00 and the second at 0x40. A 16x2 module shows the first 16 characters of each line; the other 24 are there but off screen, which is why text printed past column 15 vanishes instead of wrapping, and why scrollDisplayLeft() can bring it into view.
| Display | Row 0 | Row 1 | Row 2 | Row 3 |
|---|---|---|---|---|
| 16x2 | 0x00 | 0x40 | - | - |
| 20x4 | 0x00 | 0x40 | 0x14 | 0x54 |
| 16x4 | 0x00 | 0x40 | 0x10 | 0x50 |
On four-row displays, rows 2 and 3 are the continuation of rows 0 and 1. Print 30 characters on row 0 of a 20x4 and the last 10 appear on row 2. The 20x4 gotcha example shows exactly this. The fix is simple: start every row with lcd.setCursor(0, row).
Custom characters
The HD44780 has room for eight user-defined characters of 5x8 dots, codes 0 to 7. Each one is eight bytes, one per row, with the five low bits used. Define them with lcd.createChar(n, bytes) and print them with lcd.write(byte(n)). The LCD character generator lets you draw them with the mouse and copies the byte array.
One trap catches almost everyone: createChar() leaves the address pointer in character memory. Print right after it and the text overwrites your custom characters instead of reaching the screen. Call clear() or setCursor() first. The simulator copies the chip here too, and tells you when it happens.
Built-in symbols
Most modules ship with the A00 (Japanese) character ROM. Besides ASCII it holds katakana and a few symbols worth knowing: (char)223 is the degree sign, 126 a right arrow, 127 a left arrow, 228 µ, 244 Ω and 255 a filled block. Code 92 shows a yen sign instead of a backslash. Letters such as ü, é or ş are not in the ROM; draw them as custom characters. The simulator draws ASCII with a common 5x7 font, so a few glyphs may differ by a pixel from your module, and leaves katakana cells empty.
When the real display does not match
A row of solid blocks, nothing else. The display has power but was never initialised, or the contrast is too high. Check the wiring and the I2C address, then turn the blue potentiometer on the back.
Backlight on, no text. Usually the contrast potentiometer. On an I2C backpack, also make sure the sketch calls lcd.init() or lcd.begin() and lcd.backlight().
Two odd characters at the end of a line. println() sends a carriage return and a line feed, and the LCD prints both as characters. Use print() and setCursor().
The I2C LCD code generator builds a starting sketch with wiring notes, and the I2C 16x2 LCD guide explains the backpack step by step. Working with a graphic OLED instead? Try the OLED simulator.
Frequently Asked Questions
How do I simulate a 16x2 LCD online?
Paste your Arduino sketch into the editor, or type text into the row boxes and press Generate sketch. The simulator reads the LiquidCrystal or LiquidCrystal_I2C declaration, runs setup() and loop() and shows the display as it would look, including custom characters and delay() based animations. Nothing needs to be installed.
Why does text on my 20x4 LCD jump from row 1 to row 3?
The HD44780 controller has two memory lines of 40 characters. On a 20x4 display, row 2 is the second half of the first memory line and row 3 is the second half of the second one. When text runs past column 20 on row 0 it therefore continues on row 2, not row 1. Start every row with its own setCursor(0, row) call.
How do I print the degree symbol on an Arduino LCD?
Use lcd.print((char)223). The degree sign sits at code 223 (0xDF) in the A00 character ROM that almost every HD44780 module ships with. Typing ° inside a string does not work, because Arduino stores it as two UTF-8 bytes and the LCD shows two wrong symbols.
Why does my custom character show up as garbage?
createChar() moves the LCD's address pointer into character memory. If the next print() comes before setCursor(), clear() or home(), the text is written into the custom character slots instead of the screen. Call createChar() in setup() first, then clear() or setCursor(), then print. The simulator reproduces this behaviour and warns about it.
What is the I2C address of a 16x2 LCD?
Backpacks with the PCF8574T chip answer at 0x27 and those with the PCF8574AT at 0x3F, unless the A0 to A2 solder jumpers are changed. If neither works, run an I2C scanner sketch. The simulator does not check the address, so a sketch that works here but stays dark on the board usually has a wrong address or contrast set too low.
Is my code uploaded anywhere?
No. The code runs in your browser and never leaves it. It is autosaved in this browser's local storage, and the share link carries the code inside the link itself.