◇ Sensors · arithmetic
ADC counts to °C
Convert a 10-bit analogue reading from a TMP36 temperature sensor into degrees Celsius.
- Level 1 · Explorer
- 5 tests
- technically checked
Your task
A TMP36 sensor outputs 0.5 V at 0 °C and rises by 10 mV per °C. A microcontroller reads it with a 10-bit analogue-to-digital converter (ADC) using a 5 V reference, so it reports a whole number from 0 to 1023.
Write adcToCelsius(raw):
- volts = raw × 5 / 1023
- celsius = (volts − 0.5) × 100
Hints (0 of 2 shown)
What gets checked
- adcToCelsius(153) → ≈ 24.78 (± 0.01)
- adcToCelsius(102) → ≈ -0.147 (± 0.01)
Plus 3 hidden tests for edge cases. They run in the sandbox like the others; only the result is shown.
Tab indents · Esc then Tab leaves the editor · Ctrl/⌘ Enter runs · Ctrl/⌘ Shift Enter checks · Ctrl/⌘ / comments
Press Run to see what your program prints.
Your code runs only in this browser, inside an isolated sandbox with no network access, and stops after 3 s. Nothing you type is sent to Tactiverge; drafts and progress are saved in this browser only.