انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Maker: home
0. Lab tour1
1. The start: the Arduino6
2. Wiring and the traffic light4
3. Inputs: the button4
4. Sound and movement5
5. Sensors and numbers5
6. Distance, the screen and colours5
7. Motors and the car4
8. The project: the city's smart gate3
9. From blocks to C++ code5
10. Sensors and screens in code5
11. Smart systems5
12. Bluetooth: control from the phone1

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.

🧩 Print the reading
Blocks: loop — repeats forever
🖥️ 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.

🧩 The number controls the LED
Blocks: loop — repeats forever
The knob below halfway
The knob below halfway
The knob above halfway
The knob above halfway
✍️ Practise
Read the potentiometer.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Print the knob's number on the Serial every half second.

👀 Show the solution
🧩 Solution
Blocks: setup — runs once, loop — repeats forever
In the lab
In the lab

Result: numbers appear that change with the knob.

Medium

The opposite: the LED lights when the number is smaller than 300.

👀 Show the solution
🧩 Solution
Blocks: loop — repeats forever
In the lab
In the lab

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
🧩 Solution
Blocks: loop — repeats forever
In the lab
In the lab

Result: small knob = fast blinking.

Finished the lesson? Mark it so your progress counts.