1 of 50

Ultrasonic Sensor

SensorBot

Confidential and proprietary property of TinkRworks, Inc.

Confidential and proprietary property of TinkRworks, Inc.

2 of 50

  • Ultrasonic Sensors

1

Confidential and proprietary property of TinkRworks, Inc.

3 of 50

Ultrasonic

The ultrasonic sensor sends a sound wave (that you can’t hear) and counts how long it takes for the sound to bounce back.

2

This side Transmits the sound wave.

This side Receives the reflected sound wave.

Confidential and proprietary property of TinkRworks, Inc.

4 of 50

How it works

3

Detected

Not Detected

Confidential and proprietary property of TinkRworks, Inc.

5 of 50

Echolocation

4

Confidential and proprietary property of TinkRworks, Inc.

6 of 50

  • Connect Ultrasonic Sensor

5

Confidential and proprietary property of TinkRworks, Inc.

7 of 50

Power

6

Ground

(GND)

VCC

(5 Volts)

Confidential and proprietary property of TinkRworks, Inc.

8 of 50

Communication

Pins that connect to the Arduino

7

Ground

(GND)

VCC

(5 Volts)

Trigger

Echo

Trigger sends signals to the outside world

Echo receives signals from the outside world

Confidential and proprietary property of TinkRworks, Inc.

9 of 50

Connect Ultrasonic

Materials Needed:

  • Assembled Chassis
  • Ultrasonic Sensor
  • Jumper wires (red, orange, blue, black)

8

Confidential and proprietary property of TinkRworks, Inc.

10 of 50

Connect Wires to Sensor

VCC – Red Wire

Trig – Orange Wire 

Echo – Blue Wire

Gnd – Black Wire 

9

Confidential and proprietary property of TinkRworks, Inc.

11 of 50

Connect Wires to PCB

10

Red Wire – 5V

Orange Wire – D12

Blue Wire – D11

Black Wire – GND

Confidential and proprietary property of TinkRworks, Inc.

12 of 50

Check Your Work

Trace your wires!

VCC – Red Wire – 5V

Trig – Orange Wire – D12

Echo – Blue Wire – D11

Gnd – Black Wire – GND

11

Confidential and proprietary property of TinkRworks, Inc.

13 of 50

Place the ultrasonic sensor in the mount

Place the ultrasonic sensor into the mount with the wires pointing up.

12

Confidential and proprietary property of TinkRworks, Inc.

14 of 50

Video

13

Confidential and proprietary property of TinkRworks, Inc.

15 of 50

  • Program Ultrasonic Sensor

14

Confidential and proprietary property of TinkRworks, Inc.

16 of 50

It’s Time to Code!

  • Open Google Chrome (web browser)

  • Navigate to www.tinkrcode.com

  • Click “Have a Code?

  • Log in with your Project and Class codes.

15

Confidential and proprietary property of TinkRworks, LLC

17 of 50

Open Your Program

Open your program.

16

Confidential and proprietary property of TinkRworks, LLC

18 of 50

Connect to Bluetooth

17

  • 1. Click Connect.

  • 2. Choose the number that is on your Project Sticker and click Pair.

  • 3. Green means connected!

Confidential and proprietary property of TinkRworks, LLC

19 of 50

Sensor Setup

  • From the sensor drawer, get a sensor setup block, and add it the setup part of your program.

  • Change the Trigger Pin to D12 & the Echo Pin to D11.

18

Confidential and proprietary property of TinkRworks, Inc.

20 of 50

Ultrasonic Distance

  • Pull this block from the Sensor drawer.

  • This block checks to see if the Ultrasonic sensor detects something.

  • If it has detected something, it tells you how far away that object is.

19

Confidential and proprietary property of TinkRworks, Inc.

21 of 50

Print the Distance

  • Drag a Print Number block from the Serial Print drawer.
  • Remove the 0 and snap the blocks together.

  • Put the resulting block into the Loop part of your program.

20

throw this away

Confidential and proprietary property of TinkRworks, Inc.

22 of 50

Sensor Data

  • In the Serial Print window, what are the numbers?

  • What do the larger numbers mean?

  • What are the smaller numbers?

  • What does 1000 mean?

  • What happened when you moved your hand to the side of the sensor?

  • What happened when you tilted your hand so that it was no longer parallel to the sensor?

21

Confidential and proprietary property of TinkRworks, Inc.

23 of 50

Where the Sensor Fails

22

Confidential and proprietary property of TinkRworks, Inc.

24 of 50

Making decisions

  • It will have to make decisions about how to move based on what it ‘sees.’

  • For this, we will need to use a conditional statement.

23

  • We want our robot to react to objects in the environment.

Confidential and proprietary property of TinkRworks, Inc.

25 of 50

Conditionals

24

Confidential and proprietary property of TinkRworks, Inc.

26 of 50

Making decisions

This section is the conditional (If/Then/Else statement)

25

Confidential and proprietary property of TinkRworks, Inc.

27 of 50

