how to create a robot that moves differently depending on how close you are

11
“Robots have taken over our school!” How to make a receptionist robot that greets people when they get close. We are going to use an IR (Infra Red distance sensor). The IR sensor gives our robot very basic vision. Human vision is very clever, when we look through our eyes we see moving images of the world. The IR sensor is much more simple, it can't see pictures of the world, it just sees if things are close or far away.

Upload: neil-winterburn

Post on 15-Feb-2017

100 views

Category:

Art & Photos


0 download

TRANSCRIPT

“Robots have taken over our school!”

How to make a receptionist robot that greets people when they get close.

We are going to use an IR (Infra Red distance sensor). The IR sensor gives our robot very basic vision.

Human vision is very clever, when we look through our eyes wesee moving images of the world. The IR sensor is much more simple, it can't see pictures of the world, it just sees if things areclose or far away.

Breadboards

Breadboards can be used to connect wires, lights, sensors and motors together.

Columns go up and down and are numbered 1 – 30, with letters a toj. If you connect two wires into the same numbered column they will be connected.

Rows going sideways are used for either (+) positive or (-) negative.If you place two wires in the same (+) or (-) row they will be connected.

Infra Red Sensor Schematic

Place the breadboard so that the numbers move from 1 on the left to 30 on the right.

Place the Arduino below the breadboard as shown below.

Connect a red jumper lead from the 5V pin on the Arduino to any hole on the red (+) sideways row at the top of the breadboard.

Connect a black jumper lead from the GND pin on the Arduino to the any hole on the black (-) sideways row at the top of the breadboard.

Connecting the Infra Red Sensor

Connect the red wire from the IR sensor to one of the holes onthe red (+) sideways row of the breadboard.

Connect the black jumper wire from the IR sensor to one of the holes on the black (-) sideways row of the breadboard.

Connect the white (or yellow) jumper wire from the IR Sensor to the A0 analogue pin on the Arduino.

How to program Scratch to read the IR sensor

Drag out a Value Of Analogue 0 block and place it inside a Say block as show to the left.

Attach the IR sensor to the table so that it does not move.

Test: Click the green flag to run the program and move your hand closer and further away from the IR sensor. What happens?

The sensor returns the highest number when it senses something is

_ _ _ _ _ _ _

The sensor returns the lowest number when it senses something

_ _ _ _ _ _ _

Schematic for a servo motor and a distance Sensor

Connect the red wire from the Servo Motor to one of the holes on the red (+) horizontal row of the breadboard.

Connect the black jumper wire from the Servo Motor one of the holes on the black (-) horizontal row of the breadboard.

Connect the white (or yellow) jumper wire from the Servo Motor to Digital pin 8 on the Arduino.

How to control a motor using a distance Sensor

Drag out an IF block, a > More Than block and a Value Of Sensor block and connect them as shown.

Edit the > More Than block so that it reads > 100.

Drag out a Motor 8 Angle block and place it inside the If block.

Drag out an IF block, a < Less Than block, a Value Of Sensor block and connect them as shown.

Edit the < Less Than block so that it reads < 100.

Drag out a Motor 8 Angle block and place it inside the If block changingthe angle to 0.

TEST: Click the green flag to test what happenswhen you move your hand close to the IR sensor.

How to make the motor move at different angles dependingon how close you are to the IR sensor

Drag out the > More than block from your 1st If block and placeit on the canvas.

Drag out

An AND block

A < Less than block

Another Value of Sensor block

Connect the blocks together as shown.

This new block tests if the number form the IR sensor is More than 100 but less than 200.

Place your new More Than AND Less Than block in the 1st If block as shown.

TEST: Click the green flag to test. Make sure that the motor still moves in if the sensor senses something.

Right click on the 1st If block, then left click on duplicate and place the new IF block below the 1st one.

Change the numbers in the > More Than and < Less Than blocks as shown above.

TEST: Click the green flag to test what happens when you move your hand at different distances

Challenge: Program the robot to move the Servo Motor to different angles depending on how close someone gets to the sensor.