---
title: "Activity: Stop On Colour Change"
date: "2021-06-03"
categories: ["Activities", "All"]
tags: ["Colour Sensors", "Branching", "Iteration"]
excerpt: "Learn branching, iteration, and how to use the colour sensors."
featuredImage: "/images/resources/stop-on-colour-change.png"
---

Program the rover to keep moving forward until it detects a change of floor colour with the colour sensors. Once it detects this colour, stop the rover.

####
  Relevant Coding Skills

    Branching

	--&gt;

    Iteration

    Functions

    Variables

	--&gt;

    Algorithm Design

  --&gt;

    Maths

####
   Relevant Rover Concepts

    Ultrasonic

 --&gt;

    IR

	 --&gt;

    Colour

    Gyroscope

    Accelerometer

    Motors

    LEDs

	--&gt;

    Buzzer

 	--&gt;

Activity Demonstration

### Setup

For this exercise we recommend a strip of tape stuck to the floor that contrasts the floor colour. It doesn't have to be tape, all that matters is there is a clear change in colour for the rover to detect. An alternative solution is to use a piece of coloured paper.

Your solutions should work no matter how far from the tape the rover starts. Make sure to test the same code from multiple starting positions.

### Here’s Our Approach

#### **Stage 1**

First we need the rover to drive forward towards a change in colour. We tell the rover to move forward with a start moving motor block.

#### **Stage 2**

As the rover drives forward, we need to be constantly checking the colour sensor. Use a repeat until loop block where the condition is set to detect the desired colour. Our code is looking for the brightness of the white tape.

#### **Stage 3**

The rover will keep checking the colour sensor in the loop block until the condition is true. After the repeat we stop all motors.

#### Note

If the simple colour sensor blocks aren’t working we may need to use a different comparison block to check more detailed readings from the sensor. Use the rover sensor view to identify the one that will work best for you.

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/c52097bd-1ea2-415a-a12b-d39f1e142d5b/Screenshot+2023-05-24+123918.png)

Example Code 1

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/2e23eb40-fe43-4840-8f74-5958238dc3c0/Screenshot+2023-05-24+123918.png)

Example Code 2

### 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 &#8594;](/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 &#8594;](/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 &#8594;](/resources/year-7-digital-tech-at-st-peters)

	[All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)
