How to Scroll Text on LCD with Arduino: Simple Guide
To scroll text on an LCD with Arduino, use the
lcd.scrollDisplayLeft() or lcd.scrollDisplayRight() functions from the LiquidCrystal library. First, print the text on the LCD, then call these functions repeatedly with a delay to create a scrolling effect.Syntax
The main functions to scroll text on an LCD using Arduino are:
lcd.scrollDisplayLeft();- Scrolls the display one position to the left.lcd.scrollDisplayRight();- Scrolls the display one position to the right.
These functions move the visible text on the LCD without changing the original string printed. Use them inside a loop with a delay to create smooth scrolling.
arduino
lcd.scrollDisplayLeft(); lcd.scrollDisplayRight();
Example
This example shows how to scroll a long message from right to left on a 16x2 LCD using the LiquidCrystal library.
arduino
#include <LiquidCrystal.h> // Initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { lcd.begin(16, 2); // Set up the LCD's number of columns and rows lcd.print("Scrolling Text Demo"); delay(2000); // Show initial message for 2 seconds lcd.clear(); lcd.print("Hello Arduino LCD! This text scrolls."); } void loop() { lcd.scrollDisplayLeft(); // Scroll text left delay(300); // Wait 300 milliseconds }
Output
The LCD shows 'Hello Arduino LCD! This text scrolls.' scrolling smoothly from right to left across the screen.
Common Pitfalls
Common mistakes when scrolling text on an Arduino LCD include:
- Not clearing the LCD before printing new text, causing overlapping characters.
- Using too short or too long delays, making scrolling too fast or too slow.
- Trying to scroll text that fits entirely on the screen, which has no visible effect.
- Not initializing the LCD size correctly with
lcd.begin(columns, rows);.
Always print the full message first, then scroll it. Avoid calling lcd.clear() inside the scrolling loop as it resets the display.
arduino
/* Wrong way: clearing inside loop */ void loop() { lcd.clear(); lcd.print("Scrolling text"); lcd.scrollDisplayLeft(); delay(300); } /* Right way: print once, then scroll */ void setup() { lcd.begin(16, 2); lcd.print("Scrolling text"); } void loop() { lcd.scrollDisplayLeft(); delay(300); }
Quick Reference
Tips for smooth scrolling on Arduino LCD:
- Use
lcd.scrollDisplayLeft()orlcd.scrollDisplayRight()to move text. - Print the full message once before scrolling.
- Use a delay between scroll steps (100-500 ms works well).
- Do not clear the display inside the scroll loop.
- Ensure your message is longer than the LCD width to see scrolling effect.
Key Takeaways
Use lcd.scrollDisplayLeft() or lcd.scrollDisplayRight() to scroll text on Arduino LCD.
Print the full message once before starting the scroll loop.
Add a delay between scroll steps for smooth movement.
Do not clear the LCD inside the scrolling loop to avoid flicker.
Make sure your text is longer than the LCD width to see scrolling.