Lesson video

In progress...

Loading...

Hello, my name is Mrs. Holborow and welcome to Computing.

I'm so pleased you've decided to join me for the lesson today.

In today's lesson, we are going to be setting up and using optical reflective sensors to get a robot buggy to follow a line.

Welcome to today's lesson from the unit: Using physical computing to create a robot buggy.

This lesson is called Optical Sensors for Navigation, and by the end of today's lesson, you'll be able to describe and use optical reflective sensors to react to an environment.

Shall we make a start? We will be exploring these key words throughout today's lesson.

Let's take a look at them now.

Environment.

Environment, the surroundings or conditions something exists in or reacts to.

Optical.

Optical, something that relates to light and vision.

Reflective.

Reflective, something that bounces back light or other waves like sound.

Look out for these key words throughout today's lesson.

Today's lesson is broken down into two parts.

We'll start by describing optical reflective sensors and then we'll move on to use optical reflective sensors to follow a line.

Let's make a start by describing optical reflective sensors.

A sensor detects changes in the environment.

Sensors convert information into a signal that can be measured and used.

Jun says, "I've used an ultrasonic sensor to measure distance.

There are also lots of other types such as optical sensors." Sophia has a question.

"What is an optical sensor?" Optical sensors use light to detect objects or changes in the environment.

They can be used when non-contact sensing is important.

A reflective optical sensor sends out infrared light through an LED.

So you can see here, we've labelled the LED on the sensor.

The receiver is coated so that only infrared light is able to get through.

So you can see the receiver is highlighted on the diagram.

If infrared light is detected in the receiver, the sensor sends out a signal through one of its pins.

So you can see we've got the signal and the pin highlighted at the bottom of the sensor.

The signal can then be used by a microcontroller.

So here we have our optical sensor.

The infrared LED sends out infrared light.

Infrared light is reflected off the object.

Infrared light is detected in the receiver and the sensor sends a signal out.

Jun says, "I can't see anything coming outta the LED.

Where's the light?" Sophia says, "I think I remember that human eyes can't see infrared light." Infrared or IR light is just outside the wavelength that humans can see.

Optical sensors are used in a number of real life applications such as: Hand dryers to detect when hands are placed under.

Printers to detect sheets of paper.

Lift doors to detect when someone is in the way.

Robots to follow lines on the floor in a factory.

The colour and surface texture of an object can affect the way light is reflected.

Sophia says, "Light coloured surfaces like white reflect more light and are easier for sensors to detect." Jun says, "Dark or rough surfaces absorb or scatter light, making sensors detect less or no light at all." When working with optical sensors, you should consider how the colour of target services and objects will affect the function of the sensors.

Optical sensors have several advantages and disadvantages which are outlined in the table below.

So advantages: No physical contact is needed to detect objects.

They have a fast response time.

They're compact and easy to instal.

They're inexpensive and reliable for simple tasks.

Disadvantages: They're affected by surface colour and texture, so for example, dark, shiny or transparent materials.

They have a limited range, and performance can vary in ambient light.

By ambient light, we mean when light isn't very good.

They can also give false readings in dusty or foggy conditions.

Time to check your understanding.

I have a question for you.

Optical sensors are: A, used when non-contact sensing is important.

B, used when physical contact is needed.

Or C, not affected by surface colour and texture.

Pause the video whilst you think about your answer.

Did you select A? Well done.

Optical sensors are used when non-contact sensing is important.

Infrared light emitted from an LED: A, is visible to the human eye.

B, appears red to the human eye.

Or C, is invisible to the human eye.

Pause the video whilst you have a think.

Did you select C? Well done.

Infrared light emitted from an LED is invisible to the human eye.

I have a true false statement for you now.

Dark coloured surfaces reflect more light and are easier for sensors to detect.

Is this true or false? Pause the video whilst you have a think.

Did you select false? Well done.

But why is it false? Light coloured surfaces like white reflect more light and are easier for sensors to detect.

Okay, we are moving on to our first task of today's lesson, Task A.

I'd like you to fill in the blanks below.

Optical sensors use light to, objects or changes in the environment.

A, optical sensor sends infrared light out through an, and receives reflected infrared light back in the.

If the infrared light is detected in the receiver, the, sends a signal out through one of its pins so a, can use it.

The word bank you can use to fill in the gaps includes the words reflective, sensor, detect, receiver, LED and microcontroller.

Pause the video whilst you complete the task.

How did you get on? Did you manage to fill in the blanks? Let's have a look at the answers together.

Optical sensors use light to detect objects or changes in the environment.

A reflective optical sensor sends infrared light out through an LED and receives reflected infrared light back in the receiver.

If the infrared light is detected in the receiver, the sensor sends a signal out through one of its pins so a microcontroller can use it.

Did you fill in all the correctly? If not, remember you can pause the video here and make any corrections.

Okay, so so far we've described optical reflective sensors.

Let's now move on to use optical reflective sensors to follow a line.

When two optical sensors are used together, you can make a buggy closely follow a line on the ground.

