Skip to content

Instantly share code, notes, and snippets.

@topshed
Created January 11, 2024 15:41
Show Gist options
  • Save topshed/6b59f39508dcc527c5552e7f02bf9e9f to your computer and use it in GitHub Desktop.
Save topshed/6b59f39508dcc527c5552e7f02bf9e9f to your computer and use it in GitHub Desktop.
Detecting Colour
using the colour sensor, you can detect a range of colours and how much light is reflected from an object
@topshed
Copy link
Author

topshed commented Jan 11, 2024

Detecting colours

Add a colour sensor to your robot. If you're building a line following robot, then it needs to be pointing at the floor as shown below.

PXL_20240111_154025584

Otherwise, mount it facing forwards.

Move forward but stop if you're over something red.

Snip20240111_14

Black vs white

Detecting black/white can be trickier, depending on the lighting conditions, and if the black object is quite shiny. This is the most reliable method: the hub will display W if the sensor sees something white, and B if it sees something black.

Snip20240111_15

NEXT: Line following

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment