B
BrightMinds
12-day streak1,840 XPAsk a coach
M
● LIVE COACHED · WED 5:30 PMLESSON 04 OF 32~45 MIN+120 XP

Today you will teach your robot
to stay on the line.

By the end of this lesson, your bot will follow a curvy black line on its own using two IR sensors that see the difference between black and white.

🎯
EasyDifficulty 2 of 5
45 minBuild + code + test
🧰
6 partsAll in your starter kit
🎓
2 sensorsIR + analog read
Lesson progress3 of 5 steps done · 60%
📦 Parts on your desk

Grab these from your kit.

All shipped with your Pro plan
🧠
Arduino UNO
Main board
x1
👁
IR Sensor
TCRT5000
x2
⚙️
DC Motor + Wheel
6V geared
x2
🔋
9V Battery
+ clip cable
x1
🚗
Chassis
Acrylic, pre-drilled
x1
🔌
Jumper wires
M-F, assorted
x8
🧠 How it works

Two eyes. One simple rule.

Your robot has two IR sensors pointing down at the ground. Each one sends back a number.

LOW when it sees black on the line.
HIGH when it sees white on the floor.

If the left eye sees black, the line drifted left, so the bot turns left. If the right eye sees black, it turns right. If both see white, it drives straight.

💡
Mind blown moment: a self-driving car uses a similar idea with cameras instead of two simple eyes.
ARDUINO
IR-L · A0
IR-R · A1
MOTOR-L · D5
MOTOR-R · D6
🔧 Build it · 5 steps

Follow along, tick as you go.

1

Stick the sensors under the chassis.

5 minNo screws

Peel the double-sided tape from each IR sensor. Stick them under the front of the chassis, about 1 cm apart and 5 mm above the ground.

  • The two little LEDs on each sensor should face downward.
  • Don't worry about being perfect. You will fine-tune in Step 4.
2

Wire it up.

10 minBattery OFF

Use the jumper wires to connect the parts. Match the colors to the diagram above. Keep the battery unplugged while you wire.

  • Left IR sensor -> A0 on Arduino
  • Right IR sensor -> A1
  • Left motor -> D5 (PWM)
  • Right motor -> D6 (PWM)
  • Both sensors and motors share GND and 5V
3

Drop in the code.

8 minEditor below

Use the code editor below. Start with the Blocks view if you are newer, then peek at the Python version to see what the blocks become.

  • If you get a red error, check that the right COM port is selected.
  • Buddy AI can explain syntax errors in kid-friendly language.
4

Calibrate the sensors.

5 minOnce-only

Place the bot on a white surface and adjust each sensor until the readout is near 200. Then put it on the black line. The readout should jump toward 900.

  • Turn the screw clockwise to increase the reading.
  • Both sensors should hit similar numbers on the same color.
5

Race it.

10 minTest track included

Place your bot at the start of the test track. Plug in the battery, watch it follow the curves, then time it and try to beat 12 seconds.

  • Too jittery? Lower the motor speed in the code.
  • Losing the line? Move the sensors closer to the ground.
  • Going backwards? Swap the motor wires.
💻 Your code

One file. Two ways to read it.

line_follower.ino · saved 14s ago
line_follower.ino
// When the bot is switched on
⚡ when bot starts
set motor speed to 180
// Repeat forever
↻ forever
read left eye -> L
read right eye -> R
// Make the decision
if L > 500 and R < 500
turn left for 0.05 s
else if R > 500 and L < 500
turn right for 0.05 s
else
drive forward
Bot connected · COM3 · ready
🕹️ Simulator

No kit yet? Test it virtually first.

Auto-runs your code above

🏁 Test track · Snake

00:08.42
🤖
LEFT EYE (A0)342
RIGHT EYE (A1)918
DECISIONTURN RIGHT
Track: Snake
🧠 Checkpoint quiz

Make sure it stuck.

+30 XP if you get it first try
Your bot keeps spinning in circles forever. What is the most likely cause?
Tap an answer.
🎬 Show & tell

Film it. Submit it. Earn the badge.

Record a 15-second clip of your bot finishing the test track. Your coach can review the clip and unlock the next robotics challenge.

📹
Drop your video here
MP4 or MOV · up to 100 MB · 5-30 sec ideal