Files
micromelon-website/content/resources/line-following.mdx
Tim Hadwen ae3ae18585 Major site overhaul: resources hub, content migration, new blog posts, forms
- Redesign /resources as sectioned hub with category pages
- Migrate 645 Squarespace CDN images to local /images/content/
- Create 9 new news/blog posts with event photos
- Fix blog post slugs (rename gibberish filenames)
- Rename Design Blog to Design Blogs across site
- Remove education page, replace with Platform in nav
- Redesign rover repair request form with dynamic rover entries
- Add school search combobox to contact, store, and repair forms
- Extract shared KNOWN_SCHOOLS data
- Make /rover-expansion-3d-printing dynamically pull from MDX
- Add related resources sections to product pages
- Fix homepage broken /quote links to /store
- Store page: sample kit cards, inline quote builder, mailing list opt-in
2026-03-01 17:14:05 +10:00

47 lines
2.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Activity: Line Following"
date: "2022-02-23"
categories: ["Activities", "All", "Simulator Activities"]
tags: ["Colour Sensors", "Branching", "Iteration", "Algorithm Design", "Intermediate"]
excerpt: "Learn the colour sensor and simple algorithm design while following the line."
featuredImage: "/images/resources/line-following.png"
---
Program the rover to follow a line. Use the colour sensors on the rover to help detect where the line is and determine where the rover should move and turn to stay on the line.
![](/images/content/055865-line-following.png)
Activity Demonstration
### Setup
When setting up ensure that the line to be followed has a clear contrast from the surface it is on and is thick enough for the colour sensors to detect. We recommend a thickness of 1-2cm, anything less will become difficult for the rovers. When designing a track, try and use rounded corners for turns. The sharper the turn the more difficult it will be to stay on the line. You can also incorporate additional challenges into your course. For example, have rovers detect and go around objects on the track or detect different coloured lines that indicate speed changes or turning directions at intersections.
### Heres Our Approach
#### Stage 1
Add a while true loop and an ELSE/IF statement so that we can continuously ask our rover questions about its environment.
#### **Stage 2**
Now we need to add our brightness value that we are comparing to (in this case 210).
If you need to check the brightness value of your line, you can see the colour sensor values in the Sensor View of the Code Editor. Press the ROVER button in the top bar of the Code Editor. You can see the colour sensor values in the top right table of Sensor View.
#### **Stage 3**
Pick a brightness value between your line and the colour next to your line (e.g. if your sensor reads 130 for black, and 230 for white, something like 180 would be a good starting point). Then get the rover to drive gradually left or right using the set motor speeds block.
**Tip:**
Test with different numbers! In our example, a speed difference of 8 for the motors worked well, but numbers for your rover may vary. You could even experiment with different RGB values to see if that gives you a better result.
![](/images/content/3d0d0c-line-following-answer.png)
Example Code
![](/images/content/5b4ec0-line-following-sensor-view.png)
Sensor View in the Code Editor