Challenge - 5 Problems
Temperature Sensor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this Arduino code reading LM35?
Given the following Arduino code snippet that reads an LM35 sensor connected to analog pin A0, what will be the printed temperature in Celsius if the analogRead returns 512?
Arduino
int sensorPin = A0; void setup() { Serial.begin(9600); } void loop() { int reading = analogRead(sensorPin); float voltage = reading * (5.0 / 1023.0); float temperatureC = voltage * 100.0; Serial.println(temperatureC); delay(1000); }
Attempts:
2 left
💡 Hint
Recall that LM35 outputs 10mV per degree Celsius and analogRead returns values from 0 to 1023 for 0-5V.
✗ Incorrect
The analog reading 512 corresponds to voltage ≈ 512 * (5.0 / 1023.0) ≈ 2.50 V. The code calculates temperatureC = voltage * 100.0 ≈ 250.0 °C, which is printed.
❓ Predict Output
intermediateWhat temperature does this TMP36 reading code print?
Consider this Arduino code reading a TMP36 sensor on analog pin A1. If analogRead returns 400, what temperature in Celsius will be printed?
Arduino
int sensorPin = A1; void setup() { Serial.begin(9600); } void loop() { int reading = analogRead(sensorPin); float voltage = reading * (5.0 / 1023.0); float temperatureC = (voltage - 0.5) * 100.0; Serial.println(temperatureC); delay(1000); }
Attempts:
2 left
💡 Hint
TMP36 outputs 0.5V at 0°C and 10mV per degree Celsius above that.
✗ Incorrect
For reading=400, voltage ≈ 400 * (5.0 / 1023.0) ≈ 1.955 V. temperatureC = (1.955 - 0.5) * 100.0 ≈ 145.5 °C, which is printed.
🔧 Debug
advancedWhy does this LM35 reading code print wrong temperature?
This Arduino code reads LM35 sensor but prints wrong temperature values. What is the main bug?
Arduino
int sensorPin = A0; void setup() { Serial.begin(9600); } void loop() { int reading = analogRead(sensorPin); float voltage = reading / 1023.0 * 5.0; float temperatureC = voltage * 10.0; Serial.println(temperatureC); delay(1000); }
Attempts:
2 left
💡 Hint
Check the LM35 sensor output voltage to temperature conversion factor.
✗ Incorrect
LM35 outputs 10mV per degree Celsius, so temperatureC = voltage * 100.0, not 10.0. Using 10.0 underestimates temperature by factor 10.
📝 Syntax
advancedWhich option fixes the syntax error in this TMP36 reading code?
Identify the option that corrects the syntax error in this Arduino code snippet:
Arduino
int sensorPin = A1 void setup() { Serial.begin(9600); } void loop() { int reading = analogRead(sensorPin); float voltage = reading * (5.0 / 1023.0); float temperatureC = (voltage - 0.5) * 100.0; Serial.println(temperatureC); delay(1000); }
Attempts:
2 left
💡 Hint
Check for missing semicolons in variable declarations.
✗ Incorrect
The line 'int sensorPin = A1' is missing a semicolon at the end, causing a syntax error.
🚀 Application
expertHow to convert TMP36 voltage to Fahrenheit in Arduino?
You read a TMP36 sensor voltage on analog pin A2. Which code snippet correctly converts the voltage to temperature in Fahrenheit?
Attempts:
2 left
💡 Hint
First convert voltage to Celsius, then convert Celsius to Fahrenheit using F = C * 9/5 + 32.
✗ Incorrect
Option A correctly calculates voltage, then Celsius temperature, then converts Celsius to Fahrenheit with the right formula.
