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

✓ Written and checked by the TalentJR team · Updated 13 Oct 2026 · How we make our lessons

✏️ Practice

Work it out in your head or on paper, then tap your answer — or type it 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 — live online, request a call back

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India. 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.
We call you backOur team asks what your child needs, then shares timings and fees.
Home tutor?We are still building our list of home tutors — ask on the call if there is one near you.
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.