Let's watch this video a couple of times just to see how it's working.

Can you see the buggy is following the line that has been drawn on the piece of paper really quite closely.

In the example below, you can see the indicator lights change state when the buggy crosses the black line.

Watch the video carefully and look at the lights.

When combined with forward motion, this results in the buggy following the line.

A reflective optical sensor usually has three connecting pins.

So you can see these pins down at the bottom of the diagram.

The first pin on the left hand side is G.

The next pin is V+, and the pin on the left is S.

What do these stand for? Let's have a look.

So G is the GND or ground and connects to the blue common ground rail on the breadboard.

V+ is the supply voltage and connects to the red common power rail on the breadboard.

S is the sensor output signal and can be connected to a suitable GPIO pin.

Note that the sensor has a potentiometer that can be turned on to adjust the sensitivity.

So the potentiometer is now labelled on the diagram.

A potentiometer is a variable resistor that allows you to regulate the current flowing through a circuit.

Time to check your understanding.

I have a question for you.

On an optical sensor, which pin sends an output signal to a microcontroller? Is it A, S, B, G or C, V+? Pause the video whilst you have a think.

Did you select A? Well done.

S is short for signal, so it's sending out the signal to the micro controller.

On an optical sensor, which pin is connected to the blue ground rail on the breadboard? Is it A, V+, B, S, or C, G? Pause the video whilst you have a think.

Did you spot it? Well done.

C, G, the ground pin is connected to the ground rail on the breadboard.

When a sensor is above the black line, it outputs a one.

When it's off the black line, it outputs a zero.

A microcontroller can then use this data to control a buggy along a line.

If the left sensor is over the black line, the buggy needs to adjust left.

The buggy can adjust left or anti-clockwise by making the left motor rotate backwards and the right motor forwards briefly.

So you can see here we've got some code that will make this happen.

So motor_right_fwd, for forward,.

high.

And then motor_left_bwd, for backwards,.

high.

So the left rotates backwards and the right rotates forwards.

If the right sensor is over the black line, the buggy needs to adjust right.

The buggy can adjust right or clockwise by making the left motor rotate forwards and the right motor backwards briefly.

So we've just swapped our two lines of code round here.

So we've got motor_right_bwd.

high, and then motor_left_fwd.

high.

So left rotates forwards and right rotates backwards.

If neither sensor is over the black line, this means the buggy is in a central position and can proceed to move forwards.

So here's some code, motor_right_fwd.

high, motor_left_fwd.

high.

Both motors can be set to rotate forwards.

I have a draw false statement for you here.

When an optical sensor is above a black line, it outputs a one.

Is this true or false? Pause the video whilst you have a think.

Did you select true? Well done.

The sensitivity of the optical sensors is set in the factory and cannot be adjusted.

Is this true or false? Pause the video whilst you have a think.

Did you select false? Well done.

Optical sensors usually have a potentiometer that can be turned to adjust the sensitivity.

Okay, we are now moving on to task B of today's lesson.

For part one, if you can, follow the instructions in task B activity one to set up the reflective optical sensors.

The instructions are provided as an additional resource for this lesson.

For part two, if you can, follow the instructions in task B activity two to test the reflective optical sensors with some code.

For part three, if you can, follow the instructions in task B activity three to add reflective optical sensors to an existing project such as a robot buggy.

Pause the video here whilst you complete the tasks.

How did you get on? Did you manage to set up the optical reflective sensors and try out some code? Great work.

For part one, you were asked to set up the reflective optical sensors.

This diagram shows how to correctly set up the sensors with a Raspberry Pi Pico and a breadboard.

If you haven't got your sensors set up correctly and they're not working, maybe pause the video here and look carefully at the diagram.

For part two, you were asked to test the reflective optical sensors with some code.

So here's some test code.

On line one we have from machine import Pin.

And line two, import utime.

On line four we have: left_sensor is equal to Pin (10, Pin.

IN) On line five, exactly the same line of code, but this time right_sensor and the Pin is Pin 11.

On line seven we are starting our while loop, so we have while True.

And then we have line eight, print left, so the text left is going to be printed and then the value that is held by the left_sensor.

variable.

On line nine the same, but this time for the right sensor.

And then on line 10 we are adding a pause in, so utime.

sleep(2).

For part three, you were asked to add the reflective optical sensors to an existing project such as a robot buggy.

Did you manage to add the reflective optical sensors to your robot buggy? Did you manage to add any additional code to make your buggy follow the path.

If you did, well done.

Okay, we've come to the end of today's lesson, Optical Sensors for Navigation, and you've done a fantastic job, so well done.

Let's summarise what we've learned in this lesson.

Optical sensors use light to detect objects or changes in the environment.

A micro controller can use the data from optical sensors to control a buggy along a line.

Infrared or IR light is just outside the wavelength that humans can see.

The colour of target surfaces and objects will affect the function of the optical sensors.

I hope you've enjoyed today's lesson and I hope you'll join me again soon.

Bye.