The IR Distance Sensors

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 you’re curious about how the Ultrasonic sensor works read our ultrasonic sensor blog post

 

What is IR?

Before we jump into how the IR sensors work, let’s 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 they’re 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.

my spectrum diagram.png

Visible light is electromagnetic waves with a length of 400–700 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 doesn’t mean the other electromagnetic waves don’t exist. Lots of cool technology uses electromagnetic waves from all over the spectrum.

 

Who Can See Infrared Light?

Howard the snake loves code

Howard the snake loves code

There are some snake species that can detect infrared light but they don’t 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 snake’s 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, let’s 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:

ir diagram animation.gif
  1. The IR sensor emits an IR laser outwards.

  2. The light travels out and bounces off of an object or surface.

  3. The reflected light is now traveling back to the sensor.

  4. 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 Rover’s 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 Rover’s 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.

 

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 rover’s name. If you need a refresher on how to use the rover & code editor, check out this post.

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.

opening sensor view.gif
using sensor mode  small.gif
 

Using The IR Sensors In Code

Let’s write a simple program to print our left IR sensor values every second for 10 seconds.

writing a piece of code left only.gif
  1. Start by adding a Repeat 10 Times block.

  2. Inside the loop, place a Print statement. You can find this in the Utilities category.

  3. 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().

  4. Add a Delay For 1 Second block so this loop waits 1 second before running again.

  5. Press Play!

    When we run this; we will see the left IR distance value every second for 10 seconds.

 

Wrapping Up

Now that we’re familiar with what the IR distance sensors are, how they work and how to program them it’s time to start doing some activities. Try these activities that are done best using the IR sensors.

 

Related Posts

Previous
Previous

The Accelerometer

Next
Next

Getting Started With The Robot Simulator