Hint: lcd.print(variable) shows its value, not the name [OK]
Common Mistakes:
Printing variable name instead of value
Confusing pin name with value
Missing lcd.clear() causing old data
4. Identify the error in this code snippet that tries to display sensor data:
int sensorValue = analogRead(A0);
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(sensorValue);
lcd.clear();
medium
A. lcd.clear() should be before lcd.print()
B. analogRead() needs a semicolon
C. lcd.setCursor() is missing parameters
D. sensorValue must be declared as float
Solution
Step 1: Check lcd.clear() placement
lcd.clear() clears the screen, so it must be called before printing new data to avoid erasing it immediately.
Step 2: Verify other code parts
analogRead() has semicolon, setCursor() has correct parameters, and sensorValue as int is fine for analog values.
Final Answer:
lcd.clear() should be before lcd.print() -> Option A
Quick Check:
Clear screen before printing = correct order [OK]
Hint: Always clear screen before printing new data [OK]
Common Mistakes:
Clearing screen after printing erases output
Misplacing lcd.setCursor() parameters
Wrong variable type assumptions
5. You want to display temperature in Celsius on an LCD using a sensor that outputs voltage. The sensor voltage is read by analogRead(A1) and converted by tempC = (sensorValue * 5.0 / 1023) * 100;. Which code snippet correctly displays the temperature with one decimal place?
hard
A. lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(int(tempC)); lcd.print(" C");
B. lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(tempC); lcd.print(" Celsius");
C. lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(tempC, 1); lcd.print(" C");
D. lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(tempC + " C");
Solution
Step 1: Understand temperature conversion
tempC is a float value representing temperature in Celsius with decimals.
Step 2: Display with one decimal place
lcd.print(value, 1) prints float with 1 decimal. Adding " C" after shows units clearly.
Step 3: Check other options
lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(tempC); lcd.print(" Celsius"); prints full float but no decimal control; lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(int(tempC)); lcd.print(" C"); truncates decimals; lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(tempC + " C"); tries to add string to float incorrectly.