KIPR · Botball Explorer
Activity Sections

Discovery · Coding Project 14

Seeing Light and Dark

A sensor that answers with a number, not a yes.

Project
Coding Project 14
Strand
Coding
Phase
Make It Smart
Time
One class period
What You Are Doing
Reading a that measures brightness, choosing your own decision point, and using the black line to place things exactly inside the Loading Zone.
Mission Anchor
Mission 14 bonus · Mission 18 bonus + advanced — 35 points
Before You Start
Projects 10, 11, and 13 — loops, , and if .
What You Need
Before you start: type your PIN in the box at the top of the page. Your teacher gave you this number. When you finish, press Submit & Download to turn in your work and save a copy.

Try It — How Dark Is It?

Your touch sensor answers one question: am I something? Yes or no. Nothing else.

This one is different. Plug the sensor — the little one, sometimes called a tophat — into an . Then open the Sensor List on the Wombat and watch the number while you hold it over things.

The reflectance (tophat) sensor.

⚠ Hold It About a Quarter Inch Up

Pointed straight down, roughly 1/4 inch off the surface. the surface or held way up both give you useless numbers.

Held over…Reading
The white part of the game field
A black line on the field
Your desk
Your hand
Something dark you find in the room
Something light you find in the room
Which gives the bigger number — dark surfaces or light ones?

The sensor shines a tiny light down and measures how much bounces back. Use that to explain why the numbers came out the way they did.

There Is No "Black" Reading

You did not get a yes or a no. You got a number somewhere in a big range, and it drifts a little every time you look.

So you have to decide where black starts. The sensor will not do it for you.

Learn It — Pick Your Own Dividing Line

Analog sensors --- reflectance, light, and the ET rangefinder.
An analog sensor reports a value across a wide range instead of just 0 or 1.

  • Values around 1000: white, lots of light bounced back.
  • Values around 3000: black, most light absorbed

Your numbers may not match anyone else’s. Different sensor, different mounting height, different room lighting.

Your threshold

A is the number you pick as the dividing line. Below it, call it white. Above it, call it black.

The usual starting point is halfway between your two readings:

Finding your threshold
threshold = (white + black) / 2

// For example: (800 + 3500) / 2 = 2150

That is a starting guess, not a final answer. You will adjust it.

Reading it in code

Code / partWhat it means
analog(1);Gives you the number from the analog sensor in port 1. Compare it against your threshold to decide what the robot is looking at.

Your third kind of loop condition

The loop has not changed at all. Only the it watches.

Switch

In project 10, you watched a switch with two possible values.

while (digital(bump) == 0)
{
	drive();
}

Count

In project 11, you watched a motor position counter that climbed steadily.

while (gmpc(left) < 4000)
{
	drive();
}

Now, watch a brightness

Now, you are watching a brightness number that jumps around.

while (analog(line) < threshold)
{
	drive();
}

Read the new one out loud: “While the sensor is seeing something lighter than my threshold, keep driving. The moment it sees something darker, stop.”

Starting on a light

The light sensor does one job, and it is the job every Botball robot needs: it waits for the lights to come on, then starts the match.

// Wait for light on port 3, then continue
wait_for_light(3);
  • You do not have to mount it on the robot.
  • It runs its own routine on screen — follow the steps it gives you.
  • Call it near the very top of your program.
  • Any moderately powerful flashlight should work with the light sensor, including a phone flashlight. Point the light at the sensor and watch the reading change.
  • More light means a lower reading, which is the opposite of what most people guess.

Do It — Find the Line, Then Use It

Step 1 — Mount it and set your threshold

Fix the reflectance sensor to the front underside of your robot, pointing straight down, about 1/4 inch clear of the mat. Then take fresh readings from the mounted position — they will not match what you got holding it in your hand.

MeasurementValue
Analog port I used
White reading, mounted
Black reading, mounted
My threshold — (white + black) / 2

Step 2 — Find the Line

Create a new project called Find the Line. Drive forward until the sensor sees black, then stop.

// 1. Print "Looking for the black line"
// 2. While the sensor reads less than my threshold, drive forward
// 3. Fall out of the loop when it reads more than the threshold
// 4. Stop everything

Use for your motors and your threshold — you have known better than bare numbers since Project 9.

TryThresholdWhat happened
1
2
3

Step 3 — Three lines, three distances

The real test of a threshold is whether it works when you did not tune it for that exact spot.

Set your robot at three different distances from a line and run the same program each time, changing nothing.

Starting distanceDid it stop on the line?

This Is Something Ticks Cannot Do

A count only works from a known starting point. This program finds the line from anywhere — it does not care where it began.

Step 4 — Drive to black, back up to black

Now do it twice in a row. Drive forward to a line, stop, then reverse until you find a line again.

