Files
Tim Hadwen 1f8c46597b Site audit: fix broken images, add activity metadata, clean up content
- Remove broken image references from 25 MDX files (deleted spacer/content images)
- Add codingSkills and roverConcepts frontmatter to 24 activity pages
- Fix "Activity Demonstration" headings in 15 activity files (plain text -> h3)
- Remove unused "All" category from 89 MDX files
- Decode HTML entities (> <  ) in 9 content files
- Escape bare < > characters in MDX to fix build errors
- Standardize contact email to contact@micromelon.com.au
- Add missing description to rover-repair-request metadata
- Include previous session work: about-us updates, difficulty filtering,
  LearningPathway component, expanded schools list, new product/resource images

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 21:49:15 +10:00

105 lines
5.9 KiB
Plaintext
Raw Permalink 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: "The IR Distance Sensors"
date: "2021-06-18"
categories: ["Sensor Guides"]
tags: []
excerpt: "Learn what the IR distance sensors are and how to code them."
featuredImage: "/images/resources/ir-sensor.gif"
---
![](/images/content/96db3a-spinning-annotated-version.gif)
There are two infrared (IR) distance sensors located on the Rover. One on either side.
**What Do They Do?**
The IR sensors gives data on the distance between the robot the object the sensor is facing. There is a sensor on each side of the Rover so we can detect if there are any obstacles (like walls) near the sides of the Rover.
The IR sensors work differently to the front Ultrasonic distance sensor. If youre curious about how the Ultrasonic sensor works read our [ultrasonic sensor blog post](/resources/ultrasonic-sensor)
**What is IR?** Before we jump into how the IR sensors work, lets look at what IR actually is. IR stands for infrared. Infrared is a type of light. Human eyes cannot see** infrared light**. The light we see from the sun & light bulbs is called** visible light**.** Visible light ** and** infrared light** are different types of light.
All types of light are made up of something called electromagnetic waves. The science behind electromagnetic waves and how we see them is complicated, for now all we need to know is that they exist and theyre all around us. Electromagnetic waves vary in length, similar to how there are big waves and small waves at the beach. The diagram below shows the entire range of electromagnetic wave lengths.
![](/images/content/500b68-my-spectrum-diagram.png)
**Visible light** is electromagnetic waves with a length of 400700 nanometres (nm).** Infrared light** is electromagnetic waves with a length of 700nm to 1mm.
You can see in the diagram, there are a bunch of different types of electromagnetic wave ranges like radio, ultraviolet and gamma ray. The human eye can only perceive electromagnetic waves in the **Visible light** range but that doesnt mean the other electromagnetic waves dont exist. Lots of cool technology uses electromagnetic waves from all over the spectrum.
**Who Can See Infrared Light?**
![](/images/content/338ab2-snake-joke.png)
Howard the snake loves code
There are some snake species that can detect infrared light but they dont use their eyes. They have small pits on their faces that are sensitive to infrared light. They use this ability to hunt for prey. The infrared waves produced by the body heat of the snakes prey is what the snake is able to detect.
Although we cannot see it with our eyes, just like snakes we can use build devices to emit and detect infrared light. This is exactly what the IR sensor on our robot does.
Ok, now that we know a bit about IR, lets look at how the IR sensors on the rover work.
### How do the IR Sensors Work?
The IR sensor uses a laser to detect how far away objects are. Yes the Rover uses two IR lasers. How do these lasers help the Rover detect distance? It uses the following process:
![](/images/content/a5e9c5-ir-diagram-animation.gif)
- The IR sensor emits an IR laser outwards.
- The light travels out and bounces off of an object or surface.
- The reflected light is now traveling back to the sensor.
- The sensor detects the returning light.
**Based on how long it takes the light to reflect back, the sensor calculates how far away the object is using on the speed of light.**
**If the Rovers IR Sensor Emits Infrared Lasers, Does that Make the Rover a Laser Gun?**
Well yes, but actually no.
### IR Problems & Limitations
**The IR Sensors are Limited to a distance of Roughly 1.25m**
The larger the distance the emitted IR laser has to travel, the more likely it is IR detector is unable detect it. Increasing the range of an IR sensor requires a more powerful laser.
The Rovers built in IR sensor are designed to be efficient in small scale activities, you can always add your own electronics to the Rover and equip more powerful sensors. To read more on how to add your own electronics [see this blog post.](/resources/showcase-rover-and-arduino-line-follow)
### Programming the IR Sensors
Open up the Code Editor, connect to a Micromelon Rover and open up the sensor view. To open sensor view, click the ROVER button next to your rovers name. If you need a refresher on how to use the rover & code editor, check out [this post.](/resources/getting-started-with-the-micromelon-rover)
In the sensor view dialog, the IR sensor values are located on the sides of the rover diagram. The left IR sensor value is on the left side, the right value is on the right. The CM next to the values indicates these are centimetre values. To make sure your sensor works, point the IR sensors at different objects and measure how far away they are.
**What does 255cm mean?**
255 is the returned value when an IR sensor is unable to determine an accurate value. If you are seeing 255 it means you may be attempting to detect objects further away than 1m.
![](/images/content/f16a1c-opening-sensor-view.gif)
![](/images/content/86bd08-using-sensor-mode-small.gif)
**Using The IR Sensors In Code**
Lets write a simple program to print our left IR sensor values every second for 10 seconds.
- Start by adding a **Repeat 10 Times** block.
- Inside the loop, place a **Print** statement. You can find this in the ** Utilities** category.
- Place the **Read IR Distance** block inside our ** Print** statement.
You can find the **Read IR Distance** block in the ** Sensors** category. The python command is ** IR.ReadLeft()**.
- Add a **Delay For 1 Second** block so this loop waits 1 second before running again.
- Press Play!
When we run this; we will see the left IR distance value every second for 10 seconds.
### Wrapping Up
Now that were familiar with what the IR distance sensors are, how they work and how to program them its time to start doing some activities. Try these activities that are done best using the IR sensors.