Bird
0
0
Arduinoprogramming~20 mins

16x2 LCD with LiquidCrystal library in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LCD Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output on the LCD?

Consider this Arduino code using the LiquidCrystal library to display text on a 16x2 LCD. What will appear on the LCD screen after running this code?

Arduino
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Hello, World!");
  lcd.setCursor(0, 1);
  lcd.print("LCD Test");
}

void loop() {}
AFirst line: (empty)\nSecond line: Hello, World! LCD Test
BFirst line: LCD Test\nSecond line: Hello, World!
CFirst line: Hello, World! LCD Test\nSecond line: (empty)
DFirst line: Hello, World!\nSecond line: LCD Test
Attempts:
2 left
💡 Hint

Remember that lcd.setCursor(col, row) sets the position for the next print.

🧠 Conceptual
intermediate
1:30remaining
What does lcd.begin(16, 2) do?

In the LiquidCrystal library, what is the purpose of the lcd.begin(16, 2) command?

AIt initializes the LCD with 16 columns and 2 rows, setting up the display size.
BIt clears the LCD screen and turns off the backlight.
CIt sets the cursor to the first column and first row.
DIt loads a custom character set into the LCD memory.
Attempts:
2 left
💡 Hint

Think about what parameters begin() takes and what the LCD needs before printing.

🔧 Debug
advanced
2:30remaining
Why does this code not display anything?

Look at this Arduino code snippet. Why does the LCD remain blank after uploading?

Arduino
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.print("Hello");
  lcd.begin(16, 2);
}

void loop() {}
ABecause <code>lcd.begin()</code> must be called before any <code>lcd.print()</code> calls to initialize the display.
BBecause the <code>loop()</code> function is empty and must contain <code>lcd.display()</code>.
CBecause the pins are incorrectly assigned and need to be changed.
DBecause the LCD backlight is off and must be turned on manually.
Attempts:
2 left
💡 Hint

Think about the order of initialization and printing.

📝 Syntax
advanced
1:30remaining
Which code snippet correctly sets the cursor and prints on second line?

Which of the following code snippets correctly moves the cursor to the start of the second line and prints "Ready" on a 16x2 LCD?

A
lcd.setCursor(0, 2);
lcd.print("Ready");
B
lcd.setCursor(1, 0);
lcd.print("Ready");
C
lcd.setCursor(0, 1);
lcd.print("Ready");
D
lcd.setCursor(1, 1);
lcd.print("Ready");
Attempts:
2 left
💡 Hint

Remember that row numbering starts at 0.

🚀 Application
expert
3:00remaining
How many characters fit on a 16x2 LCD and what happens if you print more?

You have a 16x2 LCD connected and initialized with lcd.begin(16, 2). How many characters can you display at once? What happens if you print a string longer than that?

AYou can display 32 characters total. Printing more characters will overwrite the first line repeatedly.
BYou can display 32 characters total. Printing more characters continues printing off-screen and they are lost (not visible).
CYou can display 16 characters total. Printing more characters causes the LCD to reset.
DYou can display 32 characters total (16 per line). Printing more scrolls the text horizontally on the first line only.
Attempts:
2 left
💡 Hint

Think about how the LCD handles text longer than its display size.