Robotics · lesson 24 of 30 · free

Line-follower programs — Robotics for kids

A two-sensor line follower has one light sensor on each side of the line. Its program is a set of rules: if the left sensor sees black, the line has moved left, so turn left; else if the right sensor sees black, turn right; else (both white) the line is between the sensors, so go forward. The robot checks many times a second and wiggles gently along the line. When both sensors see black, the first true rule decides.

▶ Watch how it works

Got it? Practise ↓

Robot tip

Turn towards the line — “the sensor that sees black shows which way the line went”

  1. Left sees black → turn left; right sees black → turn right; both white → go forward.
  2. In an if / else if chain the first true rule wins (both black → the rule written first).
  3. With numbers: a reading below the threshold (for example below 40) means black.

Use it for: Programming a line follower robot, robotics competitions and if / else practice in coding.

Worked example: ⬛ A line follower runs: if (left sees black) { turn left } else if (right sees black) { turn right } else { go forward } The left sensor sees black and the right sensor sees white. What does it do? → turn left

  1. The first rule asks: does the left sensor see black? Yes.
  2. The first true rule decides, so it turns left.

Check: Both white would mean go forward ✓

▶ Watch it animated

✏️ Practice

Work it out in your head or on paper, type the answer and press Check. Stuck? Press “Show me how”.

Right: 0 · Tried: 0

🏁 Lesson 24 test

20 questions. Check each answer, then go to the next one. Get 16 or more right to pass.

🏅 Sign in with Google to earn the ⬛ Line Follower Pro badge when you pass — and a certificate when you finish all 10 lessons of Part 3 · Programming robots. You can still take the test without signing in.

🖨️ Robotics Worksheet: Line Follower Program

✨ Free AI tutor

Ask the AI tutor about this lesson

Why does it work? When should you use it? Ask in English, मराठी or हिंदी.

Sign in with Google to ask Free — 20 questions a day.

👩‍🏫 Robotics classes near you — online or at home

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India and visit homes in selected cities. Tell us what you need and our team will call you with timings and fees.

Live online classesSmall groups or 1:1 with a teacher, from home, any city.
Teacher at homeA TalentJR teacher visits your home (selected cities).
At a centreClasses at a TalentJR partner centre near you, where available.
Badges, certificates & gifts A badge for every lesson you pass, a certificate for every part you finish, plus TalentJR Points for daily practice. Electronics & IoT Circuits, sensors and microcontroller boards.