Bird
0
0
Arduinoprogramming~20 mins

Displaying sensor data on screen in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sensor Display Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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
}
A
Sensor:
1023
BSensor: 512
C
Sensor:
512
DSensor: 1023
Attempts:
2 left
💡 Hint
Look at how the cursor is set before printing the sensor value.
🧠 Conceptual
intermediate
1:00remaining
Why use lcd.setCursor() before printing sensor data?
In Arduino LCD programming, why do we use lcd.setCursor() before printing sensor data?
ATo move the cursor to the desired position on the screen before printing
BTo clear the screen before printing new data
CTo change the font size of the printed text
DTo turn off the LCD backlight
Attempts:
2 left
💡 Hint
Think about where the text appears on the LCD.
Predict Output
advanced
1: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);
}
ANo output, code has error
BValue: 0 to 1023 (changing every second)
CValue: 1023 only
DValue: 0 only
Attempts:
2 left
💡 Hint
analogRead reads values from 0 to 1023 depending on sensor input.
🔧 Debug
advanced
2: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
}
AanalogRead(A0) cannot be called in setup() causing runtime error
Blcd.begin() is missing parameters causing compile error
Clcd.print() requires a delay after each call or it crashes
Dlcd.print(sensorValue) prints a number but cursor is not moved, so text overlaps
Attempts:
2 left
💡 Hint
Think about how lcd.print works when printing multiple things in a row.
🚀 Application
expert
2: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?
A
#include &lt;LiquidCrystal.h&gt;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
}
void loop() {
  int val = analogRead(A0);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Sensor:");
  lcd.setCursor(0, 1);
  lcd.print(val);
  delay(2000);
}
B
#include &lt;LiquidCrystal.h&gt;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
}
void loop() {
  int val = analogRead(A0);
  lcd.setCursor(0, 0);
  lcd.print("Sensor:");
  lcd.setCursor(0, 1);
  lcd.print(val);
  delay(2000);
}
C
#include &lt;LiquidCrystal.h&gt;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
  lcd.clear();
}
void loop() {
  int val = analogRead(A0);
  lcd.setCursor(0, 0);
  lcd.print("Sensor:");
  lcd.setCursor(0, 1);
  lcd.print(val);
  delay(2000);
}
D
#include &lt;LiquidCrystal.h&gt;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
}
void loop() {
  int val = analogRead(A0);
  lcd.clear();
  lcd.print("Sensor:");
  lcd.setCursor(0, 1);
  lcd.print(val);
  delay(2000);
}
Attempts:
2 left
💡 Hint
Clearing the screen before printing new data avoids leftover characters.