Conditionals in TinkRcode

If chance of rain is > 80%

26

Take the bus home

Go to soccer practice

Confidential and proprietary property of TinkRworks, Inc.

28 of 50

Combining conditionals

27

  • What does it do when the house is too hot?

  • What does it do when it’s too cold?

  • What does it do when the temperature is just right?

Putting one conditional in another is called “nesting

Confidential and proprietary property of TinkRworks, Inc.

29 of 50

How would this look in TinkRcode?

Algorithm

TinkRcode

28

Confidential and proprietary property of TinkRworks, Inc.

30 of 50

Else If

Two If/Else statements

Else if

29

Confidential and proprietary property of TinkRworks, Inc.

31 of 50

Planning the Conditional

What do we want OUR conditionals to be?

30

Test:

    • IF there is an object < 10cm away

Then:

    • Spin right

Else:

    • Go straight

Confidential and proprietary property of TinkRworks, Inc.

32 of 50

Build the Test

31

Test:

    • IF there is an object < 10cm away

10

Confidential and proprietary property of TinkRworks, Inc.

33 of 50

Put it together

What does this code do?

How will the bot behave?

32

Confidential and proprietary property of TinkRworks, Inc.

34 of 50

  • Challenges

33

Confidential and proprietary property of TinkRworks, Inc.

35 of 50

Challenge #1: Avoid It

Challenge Name

Avoid It

Challenge Objective

  • Create a subroutine containing code that will make the bot back up, spin right, and then stop if the Ultrasonic Sensor detects an object.
  • Name it “Avoid It”.

Challenge Notes

  • You’ll need to decide the value for the distance from the ultrasonic sensor to use.
  • How long to backup and spin for.
  • Put the “Forward Slow” subroutine and the “Avoid It” subroutine in the loop to test it out.

34

Confidential and proprietary property of TinkRworks, Inc.

36 of 50

Challenge #2: I’m not touching you!

Challenge Name

I’m not touching you!

Challenge Objective

Code your bot to move forward whenever it’s far away from your hand, back up whenever it’s too close, and stand still whenever it’s in between.

Place it in a subroutine named “Not Touching You”

Challenge Notes

  • You’ll need to decide what the thresholds should be.
  • How close can your thresholds be to each other?
  • How close can your robot get to you without touching you?

35

Confidential and proprietary property of TinkRworks, Inc.

37 of 50

Challenge #3: Wall Following

Challenge Name

Wall Following

Challenge Objective

Code your bot to move along a wall, by curving toward the wall when it’s too far away and then curving away from the wall when the robot gets too close.

Challenge Notes

You may find success by speeding up and slowing down the outside wheel.

Use a servo command to point the ultrasonic sensor to the side.

36

click to start

Confidential and proprietary property of TinkRworks, Inc.

38 of 50

Wall Following Demo

37

Confidential and proprietary property of TinkRworks, Inc.

39 of 50

Wall Following Parameters

Parameters:

  • Overall speed
  • Angle of turns
    • How different are the speeds between the 2 motors.
  • Direction of the ultrasonic sensor
  • Distances from the wall to guide direction of bot.
  • Addition of delays or stops?

38

Confidential and proprietary property of TinkRworks, Inc.

40 of 50

  • Solutions

39

Confidential and proprietary property of TinkRworks, Inc.

41 of 50

Challenge #1 Solution: Avoid It

40

Confidential and proprietary property of TinkRworks, Inc.

42 of 50

Challenge #2 Solution: I’m not touching you

41

Confidential and proprietary property of TinkRworks, Inc.

43 of 50

Challenge #3 Solution: Wall Following Setup

42

If you are following a wall to the bot’s right, turn the ultrasonic sensor to the right.

Confidential and proprietary property of TinkRworks, Inc.

44 of 50

Challenge #3 Solution: Wall Following Loop

43

Confidential and proprietary property of TinkRworks, Inc.

45 of 50

Wall Following using a Variable

44

  • An optimization can be added to only read the sensor once per loop.

  • This speeds up the loop and allows the decisions to be based on one measurement.

Confidential and proprietary property of TinkRworks, Inc.

46 of 50

Challenge #3 Tip: Print out distance

45

Confidential and proprietary property of TinkRworks, Inc.

47 of 50

Challenge #3 Tip: Add Lights

46

Confidential and proprietary property of TinkRworks, Inc.

48 of 50

Wall Following Slowdown

47

Confidential and proprietary property of TinkRworks, Inc.

49 of 50

Subroutine

  • Put your code in a subroutine named “wall follow”.

48

Confidential and proprietary property of TinkRworks, Inc.

50 of 50

TinkRworks, Inc.

501 W Lake Street, Suite 106

Elmhurst, IL 60126

www.TinkRworks.com

© TinkRworks, Inc. All rights reserved

Sparking CREATIVITY

Fostering INNOVATION

Sharpening PROBLEM-SOLVING skills

Confidential and proprietary property of TinkRworks, Inc.