Hi everybody, my name is Massimo Banzi and I'm one of the co-founders of Arduino.
Welcome to the third video about the Arduino robot sponsored by RS components.
In this video, David Cuartielles and Xun Yang are going to explain to you how to add different kinds of sensors
to the robot to avoid obstacles and create strategies.
So, in this video we're going to go deeper into the programming and building of behaviours with the robot.
So, I'm sure you will enjoy it, and over to you David.
Hello this is David. This is Xun.
Today you're going to see how to use different techniques to avoid obstacles using different types of sensors.
First, we're going to check how to use an ultrasound sensor, then an infrared sensor,
then a self-made sensor with an ultra-bright LED and LDR.
Xun? Yeah.
Okay, let's have a look at the ultra-sonic sensor.
So, this is one that you can get from an electronic shop and you just need to solder three wires to it
and we use a TinkerKit cable to connect it to the robot.
So, what we want to do is connect it to port M1 on the robot.
And then we'll face the sensor directly to the front, you can use tape or anything that will attach it to the right position.
Okay, this should work.
Plug it into the computer.
And we provide you with an example that will help you connect directly this particular brand of ultrasound sensor.
It's the example called Runaway Robot.
The idea with the example is that the robot is going to take an obstacle and then turn in a direction
to try to avoid the obstacle, and if there is no obstacle than it will try to move forward again.
You can take a look at the code, of course you first have to import the Arduino robot library
then you decide which pin is going to work with the sensor.
Start the robot, start the screen, show the logo types, and then we'll check the distance.
getDistance() is a function and if the distance is less than 40, 40 actually maps more or less 20 centimetres
away from the robot. It will show an unhappy face on the screen, will stop the motors, wait for a second,
turn 90 degrees, change the face on the screen, and start moving again.
I'm going to be ready to stop it. You see? It stops, it turns [laughing] and it continues moving
it will come towards me I was just, stop it [laughing]. So, you can see that right now it's showing a sad face.
Okay. That's about using ultrasound. Ultrasound sensors like this one you can find in two different types:
with one single ultrasound cone, or with two ultrasound cones.
Ultrasound works over 40 or more kilohertz, and it works by sending an ultrasound signal just like the bats
it's like a sonar, sends a signal, bounces off an object, and it returns. And then the sensor is able of measuring.
the amount of time that it takes for the signal to fly over the air and come back.
Now we're going to explore a different type of sensor which is the infrared sensor.
This is an infrared sensor.
And as you see this one has a meter and a receiver.
It's very different from this one because it works on the invisible range of light,
whereas this one works in non-audible range of sound.
This particular one is very good for robotics because it works between 10 centimetres and 8 centimetres.
So, it comes with a special connector. What we did is to hack it, like here, to work with an ending from
a TinkerKit connector, so it's very easy to mount it on top of the robot.
So now, you have the robot with two ultrasound sensors mounted on top.
Like this one we saw earlier, it's a very standard SHARP distance sensor.
Okay, so we have programmed this robot, so when the two sensors, either of them is blocked,
the robot will turn to another direction. Let's turn it on.
So, let's first block this sensor on the right.
And the one on the left.
So now we're going to see how this program works directly here on the computer screen.
It's a very simple example, so first of all we call the Arduino library for the robot
then we have defined a threshold of 600. This sensor, when you're more or less at this distance is reading at 600
Below this point it's going down, and then we read the pin for the one sensor we call sensor right
that is the one that Xun just touched, and there is sensor left and we bring the information to the computer screen
so we can actually, by connecting the computer to the robot we can see what's going on.
And depending whether the sensor is activated and the other is not activated,
the robot will turn in one direction, and if it's the opposite thing, it will turn back
as you see we have chosen a speed of 160 for turning, otherwise the robot turns really really quick
and it's really hard to show live.
So now, we're going to see our final example, where we're going to see how to build your own distance sensor
using a very strong, ultra-bright white LED, and an LDR.
Now I'm going to teach you how to make your own distance sensor by using a TinkerKit LED and LDR sensor
So the principle is like this, the LED will be emitting light, and when the robot is getting close to a flat surface
the light from the LED will be reflected back into the LDR sensor.
Then the robot will know that it's getting close to an obstacle.
So, we'll turn on the robot now and see how it works, and we'll show you the code in the computer
so you see it's a very very simple code example, it's very similar to the other two that we saw earlier
with the difference is that this is a self-made sensor, so you could do it yourself out of discrete parts.
So here you go, the robot is running now. It's not close to any object and therefore, it's not reacting
as soon as we put an object close to it, you see, whirl around, and as soon as it finds there's nothing in front of it,
it will stop. It's a very simple example.
Now, we're going to connect the robot to the computer using a normal USB cable
mostly just to check that the same code is actually sending data back to the computer
and we can read that information straight on the computer screen.
The program, as you see here, is using the ArduinoRobot library.
We're setting up a threshold of 740 for the values read by the LDR.
This, you have to configure it to accommodate the light in the room you are in.
We start the robot, we start the serial communication, we write this in, which is the pin where the LED is connected to, on
so that the light is always on.
And we start reading inside the loop for the value of the LDR.
We read it, we print it out, and if the value is smaller than this threshold we've determined up here,
will print out turn left and then it will turn left.
So, let's just check that we have the right serial port. We do.
And we just open the serial port communication to the robot, you will see in the window here
how it's reading the value that is above 740. And, Xun you can put your hand in front of the sensor.
You see, when the sensor triggers 740 it prints out "turn left" which is the action that the robot is executing
using the motors.
So in today's video we showed you how to use a distance sensor to detect obstacles.
We showed you how to use an ultrasonic sensor, a pair of infrared sensors,
which detects whether the obstacle is on the left or the right, and also how to build your own distance sensor
with an LED and an LDR sensor.
This is was our third video in the series on how to use the Arduino robot.
Thank you very much for watching, and don't miss our next chapter,
where we will see how to make the robot follow lines.
See you next time. See you next time!
Okay, so that was great, so you learned how to use sensors and how to build behaviours
and in the next video we're going to show you how to follow lines,
and use some of those sensors that are embedded into the robot.
See you next time!