Challenge - 5 Problems
Sensor Display Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output on the LCD screen?
Given the Arduino code below, what will be displayed on the LCD screen after running?
Arduino
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int sensorValue = 512; void setup() { lcd.begin(16, 2); lcd.print("Sensor:"); lcd.setCursor(0, 1); lcd.print(sensorValue); } void loop() { // no changes }
Attempts:
2 left
💡 Hint
Look at how the cursor is set before printing the sensor value.
✗ Incorrect
The lcd.print("Sensor:") writes on the first line. lcd.setCursor(0, 1) moves to the start of the second line, then lcd.print(sensorValue) prints 512 there.
🧠 Conceptual
intermediate1:00remaining
Why use lcd.setCursor() before printing sensor data?
In Arduino LCD programming, why do we use lcd.setCursor() before printing sensor data?
Attempts:
2 left
💡 Hint
Think about where the text appears on the LCD.
✗ Incorrect
lcd.setCursor(column, row) moves the cursor to a specific position so the next printed text appears there.
❓ Predict Output
advanced1:30remaining
What will the serial monitor show?
Consider this Arduino code snippet reading a sensor and printing to Serial Monitor. What is the output?
Arduino
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.print("Value: ");
Serial.println(sensorValue);
delay(1000);
}Attempts:
2 left
💡 Hint
analogRead reads values from 0 to 1023 depending on sensor input.
✗ Incorrect
analogRead(A0) returns a value between 0 and 1023 depending on the sensor voltage. The code prints this value every second.
🔧 Debug
advanced2:00remaining
Identify the error in this LCD display code
What error will this Arduino code cause when trying to display sensor data on LCD?
Arduino
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int sensorValue; void setup() { lcd.begin(16, 2); sensorValue = analogRead(A0); lcd.print("Value: "); lcd.print(sensorValue); } void loop() { // empty }
Attempts:
2 left
💡 Hint
Think about how lcd.print works when printing multiple things in a row.
✗ Incorrect
lcd.print("Value: ") prints text starting at cursor 0,0. Then lcd.print(sensorValue) continues printing immediately after. This can cause overlapping if not managed carefully.
🚀 Application
expert2:30remaining
How to display sensor data updating every 2 seconds on LCD?
Which code snippet correctly reads a sensor and updates the LCD display every 2 seconds, clearing old data before printing new?
Attempts:
2 left
💡 Hint
Clearing the screen before printing new data avoids leftover characters.
✗ Incorrect
Option A clears the LCD each loop, sets cursor positions explicitly, and prints the label and value properly, updating every 2 seconds.
