Ultrasonic Sensor
SensorBot
Confidential and proprietary property of TinkRworks, Inc.
Confidential and proprietary property of TinkRworks, Inc.
1
Confidential and proprietary property of TinkRworks, Inc.
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.
How it works
3
Detected
Not Detected
Confidential and proprietary property of TinkRworks, Inc.
Echolocation
4
Confidential and proprietary property of TinkRworks, Inc.
5
Confidential and proprietary property of TinkRworks, Inc.
Power
6
Ground
(GND)
VCC
(5 Volts)
Confidential and proprietary property of TinkRworks, Inc.
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.
Connect Ultrasonic
Materials Needed:
8
Confidential and proprietary property of TinkRworks, Inc.
Connect Wires to Sensor
VCC – Red Wire
Trig – Orange Wire
Echo – Blue Wire
Gnd – Black Wire
9
Confidential and proprietary property of TinkRworks, Inc.
Connect Wires to PCB
10
Red Wire – 5V
Orange Wire – D12
Blue Wire – D11
Black Wire – GND
Confidential and proprietary property of TinkRworks, Inc.
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.
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.
Video
13
Confidential and proprietary property of TinkRworks, Inc.
14
Confidential and proprietary property of TinkRworks, Inc.
It’s Time to Code!
15
Confidential and proprietary property of TinkRworks, LLC
Open Your Program
Open your program.
16
Confidential and proprietary property of TinkRworks, LLC
Connect to Bluetooth
17
Confidential and proprietary property of TinkRworks, LLC
Sensor Setup
18
Confidential and proprietary property of TinkRworks, Inc.
Ultrasonic Distance
19
Confidential and proprietary property of TinkRworks, Inc.
Print the Distance
20
throw this away
Confidential and proprietary property of TinkRworks, Inc.
Sensor Data
21
Confidential and proprietary property of TinkRworks, Inc.
Where the Sensor Fails
22
Confidential and proprietary property of TinkRworks, Inc.
Making decisions
23
Confidential and proprietary property of TinkRworks, Inc.
Conditionals
24
Confidential and proprietary property of TinkRworks, Inc.
Making decisions
This section is the conditional (If/Then/Else statement)
25
Confidential and proprietary property of TinkRworks, Inc.
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.
Combining conditionals
27
Putting one conditional in another is called “nesting”
Confidential and proprietary property of TinkRworks, Inc.
How would this look in TinkRcode?
Algorithm
TinkRcode
28
Confidential and proprietary property of TinkRworks, Inc.
Else If
Two If/Else statements
Else if
29
Confidential and proprietary property of TinkRworks, Inc.
Planning the Conditional
What do we want OUR conditionals to be?
30
Test:
Then:
Else:
Confidential and proprietary property of TinkRworks, Inc.
Build the Test
31
Test:
10
Confidential and proprietary property of TinkRworks, Inc.
Put it together
What does this code do?
How will the bot behave?
32
Confidential and proprietary property of TinkRworks, Inc.
33
Confidential and proprietary property of TinkRworks, Inc.
Challenge #1: Avoid It
Challenge Name
Avoid It
Challenge Objective
Challenge Notes
34
Confidential and proprietary property of TinkRworks, Inc.
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
35
Confidential and proprietary property of TinkRworks, Inc.
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.
Wall Following Demo
37
Confidential and proprietary property of TinkRworks, Inc.
Wall Following Parameters
Parameters:
38
Confidential and proprietary property of TinkRworks, Inc.
39
Confidential and proprietary property of TinkRworks, Inc.
Challenge #1 Solution: Avoid It
40
Confidential and proprietary property of TinkRworks, Inc.
Challenge #2 Solution: I’m not touching you
41
Confidential and proprietary property of TinkRworks, Inc.
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.
Challenge #3 Solution: Wall Following Loop
43
Confidential and proprietary property of TinkRworks, Inc.
Wall Following using a Variable
44
Confidential and proprietary property of TinkRworks, Inc.
Challenge #3 Tip: Print out distance
45
Confidential and proprietary property of TinkRworks, Inc.
Challenge #3 Tip: Add Lights
46
Confidential and proprietary property of TinkRworks, Inc.
Wall Following Slowdown
47
Confidential and proprietary property of TinkRworks, Inc.
Subroutine
48
Confidential and proprietary property of TinkRworks, Inc.
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.