analogRead: numbers from 0 to 1023
Section 5: Sensors and numbersLesson 5.1 · ⏱ 8 min
The button gives only two answers: pressed or not. But the potentiometer and the light sensor give a number. The analogRead command on pin A0 gives a number from 0 to 1023.

🖥️ What happens on the stage?
In the Serial Monitor, numbers appear that change when you turn the potentiometer.
📌 Note
The Serial Monitor is a screen the Arduino writes on to tell you what is happening. Very useful for finding mistakes.
📌 Another example: the number controls the LED
If the knob's number is bigger than 512 (halfway), the blue LED lights up.



✍️ Practise
Read the potentiometer.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
Print the knob's number on the Serial every half second.
👀 Show the solution🙈 Hide the solution


Result: numbers appear that change with the knob.
Medium
The opposite: the LED lights when the number is smaller than 300.
👀 Show the solution🙈 Hide the solution


Result: it lights only at the start of the turn.
Hard
The knob changes the blinking speed: the wait = the knob's number.
👀 Show the solution🙈 Hide the solution


Result: small knob = fast blinking.

