Week 4
Helping Robots Sense
Read real sensor values, find thresholds, and calibrate a robot to trust what it senses.
- 70-85 minutes
- Mission: Read a sensor across changing conditions, find a threshold, and calibrate it so the readings are reliable in this room.
Now that the robot moves and follows instructions, students give it senses. They meet touch, distance, light, and color sensors and learn that a sensor reading is a number the robot can measure. They discover that a threshold is a cutoff that turns numbers into 'near or far' and 'light or dark', that every sensor has detection limits, and that readings wobble a little (noise), so you take several and calibrate them for this room and this robot. After reading and calibrating, they program one sensor-based stop - the robot drives and uses its distance sensor to halt right before a wall - so a threshold finally controls a real action. Fuller automatic behavior with loops and conditions across a whole mission comes next week.
By the end of this week you can
- Name the touch, distance, light, and color sensors and what each one measures
- Read a sensor value and explain that a reading is a number, not a yes/no
- Find a threshold that separates near from far or light from dark
- Explain detection limits, noise, and why you take several readings
- Calibrate a sensor so its readings are reliable for this room and robot
Learn
Four senses a robot can have
A robot senses the world through sensors. Four common ones are the touch sensor (is it being pressed?), the distance sensor (how far is the nearest thing?), the light sensor (how bright is it?), and the color sensor (what color is the surface?).
Each sensor measures just one kind of thing. A distance sensor can't tell color, and a color sensor can't tell distance. Choosing the right sensor for a job is part of robotics.
For example: Touch: a doorbell button; Distance: a car's parking beeper; Light: a phone screen that dims in the dark; Color: a machine that sorts recycling by color
A reading is a number, not a yes or no
Most sensors don't just say 'yes' or 'no' - they give a number called a sensor reading. A distance sensor might read 12 centimeters; a light sensor might read a brightness of 47.
Because it's a number, the reading changes smoothly as the world changes. As you move a wall closer, the distance number gets smaller. As a room gets brighter, the light number gets bigger.
For example: Distance sensor: 12 cm, 30 cm, 85 cm; Light sensor: 10 (dark) up to 90 (bright); Touch sensor is the exception: it usually reads pressed or not pressed
A threshold turns numbers into decisions
A threshold is a cutoff number you choose to separate two cases. If you pick 15 centimeters, then any reading below 15 means 'near' and any reading above 15 means 'far'.
The robot can't pick your threshold for you - you find it by watching the readings and choosing a value that cleanly splits the cases you care about. This week you only find and write down thresholds; next week the robot will use them to react.
For example: Near/far cutoff at 15 cm; Light/dark cutoff at a brightness of 40; Line-follower cutoff between the black line and the white floor
Detection limits: every sensor has a range
No sensor can sense everything. A distance sensor stops working past a certain range - it might read fine up to about 2 meters but give junk beyond that. That farthest point it can still sense is its detection limit.
Sensors also have a closest limit: hold a wall too near a distance sensor and the reading gets strange. Knowing the limits tells you where you can trust the sensor and where you can't.
For example: A distance sensor that can't read past ~2 m; A color sensor that needs the surface close, almost touching; A light sensor confused by a very bright window
Noise: why one reading isn't enough
Point a distance sensor at a wall that isn't moving and read it several times. You might get 30, 31, 30, 29, 31 - the number wobbles a little even though nothing changed. That wobble is called noise.
Because of noise, one reading can fool you. Scientists and roboticists take several readings and use the middle or average, which is much more reliable than a single number.
For example: Readings of 30, 31, 30, 29, 31 from a still wall; A light sensor that flickers as a cloud passes; Taking 3 to 5 readings and comparing them
Calibration and reliability
Calibration means checking or adjusting a sensor so its readings are correct for this room and this robot. A light sensor reads differently in a sunny room than a dark one, so the same threshold won't work everywhere - you calibrate it to the room you're in.
A sensor you have calibrated and tested is reliable: you can trust it to give the same, correct answer. Reliability is the whole point - a robot that senses wrong will act wrong.
For example: Taking a 'dark' and a 'light' reading to set the middle as your threshold; Re-checking the distance threshold after moving to a new room; Confirming the color sensor tells red from blue on your actual surfaces
Words to know
- Touch sensor:
- A sensor that tells whether it is being pressed or not, like a button or a bumper.
- Distance sensor:
- A sensor that measures how far away the nearest object is, usually in centimeters.
- Light sensor:
- A sensor that measures how bright or dark it is, giving a higher number in bright light.
- Color sensor:
- A sensor that reads the color of a surface right in front of it, like red, blue, or white.
- Sensor reading:
- The number a sensor gives you at one moment, such as 20 centimeters or a brightness of 47.
- Threshold:
- A cutoff number you pick that separates two cases, like 'closer than 15 cm means near'.
- Detection limit:
- The point past which a sensor can no longer sense, like a distance sensor that can't read farther than about 2 meters.
- Calibration:
- Adjusting or checking a sensor so its readings are correct for this room and this robot.
- Noise:
- Small wobbles in a reading even when nothing changes, which is why you take several readings.
- Reliability:
- How much you can trust a sensor to give the same, correct reading each time.
- Trial:
- One single measurement in a test; you usually run several trials and compare them.
- Baseline:
- A starting reading you take in a known, steady condition to compare other readings against.
Stay safe
Read these before you build or run a robot this week.
- Caution:Keep the robot on a stable surface and mind the wheels when moving it between test spots.
- Caution:Guide any blindfolded 'human sensor' and clear the floor so no one trips.
- Caution:Don't shine a flashlight directly into anyone's eyes when testing light sensors.
- Note:Save your reading log often so a browser refresh doesn't lose your data.
Do it
Choose your path
Do this course with a robot kit, the browser simulator, or unplugged with household materials. Pick one - you can switch anytime without losing your work.
Sensor Investigation Lab
Robot kitMeasure how a sensor's reading changes as a condition changes, and find a threshold that cleanly splits two cases.
- Pick one condition to change step by step - the distance to a wall, the brightness, or the surface color - and read the sensor at each step.
- Write every reading in the log. Then look at the numbers and choose a threshold: a cutoff value that separates 'near from far' or 'light from dark'.
- Remember: this week the robot only reads and reports. You are the one who decides what the numbers mean.
Read a real sensor at measured conditions
You need: A programmable robot with a sensor, Tape measure or ruler, A wall or box, Sensor Reading Log worksheet
Steps
- 1Attach the sensor and load a short program that reads the sensor and shows or reports the value (read-sensor, then wait, then stop).
- 2For a distance sensor: place a wall at 10 cm, 20 cm, 40 cm, and 80 cm and record the reading at each. For a light sensor: read the value under a bright light, in normal room light, and covered by your hand.
- 3Look at your numbers and pick a threshold - for example a distance below which you'd call something 'near', or a brightness below which you'd call it 'dark'.
- 4Write your threshold on the log and one sentence saying why you chose that number.
What success looks like: A table of readings that clearly get smaller as the wall gets closer (or larger as it gets brighter), and a chosen threshold that splits near from far.
- At least four readings recorded across different conditions
- The readings change in a sensible direction
- A threshold value is chosen and justified in one sentence
Safety: Keep the robot on the table or floor so it doesn't fall while you read the display.
If it doesn't work
- The reading jumps around and won't settle
- - That is noise - take three readings at each distance and use the middle one.
- The distance reading is stuck at a big number no matter what
- - You may be past the sensor's detection limit or aimed at nothing; point it straight at a flat wall within about 1 meter.
Go further: Move to a different room, re-read your conditions, and check whether your threshold still works or needs re-calibrating.
Week 4 lab
Sensor Investigation Lab
Place an object at different distances and try a light or a dark surface. Read the live sensor values, record them in your table, and pick a threshold. A sensor returns a measurement - a number - not an understanding of what the object is.
Set up the test
Live sensor read-out
These update the moment you change the setup. Same setup, same numbers - every time.
- Distance
- 2 cells
- Touch
- Not pressed
- Light
- 80 of 100
- Over a line
- No
Your data table
Record at least three readings. Try different distances, an edge-of-range reading, the same reading twice, a light surface, and a dark surface.
| What I set | Distance | Light | Notes | Remove |
|---|---|---|---|---|
| No readings yet. Set up a test above and press “Add current reading”. | ||||
0 readings recorded.
Choose a threshold
A threshold is the number your robot compares against to decide. Here: if the distance is at or below your threshold, the robot calls the object NEAR.
Enter a threshold number to see what the robot would decide right now.
Record at least three readings and enter a threshold to finish this lab.
Everything on this page is saved on this device only.
Calibration & Threshold Challenge
Robot kitHandle noise by taking several readings, then calibrate a light-or-dark (or near-or-far) threshold that works reliably in this room.
- Pick a steady condition and take several readings of the same thing without changing anything - notice how much the number wobbles. That wobble is noise.
- Take a reading in a clearly 'low' condition and a clearly 'high' condition (dark vs light, or near vs far). Set your threshold in the middle so it cleanly separates the two.
- Test your threshold: check that low-condition readings land on one side and high-condition readings on the other. If not, adjust it - that is calibration.
Calibrate a threshold on the real sensor
You need: A programmable robot with a light or distance sensor, Colored or shaded cards, or a wall, Sensor Reading Log worksheet
Steps
- 1Read the same still target five times and write down all five numbers to see the noise.
- 2Read a clearly 'dark' surface (or a far wall) three times, then a clearly 'light' surface (or a near wall) three times.
- 3Set your threshold halfway between the dark and light averages.
- 4Test it: show the sensor several dark and light surfaces and confirm each lands on the correct side of your threshold. Adjust if any land on the wrong side.
What success looks like: A calibrated threshold that correctly sorts dark from light (or near from far) surfaces in this room across several checks.
- Five noise readings recorded
- Dark and light averages recorded
- A threshold set between them
- Test surfaces sort correctly, or the threshold is adjusted until they do
Safety: Keep wires clear of the wheels while you move the robot to test surfaces.
If it doesn't work
- A surface sometimes lands on the wrong side
- - The two conditions may be too close together, or noise is large; move the threshold or use more contrasting surfaces.
- The whole set of readings shifted since earlier
- - The room light changed - re-calibrate now, which is exactly why calibration matters.
Go further: Move the robot to a sunnier or darker spot and calibrate a new threshold for that room.
Program the robot
Build a program from blocks, then run it on the simulator. On the kit path, use the same steps in your robot's app; unplugged, act the blocks out on a floor grid. Your program saves on this device.
Sensor-based stopping challenge
Program the robot to drive forward while it watches its distance sensor, then stop in the square right before the wall using the threshold you found. Run three trials, adjust the speed or threshold between them, and explain your final setting in the notes.
Add a block
Events & execution
Movement
Control
Data
Output
Variables & counters
Your program
- Move
- Robot (arrow points where it faces)
- Goal zone (dashed outline)
- Wall (grey, X mark)
Map: A 4 by 1 grid. The robot starts at column 1, row 1, facing right. The goal zone is at column 3, row 1. There is 1 wall.
Ready.
Ready to run. · 0 steps
Robot state
- Column
- 1
- Row
- 1
- Facing
- right
- Distance ahead
- 2 cells
- Touch
- clear
- On a line
- no
- Light
- 80
- In goal zone
- no
- Collisions
- 0
- Steps
- 0
Robot at column 1, row 1, facing right. Distance ahead: 2 cells. Touch: clear. Over a line: no. Light: 80. Not in the goal zone.
Log output
Nothing logged yet.
- Heads up: This program has no safe stop behavior. Add a safe stop so the robot stops when it is done or blocked.
Predict
Commit to a guess before you test - then see how close you were. Your predictions save automatically.
How to check: Place the wall at 40 cm, read the sensor three times, and compare the middle reading to your prediction.
How to check: Take five readings without moving anything and see whether they match exactly or wobble a little (noise).
Test & improve
Distance-vs-reading table
Place the wall (or set the condition) at each listed distance, take the sensor reading, and record the number. Use the middle of three readings if it wobbles.
Measure: The sensor reading at each set distance, and whether you'd call it near or far
| Set distance (cm) | Sensor reading | Near or far? |
|---|---|---|
Three-trial noise check
Pick one condition and don't change it. Read the sensor three times in a row and record each reading to see how much it wobbles.
Measure: How much the reading changes between trials when nothing is changing (the noise)
| Trial | Sensor reading | Difference from trial 1 |
|---|---|---|
Knowledge check
Answer these to check that you understand sensor readings, thresholds, noise, and calibration.
1. Match each sensor to what it measures.
Choose the match for each item.
Distance sensorLight sensorTouch sensorColor sensor2. In your own words, what is a sensor threshold?
3. What is a sensor reading?
4. A distance sensor reads 30 cm at one wall and 12 cm at a closer wall. What does this tell you about how the reading works?
5. You want the robot to treat anything closer than 15 cm as 'near'. What is the number 15 called?
6. You read the same still wall five times and get 30, 31, 30, 29, 31. Why do the numbers wobble?
7. Your light-or-dark threshold worked in the classroom but fails in a sunny room. What should you do?
0 of 7 answered
Reflect
Your reflections save automatically.
Coming up next week
Next week the robot stops just reporting numbers and starts reacting to them on its own, using loops and conditions with the thresholds you found.
- Keep your calibrated thresholds from this week - you'll use them to make the robot decide next week.
- Charge your kit or bookmark the simulator.
- Think about a simple rule like 'if the wall is closer than my threshold, then turn' - that's what you'll build.
Finish Week 4
Complete these to mark the week done and unlock the next one:
- Record sensor readings across conditions in the Sensor Investigation Lab (not done yet)
- Choose and calibrate a threshold in the Calibration & Threshold Challenge (not done yet)
- Score at least 4 of 5 on the knowledge check (not done yet)
- Write your reflection (not done yet)