⚠ Think Before You Write This One

When the robot stops, it is sitting on black. If you immediately start a loop that says “back up while you see white,” what does the sensor see on the very first check?

What did you have to do to get off the first line before looking for the next one?

Step 5 — Start on a light

Add wait_for_light() to the top of a program and follow the calibration routine on the Wombat’s screen.

Now your robot sits still until someone shines a light at it.

Why would every robot at a tournament need to start this way, rather than someone pressing a button on each one?

Step 6 — Mission 14 Bonus — A cone · 7 pts

Mission 14

Traffic Control

Watch Mission 14 video

Base Mission

3 points Live judged

Both Traffic Cones satisfy the definition.

Bonus Mission

7 points Final judged

A Traffic Cone is the Loading Zone. The Base Mission must be satisfied to score the Bonus Mission.

Scores

  • Both Traffic Cones are the black line.
  • A Traffic Cone is the Loading Zone while the other remains elsewhere on the field.
  • The same Traffic Cone used for Base Mission is placed the Loading Zone.

Does Not Score

  • Either Traffic Cone is touching black line.
  • Only one Traffic Cone is the black line.
  • A Traffic Cone is the Loading Zone but the second cone is still touching black line.
  • The Base Mission has not been satisfied.

⚠ The Base Still Has to Hold

You cannot score this bonus unless both cones are the black line — including the one you left behind. If your second cone drifted back onto the line, the bonus is worth nothing.

Use your line-finding program to drive to the Loading Zone , then place the cone.

Step 7 — Mission 18 — Botguy and both cones for 28 points

Watch Mission 18 video

Base Mission

11 points Final judged

Botguy is the Loading Zone.

Bonus Mission

13 points Final judged

Botguy is the Loading Zone AND at least one Traffic Cone is the Loading Zone.

Advanced Bonus

15 points Final judged

Botguy is the Loading Zone AND both Traffic Cones are the Loading Zone.

Scores

  • Botguy is the Loading Zone.
  • Botguy and one Traffic Cone are the Loading Zone.
  • Botguy and both Traffic Cones are the Loading Zone.

Does Not Score

  • Botguy is outside the Loading Zone.
  • Botguy is touching only the exterior boundary of the Loading Zone.
  • A Traffic Cone is the Loading Zone but Botguy is not.
  • Botguy and only one Traffic Cone are the Loading Zone for the Advanced Bonus.

and Are Not the Same Thing

Mission 14’s bonus only needs a cone the zone — any part of it poking into the interior counts.

Mission 18 needs the cones — every single part inside, nothing touching or crossing the boundary.

A cone half over the line scores Mission 14 and nothing from Mission 18. This is exactly why you need the sensor: it tells you where the boundary actually is.

One Delivery, Three Scores

Put Botguy and both cones fully inside the Loading Zone and you collect Mission 14’s bonus, Mission 18’s bonus, and Mission 18’s advanced — 35 points from one trip pattern.

Every part of this is final position, so nothing may drift out before the match ends.

Which order will you deliver them in, and why that order?

Step 8 — Run it five times

RunM14 bonusM18 bonusM18 advancedPoints
1
2
3
4
5
If a placement failed, was it the driving or the letting go?

Score It — Checkpoint

My score

Mission partScored?Points
Mission 14 — Bonus (a cone the Loading Zone)7
Mission 18 — Bonus (Botguy + one cone )13
Mission 18 — Advanced (Botguy + both cones )15
My total35

My sensor card

MeasurementValue
Reflectance sensor analog port
White reading
Black reading
Threshold I actually use
Light sensor port

or ?

Say whether each one satisfies , , both, or neither.

The cone is…Which definition?
Sitting well inside the zone, nothing near the edge
Mostly inside, with its base edge resting on the boundary line
Just its tip poking over the boundary into the zone
Right beside the zone, touching the outside of the line

Fix the threshold

The robot…Move the threshold which way?
Stops before it reaches the black line
Drives over the line and keeps going
Stops in a different place each run

Can you do it again?

Think about it

Your threshold works perfectly in your classroom. The tournament room has huge windows and much brighter light. What might happen, and what would you do about it on the day?

Your robot now has three ways to know where it is: bumping something, counting ticks, and reading brightness. Which one would you trust most, and does the answer change depending on the job?

Right now the sensor only tells your robot to stop. What if it kept reading while driving, and steered based on what it saw?

Next

That last question is the whole of the next project. In Project 15 — Following the Line, the sensor stops being a stop sign and becomes a steering wheel.

KIPR · Botball Explorer — Discovery Projects · © KISS Institute for Practical Robotics 1997–2026

When you are finished, press the button to turn in your work and save a copy.

KIPR · Botball Explorer · Discovery