Files
micromelon-website/content/resources/line-following.mdx
Tim Hadwen 707c49dd3f Build Your Kit page and full Micromelon website
Complete website build including:
- Build Your Kit store page with cart system, sectioned layout
  (Hardware, Software, Attachments, Spare Parts), inline quote
  request form, and sticky sidebar summary
- 16+ pages: Education, Platform, Resources, News, About Us,
  Download, Contact, Rover, Code Editor, Robot Simulator, etc.
- 89+ MDX resource articles and 18 news posts
- Store product images scraped from micromelon.com.au
- Quote request API route with Airtable integration
- Dynamic back links and cover photos on resource pages
- Redesigned downloads page
- Fixed corrupted MDX code blocks
2026-02-28 19:00:42 +10:00

111 lines
4.7 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"
---
[
![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/d48b056d-c05e-4abd-aceb-0e397c551283/Simulator+Indicator.png)
](/robot-simulator)
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.
![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1645647891907-6F5L61OFOMNV437NNH3T/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.
![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/e6dda0a5-3de2-41f2-ab19-0c502b693f90/line-following-answer.png)
Example Code
![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/967f926d-3f4c-4eaf-96e2-ef7b398a6c30/line-following-sensor-view.png)
Sensor View in the Code Editor
### Related Posts
Resources
[
![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1639455538805-9NI7CPKR7IYG6D4RBKAN/high+quality+sumo.png)
](/resources/creating-a-sumo-unit)
[All](/resources?category=All)
[Creating A Sumo Unit For Your Digital Technologies Class](/resources/creating-a-sumo-unit)
[All](/resources?category=All)
How to run a sumo unit in your digital technologies classroom.
[Read More →](/resources/creating-a-sumo-unit)
[All](/resources?category=All)
[
![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1637464845856-BBPD7GTIIHHOSJCFORWF/the+ultrasonic+sensor.png)
](/resources/ultrasonic-sensor)
[All](/resources?category=All), [Guides](/resources?category=Guides)
[The Ultrasonic Sensor](/resources/ultrasonic-sensor)
[All](/resources?category=All), [Guides](/resources?category=Guides)
Learn all about the ultrasonic sensor!
[Read More →](/resources/ultrasonic-sensor)
[All](/resources?category=All), [Guides](/resources?category=Guides)
[
![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1625616494179-LZHZP5MUA0E0MQKEB7HC/cropped+image+4.png)
](/resources/year-7-digital-tech-at-st-peters)
[All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)
[Case Study: Year 7 Digital Tech at St Peters Lutheran College](/resources/year-7-digital-tech-at-st-peters)
[All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)
See how Meg Foley at St Peters conducted a challenge for their Year 7s using Micromelon.
[Read More →](/resources/year-7-digital-tech-at-st-peters)
[All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)