Infrared Sensor
SensorBot
Confidential and proprietary property of TinkRworks, Inc.
Confidential and proprietary property of TinkRworks, Inc.
1
Confidential and proprietary property of TinkRworks, Inc.
Your IR Sensor
2
Confidential and proprietary property of TinkRworks, Inc.
What is IR?
3
Confidential and proprietary property of TinkRworks, Inc.
What is IR used for?
4
Visible light
Infrared light
Confidential and proprietary property of TinkRworks, Inc.
What is IR used for?
Astronomers can use infrared filters to see through all the dust in space too!
5
Confidential and proprietary property of TinkRworks, Inc.
6
Confidential and proprietary property of TinkRworks, Inc.
Remote and Sensor
Remote Control
IR Sensor
7
The remote control connects to the IR sensor.
Infrared light
Confidential and proprietary property of TinkRworks, Inc.
Protocol
What does the remote-control protocol look like?
8
Start indicates the beginning of the transmission
The stop indicates the end of the transmission
Command
Device address (unique per TV manufacturer)
Confidential and proprietary property of TinkRworks, Inc.
IR Sensor
The IR receiver needs power and a way to communicate with the Arduino.
9
GND
5V
S
Confidential and proprietary property of TinkRworks, Inc.
10
Confidential and proprietary property of TinkRworks, Inc.
It’s Time to Code!
11
Confidential and proprietary property of TinkRworks, Inc.
Project Code
12
Confidential and proprietary property of TinkRworks, Inc.
Class Code
13
Confidential and proprietary property of TinkRworks, Inc.
Open Your Program
14
Confidential and proprietary property of TinkRworks, Inc.
Connect to Bluetooth
15
Confidential and proprietary property of TinkRworks, Inc.
Programming with the IR Sensor
16
Confidential and proprietary property of TinkRworks, Inc.
Serial Printing
17
Confidential and proprietary property of TinkRworks, Inc.
Reading the IR Sensor
Run this code and press several different buttons on the remote.
18
Confidential and proprietary property of TinkRworks, Inc.
Reading the IR Sensor
19
Confidential and proprietary property of TinkRworks, Inc.
IR Sensor Values
20
Confidential and proprietary property of TinkRworks, Inc.
Very Important!
The ir variable value is a number other than 17 ONLY when the button is first pressed.
21
Confidential and proprietary property of TinkRworks, Inc.
Ir Values
22
Confidential and proprietary property of TinkRworks, Inc.
Revise Important Statement
The ir variable value is equal to the button block only when the button is first pressed.
23
Confidential and proprietary property of TinkRworks, Inc.
24
Confidential and proprietary property of TinkRworks, Inc.
Conditionals
We want the bot to do something when we press a button.
25
Button is pressed
Do something
But we really want it to do something different when different buttons are pressed.
Confidential and proprietary property of TinkRworks, Inc.
Lots of Conditionals
What we really need to say is:
26
Confidential and proprietary property of TinkRworks, Inc.
Another type of Conditional: the Case Block
27
Confidential and proprietary property of TinkRworks, Inc.
The Case Block
The Switch block needs a variable. This variable is used to pick one of the case blocks to run.
The value in the Case block indicates that the block will run when the variable equals that value.
There can be lots of cases. Drag in as many Case blocks as you need.
The Default block is used when none of the values match.
28
Confidential and proprietary property of TinkRworks, Inc.
Programming With the IR Sensor
29
Confidential and proprietary property of TinkRworks, Inc.
Programming With the IR Sensor
30
Confidential and proprietary property of TinkRworks, Inc.
Moving Forward
Remember:
31
Confidential and proprietary property of TinkRworks, Inc.
Challenge #1: Remote Control Car
Challenge Name
Remote Control Car
Challenge Objective
Turn your robot into a remote-control car.
Challenge Notes
When you press the Up button, it should go forward. The down button should make the robot go backward and left and right should make it spin. Use the OK button to stop everything.
32
Confidential and proprietary property of TinkRworks, Inc.
Solution #1
Can put slow or fast here.
33
Confidential and proprietary property of TinkRworks, Inc.
Control Flow
34
Confidential and proprietary property of TinkRworks, Inc.
Challenge #2: Lights
Challenge Name
Lights
Challenge Objective
Add a series of lights to Case STAR of your Switch/Case block using delays.
Challenge Notes
You can create a lights subroutine, or just put them in your Case STAR.
When you have added them, try them out by pressing the * button on the remote controller.
35
Confidential and proprietary property of TinkRworks, Inc.
Solution #2
36
Confidential and proprietary property of TinkRworks, Inc.
Solution #2
37
Confidential and proprietary property of TinkRworks, Inc.
Auto Backup
38
Confidential and proprietary property of TinkRworks, Inc.
At the Same Time
39
Confidential and proprietary property of TinkRworks, Inc.
40
Confidential and proprietary property of TinkRworks, Inc.
Mode
41
Confidential and proprietary property of TinkRworks, Inc.
Mode Variable
42
Confidential and proprietary property of TinkRworks, Inc.
Mode One
43
Confidential and proprietary property of TinkRworks, Inc.
Mode One
44
Confidential and proprietary property of TinkRworks, Inc.
Mode One
45
Confidential and proprietary property of TinkRworks, Inc.
Try it
46
Confidential and proprietary property of TinkRworks, Inc.
Not Auto Backup
47
Confidential and proprietary property of TinkRworks, Inc.
Not Auto Backup
48
Confidential and proprietary property of TinkRworks, Inc.
Not Auto Backup
49
Confidential and proprietary property of TinkRworks, Inc.
Case Zero
We don’t need a conditional for mode = 0 because we are stopping the Auto Backup and not starting anything else.
50
Confidential and proprietary property of TinkRworks, Inc.
51
Confidential and proprietary property of TinkRworks, Inc.
Challenge #2: More Modes
Challenge Name
More Modes
Challenge Objective
Add the Wall Following subroutine to a mode.
Add the Not Touching You subroutine to another mode.
Add any other Subroutines that you have or want to make.
Challenge Notes
Think of bits of code that need to be looped over and over to work.
52
Confidential and proprietary property of TinkRworks, Inc.
Challenge #3: Lights for Modes
Challenge Name
Lights for Modes
Challenge Objective
Show which mode you are in by changing the bot’s lights.
Challenge Notes
What color will be Mode 0?
What color will be Mode 1?
What color will be Mode 2?
53
Confidential and proprietary property of TinkRworks, Inc.
Challenge #4: Drive With Lights
Challenge Name
Drive with Lights
Challenge Objective
Turn on some lights while you drive using a new mode.
Challenge Notes
Create a new mode to turn on the lights.
When you press the 0, stop the lights.
54
Confidential and proprietary property of TinkRworks, Inc.
55
Confidential and proprietary property of TinkRworks, Inc.
#2 Solution
56
Confidential and proprietary property of TinkRworks, Inc.
Solution#3
57
Confidential and proprietary property of TinkRworks, Inc.
Solution #4
58
Confidential and proprietary property of TinkRworks, Inc.
Extension
59
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.