Microduino MIXC104E KIT-mCookie-Education User Manual MIX4 Book 02202018 SS indd

Microduino Inc. KIT-mCookie-Education MIX4 Book 02202018 SS indd

Contents

User manual Part 2

Download: Microduino MIXC104E KIT-mCookie-Education User Manual MIX4 Book   02202018 SS indd
Mirror Download [FCC.gov]Microduino MIXC104E KIT-mCookie-Education User Manual MIX4 Book   02202018 SS indd
Document ID3971237
Application IDTjhTE6XdM8UwLx2uqIJSJQ==
Document DescriptionUser manual Part 2
Short Term ConfidentialNo
Permanent ConfidentialNo
SupercedeNo
Document TypeUser Manual
Display FormatAdobe Acrobat PDF - pdf
Filesize499.1kB (6238741 bits)
Date Submitted2018-08-21 00:00:00
Date Available2018-08-21 00:00:00
Creation Date2018-02-20 15:53:03
Producing Softwareilovepdf.com
Document Lastmod2018-08-07 11:49:46
Document TitleMIX4 Book - 02202018 SS.indd
Document CreatorAdobe InDesign CC 13.0 (Windows)

Project Worksheet
Complete the worksheet below to your best abilities.
1. A solution.
Use two Motors to move the car. Use the Joystick to receive input from the user to go straight, turn left or right.
Adjust the speed of the Motors accordingly.
2. List all the parts needed for the solution. What is the purpose of each part?
3. What is a simple explanation of the logic for the solution?
4. Create a flow chart of the solution.
5. How do you assemble and connect the modules for the solution?
6. Configure blocks to relate to the flow chart.
156
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part?
1x
mCenter+ - control the project, connect sensors and trinkets to project, and supply power.
1x
USB Cable - connect mCenter+ to a computer for charging and programming the project.
1x
Hub Connector Cable - connect sensors and trinkets to the mCenter+.
1x
Motor Controller - controls and drives the attached motors.
2x
Motor - to move the RC car.
2x
Wheel - attach to motor.
1x
Joystick - to the direction of the RC car.
157
Project Worksheet - Answers
3. What is a simple explanation of the logic for the solution?
Use two Motors to move the RC car.
Use the Joystick to input the direction to move the car (left, right, up, down).
Depending on the Joystick’s direction being held down:
• Up - move car forward (both motors rotating forward).
• Down - move car backward (both motors rotating backwards).
• Left - move car left (motor 1 rotating forward slowly, motor 2 rotating forward fast).
• Right - move car right (motor 1 rotating forward fast, motor 2 rotating forward slowly).
• None - stop car (both motors turned off).
For Left and Right directions, the difference in motor speeds causes the car to turn.
Turning Left
Forward
Turning Right
158
Project Worksheet - Answers
4. Create a flow chart of the solution.
Start
Set variable for motor speed
Is Joystick "Up"
being pressed?
True
Set motors to move
RC car forward
True
Set motors to move
RC car backward
False
Is Joystick "Down"
being pressed?
False
Loop
forever.
Is Joystick "Left"
being pressed?
True
Set motors to turn
RC car left
False
Is Joystick "Right"
being pressed?
True
Set motors to turn
RC car right
False
Set motors to off
(stop RC car)
Short delay
159
Project Worksheet - Answers
5. How do you assemble and connect the modules for the solution?
1.
2.
3.
4.
5.
D2/D3
D6/D7
D4/D5
D8/D9
I2C
A6/A7
I2C
A2/A3
I2C
A0/A1
Stack the Motor Controller onto mCenter+.
Connect a Motor to connector “1A1B” on the Motor Controller.
Connect a Motor to connector “2A2B” on the Motor Controller.
Connect the Joystick to pin A0/A1.
Insert one end of the USB cable into mCenter+ and connect the other to a computer.
160
Project Worksheet - Answers
6. Configure blocks to relate to the flow chart.
Start
Set variable for motor speed
Is Joystick "Up"
being pressed?
True
Set motors to move
RC car forward
True
Set motors to move
RC car backward
False
Is Joystick "Down"
being pressed?
False
Loop
forever.
Is Joystick "Left"
being pressed?
True
Set motors to turn
RC car left
False
Is Joystick "Right"
being pressed?
True
Set motors to turn
RC car right
False
Set motors to off
(stop RC car)
Short delay
161
The Script
Click Green Flag to activate script.
Set the variable for the speed of the motors.
(Create “motor_speed” variable
first in the variable tab.)
Block Locator
Events
Control
Check if the Joystick (pin A0) “Up” key is being pressed.
Set motors to move car forward.
Check if the Joystick (pin A0) “Down” key is being pressed.
Operators
Set motors to move car backward.
Check if the Joystick (pin A0) “Left” key is being pressed.
Set motors to turn car left.
Data
mCookie
Check if the Joystick (pin A0) “Right” key is being pressed.
Set motors to turn car right.
Otherwise (no key being pressed), turn motors off.
Short delay before looping.
Loop.
162
Testing the Program
Important:
• Ensure that mCenter+ is on. Flip the switch on mCenter+
to turn it on. An LED on mCenter+ will light up to indicate
power is being supplied.
• Ensure you have selected the Serial Port and flashed the
special firmware (mCookie) first before testing (this only
needs to be done once unless the firmware is overwritten).
• Ensure you have selected the Serial Port and connected
before testing.
Select Serial Port
Flash firmware
Testing:
Click the green
flag to activate
the script.
1. Press and hold the Joystick in the Up,
Down, Left or Right position.
2. The Motors will turn accordingly to move
the RC car.
Note: If the program is working correctly and you wish to use the program without being connected to your computer. Switch to Arduino mode
(top right), then “Flash Program” (this overrides the special firmware, you will need to reflash to use Live mode).
163
Create a Structure
Create a structure for the project using building blocks, paper, or other crafting materials.
164
Project Challenge
How can you modify the speed in which the car moves?
Adjust the turning radius (quicker turning).
Add another Joystick input (“Center” pressing).
Make this input to cause the car to spin (motor 1 forward, motor 2 backward).
165
Review
Motor Controller - controls and drives attached motors. Can control up to 2 motors.
Motor - converts electrical energy into mechanical energy in the form of torque.
Wheel - attaches to the Motor.
Motor - Set Speed block - set the speed of a motor.
Joystick - input module (sensor) which can detect the position of the stick (up, down, left, right,
center (press)).
Joystick State block - returns TRUE if the position of the stick state matches the checking state.
Otherwise returns FALSE.
166
Expanding the Project
Write down a way of expanding this project. Create it on your own.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Research
Research more about the history of RC cars. Besides being controllable directly by a wired
Joystick, what other methods are used to control RC cars?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
167
Safety Car
MIX 4 - Project 7
(Old Cards: MIX4B-02)
168
About Collision Avoidance
A collision avoidance system is an automobile safety system designed to reduce the severity of a collision.
It is also known as a precrash system, forward collision warning system, or collision mitigating system. It
uses radar (all-weather) and sometimes laser (LIDAR) and camera (employing image recognition) to detect an imminent crash. GPS sensors can detect fixed dangers such as approaching stop signs through a
location database.
Once the detection is done, these systems either provide a warning to the driver when there is an imminent collision or take action autonomously without any driver input (by braking or steering or both).
Collision avoidance by braking is appropriate at low vehicle speeds (e.g. below 50 km/h), while collision
avoidance by steering is appropriate at higher vehicle speeds. Cars with collision avoidance may also be
equipped with adaptive cruise control, and use the same forward-looking sensors.
Source: https://en.wikipedia.org/wiki/Collision_avoidance_system
169
Review of Modules
Line Finder
Usage
The Line Finder module is able to detect reflectivity or gray level of a surface. In general, darker or less reflective surfaces produces a higher value. While a lighter or more
reflective surface produces a lower value. It must be connected to a pin with an
“A” prefix (A0/A1, A2/A3, A6/A7).
Surface Reflectivity
Lighter,
more reflective surfaces.
Analog Read block
Darker,
less reflective surfaces.
Value Returned
1023
This block returns the value that the Line Finder detects. A value between 0 and 1023 is
returned.
Pin that Line Finder
is connected to.
170
Review of Modules
Motor
A Motor is a electrical machine which converts electrical energy to mechanical energy. It
is capable of rotating clockwise and counter clockwise. It is controlled by a Motor Controller. A Motor Controller can control up to two Motors. A Wheel can be attached to the
Motor.
Motor Controller
Motor - Set Speed block
Motor to configure.
Motor - Brake block
Speed to set.
Wheel
This block sets the speed of the motor. Positive values turns the Motor in one direction. While negative values turns the Motor in the opposite direction. A value of 0
stops the Motor. Values between -255 and 255 are accepted. 255 is maximum clockwise speed. -255 is maximum counter-clockwise speed.
This block sets the speed to 0 to stop the Motor.
Motor to configure.
171
Review of Blocks
Addition Block
This block returns the sum of the left input and right input.
Subtraction Block
This block returns the value of subtracting the left input by the right input.
Multiplication Block
This block returns the product of the left input and right input.
Division Block
This block returns the value of dividing the left input by the right input.
Less Than Block
This block returns TRUE if the left input is less than the right input.
Equal Block
This block returns TRUE if the left input is equal to the right input.
Greater Than Block
This block returns TRUE if the left input is greater than the right input.
172
Review of Concepts
Creating a Variable in Scratch
Click on the “Variable” category.
Then click on the “Create variable...” button.
Name your variable.
173
Review of Concepts
Creating a Variable in Scratch (continued)
Several new blocks will appear which allows
access and modification of the new variable.
Variable Value block
This block returns the current value of the variable.
Variable Set block
This block sets the value of the variable. It will overwrite the current value.
Variable Change block
This block changes the variable value by adding the input value (negative values or blocks are accepted).
input value
174
The Problem
How can we create an autonomous car which moves forward until it reaches an
object, then moves backwards until it reaches an object, then repeats?
175
Project Worksheet
Complete the worksheet below to your best abilities.
1. A solution.
Use two Line Finders to detect obstacles (objects) in the front and back of the car. Use two motors to move the
car.
2. List all the parts needed for the solution. What is the purpose of each part?
3. What is a simple explanation of the logic for the solution?
4. Create a flow chart of the solution.
5. How do you assemble and connect the modules for the solution?
6. Configure blocks to relate to the flow chart.
176
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part?
1x
mCenter+ - control the project, connect sensors and trinkets to project, and supply power.
1x
USB Cable - connect mCenter+ to a computer for charging and programming the project.
2x
Hub Connector Cable - connect sensors and trinkets to the mCenter+.
1x
Motor Controller - controls and drives the attached motors.
2x
Motor - to move the RC car.
2x
Wheel - attach to motor.
2x
Line Finder - detect objects in the front and back of the car.
177
Project Worksheet - Answers
3. What is a simple explanation of the logic for the solution?
Use two Motors to move the RC car.
Use two Line Finders (one in front, one in back) to detect objects in the way.
Move forward until an object is detected (Line Finder in front value < 700).
Move backward until an object is detected (Line Finder in back value < 700).
Repeat.
178
Project Worksheet - Answers
4. Create a flow chart of the solution.
Start
Set variable for motor speed
Line Finder (front)
doesn’t detect an object
True
Set motors to move
RC car forward
Short delay
True
Set motors to move
RC car backward
Short delay
False
Loop
forever.
Line Finder (back)
doesn’t detect an object
False
Short delay
179
Project Worksheet - Answers
5. How do you assemble and connect the modules for the solution?
1.
2.
3.
4.
5.
6.
D2/D3
D6/D7
D4/D5
D8/D9
I2C
A6/A7
I2C
A2/A3
I2C
A0/A1
Stack the Motor Controller onto mCenter+.
Connect a Motor to connector “1A1B” on the Motor Controller.
Connect a Motor to connector “2A2B” on the Motor Controller.
Connect a Line Finder to pin A0/A1.
Connect a Line Finder to pin A2/A3.
Insert one end of the USB cable into mCenter+ and connect the other to a computer.
180
Project Worksheet - Answers
6. Configure blocks to relate to the flow chart.
Start
Set variable for motor speed
Line Finder (front)
doesn’t detect an object
True
Set motors to move
RC car forward
Short delay
True
Set motors to move
RC car backward
Short delay
False
Loop
forever.
Line Finder (back)
doesn’t detect an object
False
Short delay
181
The Script
Block Locator
Click Green Flag to activate script.
(Create “motor_speed” variable
first in the variable tab.)
Events
Control
Set the variable for the speed of the motors.
Repeat until Line Finder (A0)
in front detects an object.
Operators
Set motors to move car forward.
Short delay before looping.
Repeat until Line Finder (A2)
in back detects an object.
Set motors to move car backward.
Arduino
Data
mCookie
Short delay before looping.
Short delay before looping.
Loop.
182
Testing the Program
Important:
• Ensure that mCenter+ is on. Flip the switch on mCenter+
to turn it on. An LED on mCenter+ will light up to indicate
power is being supplied.
• Ensure you have selected the Serial Port and flashed the
special firmware (mCookie) first before testing (this only
needs to be done once unless the firmware is overwritten).
• Ensure you have selected the Serial Port and connected
before testing.
Select Serial Port
Flash firmware
Testing:
Click the green
flag to activate
the script.
1. The car will move forward until the Line Finder (front) detects an object.
2. The car will then move backward until the Line Finder (back) detects an object.
3. Repeat.
Note: If the program is working correctly and you wish to use the program without being connected to your computer. Switch to Arduino mode
(top right), then “Flash Program” (this overrides the special firmware, you will need to reflash to use Live mode).
183
Create a Structure
Create a structure for the project using building blocks, paper, or other crafting materials.
184
Project Challenge
Modify the script to use “If Else” blocks instead of “Repeat Until” blocks.
Add a third condition check to stop the car if both Line Finders detect an object.
185
Review
Motor Controller - controls and drives attached motors. Can control up to 2 motors.
Motor - converts electrical energy into mechanical energy in the form of torque.
Wheel - attaches to the Motor.
Motor - Set Speed block - set the speed of a motor.
Line Finder - detects the reflective surface or distance of an object.
Analog Read block - returns the value of the reflective surface from the Line Finder sensor.
186
Expanding the Project
Write down a way of expanding this project. Create it on your own.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Research
Research more about obstacle avoidance systems in cars.
What are some interesting techniques that are used in these systems?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
187
Delivery Truck
MIX 4 - Project 8
(Old Cards: MIX4B-03)
188
About Deliveries
Delivery is the process of transporting goods from a source location to a predefined destination. There are
different delivery types. Cargo (physical goods) are primarily delivered via roads and railroads on land,
shipping lanes on the sea and airline networks in the air. Certain specialized goods may be delivered via
other networks, such as pipelines for liquid goods, power grids for electrical power and computer networks such as the Internet or broadcast networks for electronic information.
The general process of delivering goods is known as distribution. The study of effective processes for
delivery and disposition of goods and personnel is called logistics. Firms that specialize in delivering commercial goods from point of production or storage to point of sale are generally known as distributors,
while those that specialize in the delivery of goods to the consumer are known as delivery services. Postal, courier, and relocation services also deliver goods for commercial and private interests.
Source: https://en.wikipedia.org/wiki/Delivery_(commerce)
189
Review of Modules
Line Finder
Usage
The Line Finder module is able to detect reflectivity or gray level of a surface. In general, darker or less reflective surfaces produces a higher value. While a lighter or more
reflective surface produces a lower value. It must be connected to a pin with an
“A” prefix (A0/A1, A2/A3, A6/A7).
Surface Reflectivity
Lighter,
more reflective surfaces.
Analog Read block
Darker,
less reflective surfaces.
Value Returned
1023
This block returns the value that the Line Finder detects. A value between 0 and 1023 is
returned.
Pin that Line Finder
is connected to.
190
Review of Modules
Potentiometer
A Potentiometer is a input module which can be turned or rotated right or left. Based
on the position of the knob, it produces a different signal value for the Core module to
read. It must be connected to an analog port (ports denoted with “A”).
Analog Read block
This block returns the value from the Potentiometer. A value between 0 and 1023 is returned.
If the potentiometer is turned all the way to the left, it produces a 0 value. If it is turned all
the way tot the right, it produces a 1023 value. In the middle it produces a value around 512.
Pin the Potentiometer
is connected to.
1023
191
Review of Modules
Motor
A Motor is a electrical machine which converts electrical energy to mechanical energy. It
is capable of rotating clockwise and counter clockwise. It is controlled by a Motor Controller. A Motor Controller can control up to two Motors. A Wheel can be attached to the
Motor.
Motor Controller
Motor - Set Speed block
Motor to configure.
Motor - Brake block
Speed to set.
Wheel
This block sets the speed of the motor. Positive values turns the Motor in one direction. While negative values turns the Motor in the opposite direction. A value of 0
stops the Motor. Values between -255 and 255 are accepted. 255 is maximum clockwise speed. -255 is maximum counter-clockwise speed.
This block sets the speed to 0 to stop the Motor.
Motor to configure.
192
Review of Blocks
Addition Block
This block returns the sum of the left input and right input.
Subtraction Block
This block returns the value of subtracting the left input by the right input.
Multiplication Block
This block returns the product of the left input and right input.
Division Block
This block returns the value of dividing the left input by the right input.
Less Than Block
This block returns TRUE if the left input is less than the right input.
Equal Block
This block returns TRUE if the left input is equal to the right input.
Greater Than Block
This block returns TRUE if the left input is greater than the right input.
193
Review of Concepts
Creating a Variable in Scratch
Click on the “Variable” category.
Then click on the “Create variable...” button.
Name your variable.
194
Review of Concepts
Creating a Variable in Scratch (continued)
Several new blocks will appear which allows
access and modification of the new variable.
Variable Value block
This block returns the current value of the variable.
Variable Set block
This block sets the value of the variable. It will overwrite the current value.
Variable Change block
This block changes the variable value by adding the input value (negative values or blocks are accepted).
input value
195
The Problem
How can we create a delivery truck with adjustable speeds?
Which waits for something to be loaded, then drives it to the destination, waits for
it to be unloaded, then drives back.
196
Project Worksheet
Complete the worksheet below to your best abilities.
1. A solution.
Use two motors to move the delivery truck. Use a Line Finder to detect if cargo is present or not. Use a Line
Finder (front) to check if the destination is reached. Use a Line Finder (back) to check if returned back to base.
Use a Potentiometer to adjust the speed of the truck.
2. List all the parts needed for the solution. What is the purpose of each part?
3. What is a simple explanation of the logic for the solution?
4. Create a flow chart of the solution.
5. How do you assemble and connect the modules for the solution?
6. Configure blocks to relate to the flow chart.
197
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part?
1x
mCenter+ - control the project, connect sensors and trinkets to project, and supply power.
1x
USB Cable - connect mCenter+ to a computer for charging and programming the project.
5x
Hub Connector Cable - connect sensors and trinkets to the mCenter+.
1x
Motor Controller - controls and drives the attached motors.
2x
Motor - to move the delivery truck.
2x
Wheel - attach to motor.
3x
Line Finder - detect objects in the front and back of the car and if cargo is present.
1x
Potentiometer - to adjust speed of the truck.
1x
IO Splitter - to connect two sensors/trinkets to a single connector.
198
Project Worksheet - Answers
3. What is a simple explanation of the logic for the solution?
Use
Use
Use
Use
Use
two Motors to move the delivery truck.
a Line Finder in the cargo holding location to detect if cargo is loaded or unloaded.
a Line Finder in the front to detect if the destination has been reached.
a Line Finder in the back to detect if returned to base.
a Potentiometer to adjust the speed of the delivery truck.
Wait until cargo is loaded onto truck (Line Finder in cargo holding < 200).
Wait 1 second before driving to destination.
Move forward* until destination is reached (Line Finder in front < 700).
Wait until cargo is unloaded from truck (Line Finder in cargo holding > 400).
Wait 1 second before driving back to base.
Move backward* until back to base (Line Finder in back < 700).
*When setting the speed to move forward or backward, read the Potentiometer (value between 0 and 1023) first,
then scale (divide by 4, 1023/4 =~ 255) and use that as the speed.
199
Project Worksheet - Answers
4. Create a flow chart of the solution.
Start
Set variable for motor speed
Set motors to off
(stop the truck)
Wait until cargo is loaded
Short delay before
driving to destination
Read and store Potentiometer
and scale it for motor speed
Loop
forever.
Set motors to move
truck forward
Wait until truck has
reach its destination
Set motors to off
(stop the truck)
Wait until cargo is unloaded
Short delay before
driving back to base
Set motors to move
truck backward
Wait until truck has
reach back to base
200
Project Worksheet - Answers
5. How do you assemble and connect the modules for the solution?
D2/D3
D6/D7
D4/D5
D8/D9
I2C
A6/A7
I2C
A2/A3
I2C
A0/A1
IN
1.
2.
3.
4.
5.
6.
7.
Stack the Motor Controller onto mCenter+.
Connect a Motor to connector “1A1B” on the Motor Controller.
Connect a Motor to connector “2A2B” on the Motor Controller.
Connect a Line Finder to pin A2/A3.
Connect a Potentiometer to pin A6/A7
Connect two Line Finders to an IO Splitter. Connect the IO Splitter to pin A0/A1.
Insert one end of the USB cable into mCenter+ and connect the other to a computer.
201
Project Worksheet - Answers
6. Configure blocks to relate to the flow chart.
Start
Set variable for motor speed
Set motors to off
(stop the truck)
Wait until cargo is loaded
Short delay before
driving to destination
Read and store Potentiometer
and scale it for motor speed
Loop
forever.
Set motors to move
truck forward
Wait until truck has
reach its destination
Set motors to off
(stop the truck)
Wait until cargo is unloaded
Short delay before
driving back to base
Set motors to move
truck backward
Wait until truck has
reach back to base
202
The Script
Click Green Flag to activate script.
Set the variable for the speed of the motors.
(Create “motor_speed” variable
first in the variable tab.)
Block Locator
Events
Control
Turn motors off (stop the truck).
Wait until Line Finder (A0) detects cargo (loaded).
Wait 1 second before driving to destination.
Operators
Scale and store Potentiometer (pin A6) value to motor speed.
Set motors to move truck forward.
Arduino
Wait until Line Finder (A1) in front detects reaching destination.
Turn motors off (stop the truck).
Wait until Line Finder (A0) detects no cargo (unloaded).
Wait 1 second before driving back to base.
Data
mCookie
Scale and store Potentiometer (pin A6) value to motor speed.
Set motors to move truck backward.
Wait until Line Finder (A2) in back detects returning to base.
Loop.
203
Testing the Program
Important:
• Ensure that mCenter+ is on. Flip the switch on mCenter+
to turn it on. An LED on mCenter+ will light up to indicate
power is being supplied.
• Ensure you have selected the Serial Port and flashed the
special firmware (mCookie) first before testing (this only
needs to be done once unless the firmware is overwritten).
• Ensure you have selected the Serial Port and connected
before testing.
Testing:
Click the green
flag to activate
the script.
Select Serial Port
Flash firmware
Line Finder (pin A0)
1. Load cargo into the truck.
2. The truck will then move forward until it research its
destination (object blocking its path in the front).
3. Truck will stop and wait until cargo is unloaded.
4. The truck will then move backward until it research
its base (object blocking its path in the back).
Line Finder (pin A2)
Line Finder (pin A1)
Note: If the program is working correctly and you wish to use the program without being connected to your computer. Switch to Arduino mode
(top right), then “Flash Program” (this overrides the special firmware, you will need to reflash to use Live mode).
204
Create a Structure
Create a structure for the project using building blocks, paper, or other crafting materials.
205
Project Challenge
Add a Color LED to your project.
Turn set the Color LED’s based on the state the delivery truck.
(Examples: loaded cargo, stopped, moving, unloaded cargo.)
206
Review
Motor Controller - controls and drives attached motors. Can control up to 2 motors.
Motor - converts electrical energy into mechanical energy in the form of torque.
Wheel - attaches to the Motor.
Motor - Set Speed block - set the speed of a motor.
Line Finder - detects the reflective surface or distance of an object.
Analog Read block - returns the value of the reflective surface from the Line Finder sensor.
Potentiometer - input module with an adjustable knob.
Analog Read block - reads the value from the potentiometer. Returns a value between 0 and
1023.
207
Expanding the Project
Write down a way of expanding this project. Create it on your own.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Research
Research more about delivery trucks.
What are some important things delivery trucks must accomplish to be profitable?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
208
Obstacle Avoidance Car
MIX 4 - Project 9
(Old Cards: MIX4B-04)
209
About Obstacle Avoidance
In robotics, obstacle avoidance is the task of satisfying some control objective subject to non-intersection
or non-collision position constraints.
What is critical about obstacle avoidance concept in this area is the growing need of usage of unmanned
aerial vehicles in urban areas for especially military applications where it can be very useful in city wars.
Normally obstacle avoidance is considered to be distinct from path planning in that one is usually implemented as a reactive control law while the other involves the pre-computation of an obstacle-free path
which a controller will then guide a robot along.
Source: https://en.wikipedia.org/wiki/Obstacle_avoidance
210
Review of Modules
Line Finder
Usage
The Line Finder module is able to detect reflectivity or gray level of a surface. In general, darker or less reflective surfaces produces a higher value. While a lighter or more
reflective surface produces a lower value. It must be connected to a pin with an
“A” prefix (A0/A1, A2/A3, A6/A7).
Surface Reflectivity
Lighter,
more reflective surfaces.
Analog Read block
Darker,
less reflective surfaces.
Value Returned
1023
This block returns the value that the Line Finder detects. A value between 0 and 1023 is
returned.
Pin that Line Finder
is connected to.
211
Review of Modules
Potentiometer
A Potentiometer is a input module which can be turned or rotated right or left. Based
on the position of the knob, it produces a different signal value for the Core module to
read. It must be connected to an analog port (ports denoted with “A”).
Analog Read block
This block returns the value from the Potentiometer. A value between 0 and 1023 is returned.
If the potentiometer is turned all the way to the left, it produces a 0 value. If it is turned all
the way tot the right, it produces a 1023 value. In the middle it produces a value around 512.
Pin the Potentiometer
is connected to.
1023
212
Review of Modules
Motor
A Motor is a electrical machine which converts electrical energy to mechanical energy. It
is capable of rotating clockwise and counter clockwise. It is controlled by a Motor Controller. A Motor Controller can control up to 2 Motors. A Wheel can be attached to the
Motor.
Motor Controller
Motor - Set Speed block
Motor to configure.
Motor - Brake block
Speed to set.
Wheel
This block sets the speed of the motor. Positive values turns the Motor in one direction. While negative values turns the Motor in the opposite direction. A value of 0
stops the Motor. Values between -255 and 255 are accepted. 255 is maximum clockwise speed. -255 is maximum counter-clockwise speed.
This block sets the speed to 0 to stop the Motor.
Motor to configure.
213
Review of Blocks
Addition Block
This block returns the sum of the left input and right input.
Subtraction Block
This block returns the value of subtracting the left input by the right input.
Multiplication Block
This block returns the product of the left input and right input.
Division Block
This block returns the value of dividing the left input by the right input.
Less Than Block
This block returns TRUE if the left input is less than the right input.
Equal Block
This block returns TRUE if the left input is equal to the right input.
Greater Than Block
This block returns TRUE if the left input is greater than the right input.
214
Review of Concepts
Creating a Variable in Scratch
Click on the “Variable” category.
Then click on the “Create variable...” button.
Name your variable.
215
Review of Concepts
Creating a Variable in Scratch (continued)
Several new blocks will appear which allows
access and modification of the new variable.
Variable Value block
This block returns the current value of the variable.
Variable Set block
This block sets the value of the variable. It will overwrite the current value.
Variable Change block
This block changes the variable value by adding the input value (negative values or blocks are accepted).
input value
216
The Problem
How can we create a car which can detect and avoid objects in the way?
217
Project Worksheet
Complete the worksheet below to your best abilities.
1. A solution.
Use two motors to move the car. Use 4 Line Finder positioned in front of the car to detect oncoming objects.
Use this information to steer the car away to avoid the object. Use a Potentiometer to set the motor speeds.
2. List all the parts needed for the solution. What is the purpose of each part?
3. What is a simple explanation of the logic for the solution?
4. Create a flow chart of the solution.
5. How do you assemble and connect the modules for the solution?
6. Configure blocks to relate to the flow chart.
218
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part?
1x
mCenter+ - control the project, connect sensors and trinkets to project, and supply power.
1x
USB Cable - connect mCenter+ to a computer for charging and programming the project.
7x
Hub Connector Cable - connect sensors and trinkets to the mCenter+.
1x
Motor Controller - controls and drives the attached motors.
2x
Motor - to move the car.
2x
Wheel - attach to motor.
4x
Line Finder - detect objects oncoming objects.
1x
Potentiometer - to adjust speed of the car.
2x
IO Splitter - to connect two sensors/trinkets to a single connector.
219
Project Worksheet - Answers
3. What is a simple explanation of the logic for the solution?
Use two Motors to move the car.
Use 4 Line Finders placed in front of the car to detect oncoming objects.
Use a Potentiometer to set the speed of the car.
S0 S1 S2 S3
S0 S1 S2 S3
S0 S1 S2 S3
S0, S1, S2, S3 are the 4 Line Finders placed in front of the car.
If S0 detects an object, steer to the right.
Else if S1 detects an object, steer to the right.
Else if S2 detects an object, steer to the left.
Else if S3 detects an object, steer to the left.
Else no objects are detected, go forward.
220
Project Worksheet - Answers
4. Create a flow chart of the solution.
Start
Read and store Potentiometer
and scale it for motor speed
Read and store Line Finder
values
Is there an object detected on
the left most side (S0)?
True
Set motors to
turn car right
True
Set motors to
turn car right
True
Set motors to
turn car left
True
Set motors to
turn car left
False
Is there an object detected on
the left middle side (S1)?
Loop
forever.
False
Is there an object detected on
the right middle side (S2)?
False
Is there an object detected on
the right most side (S3)?
False
Otherwise there is no obstacle,
set motors to go forward
Short delay
221
Project Worksheet - Answers
5. How do you assemble and connect the modules for the solution?
D4/D5
D8/D9
I2C
A6/A7
I2C
A2/A3
I2C
A0/A1
D6/D7
IN
D2/D3
IN
1.
2.
3.
4.
5.
6.
7.
Stack the Motor Controller onto mCenter+.
Connect a Motor to connector “1A1B” on the Motor Controller.
Connect a Motor to connector “2A2B” on the Motor Controller.
Connect a Potentiometer to pin A6/A7
Connect two Line Finders to an IO Splitter. Connect the IO Splitter to pin A0/A1.
Connect two Line Finders to an IO Splitter. Connect the IO Splitter to pin A2/A3.
Insert one end of the USB cable into mCenter+ and connect the other to a computer.
222
Project Worksheet - Answers
6. Configure blocks to relate to the flow chart.
Start
Read and store Potentiometer
and scale it for motor speed
Read and store Line Finder
values
Is there an object detected on
the left most side (S0)?
True
Set motors to
turn car right
True
Set motors to
turn car right
True
Set motors to
turn car left
True
Set motors to
turn car left
False
Is there an object detected on
the left middle side (S1)?
Loop
forever.
False
Is there an object detected on
the right middle side (S2)?
False
Is there an object detected on
the right most side (S3)?
False
Otherwise there is no obstacle,
set motors to go forward
Short delay
223
The Script
Click Green Flag to activate script.
Scale and store Potentiometer (pin A6) value to motor speed.
Read and store Line Finder (pin A0) value.
Read and store Line Finder (pin A1) value.
Read and store Line Finder (pin A2) value.
Read and store Line Finder (pin A3) value.
Check if there is an oncoming object on the left most side.
Set motors to turn car right.
Block Locator
(Create these variables
first in the variable tab.)
Events
Control
Operators
Check if there is an oncoming object on the left center side.
Set motors to turn car right.
Arduino
Check if there is an oncoming object on the right center side.
Set motors to turn car left.
Check if there is an oncoming object on the right most side.
Set motors to turn car left.
Data
mCookie
Otherwise no coming objects.
Set motors to move car forward.
Short delay before looping.
Loop.
224
Testing the Program
Important:
• Ensure that mCenter+ is on. Flip the switch on mCenter+
to turn it on. An LED on mCenter+ will light up to indicate
power is being supplied.
• Ensure you have selected the Serial Port and flashed the
special firmware (mCookie) first before testing (this only
needs to be done once unless the firmware is overwritten).
• Ensure you have selected the Serial Port and connected
before testing.
Select Serial Port
Flash firmware
Testing:
Click the green
flag to activate
the script.
Car will automatically
avoid oncoming objects
by steering left or right.
Speed can be adjusted
with the Potentiometer.
S0 S1 S2 S3
Ensure Line Finders are
in the correct position.
Note: If the program is working correctly and you wish to use the program without being connected to your computer. Switch to Arduino mode
(top right), then “Flash Program” (this overrides the special firmware, you will need to reflash to use Live mode).
225
Create a Structure
Create a structure for the project using building blocks, paper, or other crafting materials.
226
Project Challenge
Adjust the script so the car turns slightly right when it detects an object on the left
most side (S0).
Adjust the script so the car turns slightly left when it detects an object on the right
most side (S3).
227
Review
Motor Controller - controls and drives attached motors. Can control up to 2 motors.
Motor - converts electrical energy into mechanical energy in the form of torque.
Wheel - attaches to the Motor.
Motor - Set Speed block - set the speed of a motor.
Line Finder - detects the reflective surface or distance of an object.
Analog Read block - returns the value of the reflective surface from the Line Finder sensor.
Potentiometer - input module with an adjustable knob.
Analog Read block - reads the value from the potentiometer. Returns a value between 0 and
1023.
228
Expanding the Project
Write down a way of expanding this project. Create it on your own.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Research
Research more about obstacle avoidance.
Why is this an important feature in safe driving cars?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
229
Edge Avoidance Car
MIX 4 - Project 10
(Old Cards: MIX4B-06)
230
About Edge Detection
If you put the a cleaning robot on a desk it won’t fall onto the ground, because
there are sensors detecting distance from the ground at the bottom of it.
Source: https://en.wikipedia.org/wiki/Obstacle_avoidance
231
Review of Modules
Line Finder
Usage
The Line Finder module is able to detect reflectivity or gray level of a surface. In general, darker or less reflective surfaces produces a higher value. While a lighter or more
reflective surface produces a lower value. It must be connected to a pin with an
“A” prefix (A0/A1, A2/A3, A6/A7).
Surface Reflectivity
Lighter,
more reflective surfaces.
Analog Read block
Darker,
less reflective surfaces.
Value Returned
1023
This block returns the value that the Line Finder detects. A value between 0 and 1023 is
returned.
Pin that Line Finder
is connected to.
232
Review of Modules
Motor
A Motor is a electrical machine which converts electrical energy to mechanical energy. It
is capable of rotating clockwise and counter clockwise. It is controlled by a Motor Controller. A Motor Controller can control up to 2 Motors. A Wheel can be attached to the
Motor.
Motor Controller
Motor - Set Speed block
Motor to configure.
Motor - Brake block
Speed to set.
Wheel
This block sets the speed of the motor. Positive values turns the Motor in one direction. While negative values turns the Motor in the opposite direction. A value of 0
stops the Motor. Values between -255 and 255 are accepted. 255 is maximum clockwise speed. -255 is maximum counter-clockwise speed.
This block sets the speed to 0 to stop the Motor.
Motor to configure.
233
Review of Blocks
Addition Block
This block returns the sum of the left input and right input.
Subtraction Block
This block returns the value of subtracting the left input by the right input.
Multiplication Block
This block returns the product of the left input and right input.
Division Block
This block returns the value of dividing the left input by the right input.
Less Than Block
This block returns TRUE if the left input is less than the right input.
Equal Block
This block returns TRUE if the left input is equal to the right input.
Greater Than Block
This block returns TRUE if the left input is greater than the right input.
234
Review of Concepts
Booleans
Booleans are a type of data, which can only either be TRUE or FALSE. Booleans are used in the condition checks
on blocks such as the “If”, “If Else”, “Wait Until” blocks.
Boolean Operators
Boolean Operators enables performing operations on boolean types. It is useful for testing multiple conditions.
Left Input
True
True
False
False
Right Input
True
False
True
False
Result
True
False
False
False
And block
Left Input
True
True
False
False
Right Input
True
False
True
False
Result
True
True
True
False
Or block
Input Result
True False
False True
This block returns TRUE, when both the inputs
are TRUE. Otherwise, it returns FALSE.
This block returns TRUE, when one of the input is
TRUE. Otherwise, it returns FALSE.
Not block
This block returns the opposite of the input. If input is TRUE, this returns FALSE. If input is FALSE,
this returns TRUE.
235
Review of Concepts
Creating a Variable in Scratch
Click on the “Variable” category.
Then click on the “Create variable...” button.
Name your variable.
236
Review of Concepts
Creating a Variable in Scratch (continued)
Several new blocks will appear which allows
access and modification of the new variable.
Variable Value block
This block returns the current value of the variable.
Variable Set block
This block sets the value of the variable. It will overwrite the current value.
Variable Change block
This block changes the variable value by adding the input value (negative values or blocks are accepted).
input value
237
The Problem
How can we create a car which detects and avoids edges (cliffs)?
238
Project Worksheet
Complete the worksheet below to your best abilities.
1. A solution.
Use two motors to move the car. Use 2 Line Finders in front of the car pointed downwards to detect if there is
an edge (cliff). Steer away if there is a cliff.
2. List all the parts needed for the solution. What is the purpose of each part?
3. What is a simple explanation of the logic for the solution?
4. Create a flow chart of the solution.
5. How do you assemble and connect the modules for the solution?
6. Configure blocks to relate to the flow chart.
239
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part?
1x
mCenter+ - control the project, connect sensors and trinkets to project, and supply power.
1x
USB Cable - connect mCenter+ to a computer for charging and programming the project.
2x
Hub Connector Cable - connect sensors and trinkets to the mCenter+.
1x
Motor Controller - controls and drives the attached motors.
2x
Motor - to move the car.
2x
Wheel - attach to motor.
2x
Line Finder - detect if there is an edge / cliff.
240
Project Worksheet - Answers
3. What is a simple explanation of the logic for the solution?
Use two Motors to move the car.
Use 2 Line Finders in front of the car pointing downwards to detect edges (cliff).
Read the left Line Finder to see if there is ground ahead (no cliff).
Read the right Line Finder to see if there is a ground ahead (no cliff).
If
If
If
If
there
there
there
there
is
is
is
is
ground in both Left and Right sides, proceed forward.
no ground on the Left and ground on the Right, turn right. (Right side is safe to drive on).
ground on the Left and no ground on the Right, turn left. (Left side is safe to drive on).
no ground in both Left and Right sides, stop car.
241
Project Worksheet - Answers
4. Create a flow chart of the solution.
Start
Set variable for motor speed
Read and store left and right
Line Finder values
Is both left and right
sides safe (no cliff)?
True
Set motors to
move car forward
False
Is only the right
side safe (no cliff)?
Loop
forever.
True
Set motors to
turn car right
False
Is only the left
side safe (no cliff)?
True
Set motors to
turn car left
False
Otherwise, unsafe
Turn off motors
(stop car)
Short delay
242
Project Worksheet - Answers
5. How do you assemble and connect the modules for the solution?
1.
2.
3.
4.
5.
6.
D2/D3
D6/D7
D4/D5
D8/D9
I2C
A6/A7
I2C
A2/A3
I2C
A0/A1
Stack the Motor Controller onto mCenter+.
Connect a Motor to connector “1A1B” on the Motor Controller.
Connect a Motor to connector “2A2B” on the Motor Controller.
Connect a Line Finder to pin A0/A1.
Connect a Line Finder to pin A2/A3.
Insert one end of the USB cable into mCenter+ and connect the other to a computer.
243
Project Worksheet - Answers
6. Configure blocks to relate to the flow chart.
Start
Set variable for motor speed
Read and store left and right
Line Finder values
Is both left and right
sides safe (no cliff)?
True
Set motors to
move car forward
False
Is only the right
side safe (no cliff)?
Loop
forever.
True
Set motors to
turn car right
False
Is only the left
side safe (no cliff)?
True
Set motors to
turn car left
False
Otherwise, unsafe
Turn off motors
(stop car)
Short delay
244
The Script
Click Green Flag to activate script.
Set the variable for the speed of the motors.
(Create these variables
first in the variable tab.)
Block Locator
Events
Control
Read and store the left Line Finder (pin A0) value.
Read and store the right Line Finder (pin A2) value.
Check if it is safe on both Left and Right sides.
Set motors to proceed forward.
Operators
Check if there is a cliff on Left side and safe on Right side.
Set motors turn right.
Check if it is safe on Left side and a cliff on Right side.
Set motors turn left.
Arduino
Data
mCookie
Otherwise both sides are unsure,
set motors to stop car.
Short delay before looping.
Loop.
245
Testing the Program
Important:
• Ensure that mCenter+ is on. Flip the switch on mCenter+
to turn it on. An LED on mCenter+ will light up to indicate
power is being supplied.
• Ensure you have selected the Serial Port and flashed the
special firmware (mCookie) first before testing (this only
needs to be done once unless the firmware is overwritten).
• Ensure you have selected the Serial Port and connected
before testing.
Testing:
Click the green
flag to activate
the script.
Select Serial Port
Flash firmware
1. The car will automatically move forward if left and right sides are safe (no cliff).
2. The car will turn right if only the right side is safe.
3. The car will turn left is only the left side is safe.
4. The car will stop if both left and right sides are unsafe (cliff).
Right Line Finder (pin A2)
Left Line Finder (pin A0)
Note: If the program is working correctly and you wish to use the program without being connected to your computer. Switch to Arduino mode
(top right), then “Flash Program” (this overrides the special firmware, you will need to reflash to use Live mode).
246
Create a Structure
Create a structure for the project using building blocks, paper, or other crafting materials.
247
Project Challenge
The car stops when the left and right sides are unsafe.
What other options can the car makes in this situation?
Implement it on your own.
248
Review
Motor Controller - controls and drives attached motors. Can control up to 2 motors.
Motor - converts electrical energy into mechanical energy in the form of torque.
Wheel - attaches to the Motor.
Motor - Set Speed block - set the speed of a motor.
Line Finder - detects the reflective surface or distance of an object.
Analog Read block - returns the value of the reflective surface from the Line Finder sensor.
249
Expanding the Project
Write down a way of expanding this project. Create it on your own.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Research
Research more about edge/cliff detection. What things implement this feature?
Why is it important for each of those things to have this feature?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
250
Line Finding Car 1
MIX 4 - Project 11
(Old Cards: MIX4B-07)
251
About Line Following Cars
Some of the earliest Automated Guided Vehicles (AGVs) were line following mobile robots. They might
follow a visual line painted or embedded in the floor or ceiling or an electrical wire in the floor.
Most of these robots operated a simple “keep the line in the center sensor” algorithm. They could not circumnavigate obstacles; they just stopped and waited when something blocked their path.
Source: https://en.wikipedia.org/wiki/Mobile_robot#Line-following_Car
252
Review of Modules
Line Finder
Usage
The Line Finder module is able to detect reflectivity or gray level of a surface. In general, darker or less reflective surfaces produces a higher value. While a lighter or more
reflective surface produces a lower value. It must be connected to a pin with an
“A” prefix (A0/A1, A2/A3, A6/A7).
Surface Reflectivity
Lighter,
more reflective surfaces.
Analog Read block
Darker,
less reflective surfaces.
Value Returned
1023
This block returns the value that the Line Finder detects. A value between 0 and 1023 is
returned.
Pin that Line Finder
is connected to.
253
Review of Modules
Motor
A Motor is a electrical machine which converts electrical energy to mechanical energy. It
is capable of rotating clockwise and counter clockwise. It is controlled by a Motor Controller. A Motor Controller can control up to 2 Motors. A Wheel can be attached to the
Motor.
Motor Controller
Motor - Set Speed block
Motor to configure.
Motor - Brake block
Speed to set.
Wheel
This block sets the speed of the motor. Positive values turns the Motor in one direction. While negative values turns the Motor in the opposite direction. A value of 0
stops the Motor. Values between -255 and 255 are accepted. 255 is maximum clockwise speed. -255 is maximum counter-clockwise speed.
This block sets the speed to 0 to stop the Motor.
Motor to configure.
254
Review of Blocks
Addition Block
This block returns the sum of the left input and right input.
Subtraction Block
This block returns the value of subtracting the left input by the right input.
Multiplication Block
This block returns the product of the left input and right input.
Division Block
This block returns the value of dividing the left input by the right input.
Less Than Block
This block returns TRUE if the left input is less than the right input.
Equal Block
This block returns TRUE if the left input is equal to the right input.
Greater Than Block
This block returns TRUE if the left input is greater than the right input.
255
Review of Concepts
Booleans
Booleans are a type of data, which can only either be TRUE or FALSE. Booleans are used in the condition checks
on blocks such as the “If”, “If Else”, “Wait Until” blocks.
Boolean Operators
Boolean Operators enables performing operations on boolean types. It is useful for testing multiple conditions.
Left Input
True
True
False
False
Right Input
True
False
True
False
Result
True
False
False
False
And block
Left Input
True
True
False
False
Right Input
True
False
True
False
Result
True
True
True
False
Or block
Input Result
True False
False True
This block returns TRUE, when both the inputs
are TRUE. Otherwise, it returns FALSE.
This block returns TRUE, when one of the input is
TRUE. Otherwise, it returns FALSE.
Not block
This block returns the opposite of the input. If input is TRUE, this returns FALSE. If input is FALSE,
this returns TRUE.
256
Review of Concepts
Creating a Variable in Scratch
Click on the “Variable” category.
Then click on the “Create variable...” button.
Name your variable.
257
Review of Concepts
Creating a Variable in Scratch (continued)
Several new blocks will appear which allows
access and modification of the new variable.
Variable Value block
This block returns the current value of the variable.
Variable Set block
This block sets the value of the variable. It will overwrite the current value.
Variable Change block
This block changes the variable value by adding the input value (negative values or blocks are accepted).
input value
258
The Problem
How can we create a car which follows a black line (track)?
259
Project Worksheet
Complete the worksheet below to your best abilities.
1. A solution.
Use two motors to move the car. Use Two Line Finders pointed downward to detect the black line. Adjust accordingly to stay on the black line.
2. List all the parts needed for the solution. What is the purpose of each part?
3. What is a simple explanation of the logic for the solution?
4. Create a flow chart of the solution.
5. How do you assemble and connect the modules for the solution?
6. Configure blocks to relate to the flow chart.
260
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part?
1x
mCenter+ - control the project, connect sensors and trinkets to project, and supply power.
1x
USB Cable - connect mCenter+ to a computer for charging and programming the project.
2x
Hub Connector Cable - connect sensors and trinkets to the mCenter+.
1x
Motor Controller - controls and drives the attached motors.
2x
Motor - to move the car.
2x
Wheel - attach to motor.
2x
Line Finder - to detect the black line.
261
Project Worksheet - Answers
3. What is a simple explanation of the logic for the solution?
Use two Motors to move the car.
Use 2 Line Finders pointed downward to detect the black line.
Left
Line Finder
Right
Line Finder
Black line
When the both Line Finders do not detect the black line, proceed forward.
When the left Line Finder detects the black line, steer left.
When the right Line Finder detects the black line, steer right.
*Note: The Line Finders must be spaced apart slightly more than the width of the black line (as illustrated).
262
Project Worksheet - Answers
4. Create a flow chart of the solution.
Start
Set variable for motor speed
Read and store if left and right
Line Finder detects a line
Is both left and right
sides not detecting a line?
True
Set motors to
move car forward
False
Is only the left
detecting a line?
Loop
forever.
True
Set motors to
turn car left
False
Is only the right
detecting a line?
True
Set motors to
turn car right
False
Otherwise, on the line
turn off motors
(stop car)
Short delay
263
Project Worksheet - Answers
5. How do you assemble and connect the modules for the solution?
1.
2.
3.
4.
5.
6.
D2/D3
D6/D7
D4/D5
D8/D9
I2C
A6/A7
I2C
A2/A3
I2C
A0/A1
Stack the Motor Controller onto mCenter+.
Connect a Motor to connector “1A1B” on the Motor Controller.
Connect a Motor to connector “2A2B” on the Motor Controller.
Connect a Line Finder to pin A0/A1.
Connect a Line Finder to pin A2/A3.
Insert one end of the USB cable into mCenter+ and connect the other to a computer.
264
Project Worksheet - Answers
6. Configure blocks to relate to the flow chart.
Start
Set variable for motor speed
Read and store if left and right
Line Finder detects a line
Is both left and right
sides not detecting a line?
True
Set motors to
move car forward
False
Is only the left
detecting a line?
Loop
forever.
True
Set motors to
turn car left
False
Is only the right
detecting a line?
True
Set motors to
turn car right
False
Otherwise, on the line
turn off motors
(stop car)
Short delay
265
The Script
Click Green Flag to activate script.
Set the variable for the speed of the motors.
Read and store Left side if detects a black line.
0 (false) = detecting line. 1 (true) = not detecting line.
Read and store Right side if detects a black line.
0 (false) = detecting line. 1 (true) = not detecting line.
Check if not detecting line on both sides.
Set motors to move car forward.
Check if detecting line on left side.
Set motors to turn car right.
Check if detecting line on right side.
Set motors to turn car left.
(Create these variables
first in the variable tab.)
Block Locator
Events
Control
Operators
Arduino
Data
mCookie
Otherwise car is on the black line,
Set motors to off (stop the car).
Short delay before looping.
Loop.
266
Testing the Program
Important:
• Ensure that mCenter+ is on. Flip the switch on mCenter+
to turn it on. An LED on mCenter+ will light up to indicate
power is being supplied.
• Ensure you have selected the Serial Port and flashed the
special firmware (mCookie) first before testing (this only
needs to be done once unless the firmware is overwritten).
• Ensure you have selected the Serial Port and connected
before testing.
Testing:
Click the green
flag to activate
the script.
Select Serial Port
Flash firmware
1. Create a straight line with black tape.
2. Make sure your Line Finders are spaced apart SLIGHTLY larger than the width of the black tape.
3. Place the car on the black tape. The car will trace the black tape.
Right Line Finder (pin A1)
Left Line Finder (pin A0)
Note: If the program is working correctly and you wish to use the program without being connected to your computer. Switch to Arduino mode
(top right), then “Flash Program” (this overrides the special firmware, you will need to reflash to use Live mode).
267
Create a Structure
Create a structure for the project using building blocks, paper, or other crafting materials.
268
Project Challenge
The car stops if it detects the line on both Line Finders (left and right).
What is another solution for this scenario?
Implement it on your own.
269
Review
Motor Controller - controls and drives attached motors. Can control up to 2 motors.
Motor - converts electrical energy into mechanical energy in the form of torque.
Wheel - attaches to the Motor.
Motor - Set Speed block - set the speed of a motor.
Line Finder - detects the reflective surface or distance of an object.
Analog Read block - returns the value of the reflective surface from the Line Finder sensor.
270
Expanding the Project
Write down a way of expanding this project. Create it on your own.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Research
Research more about Line Finding cars.
What are some other features and advancements have been added to this type of car?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
271
Line Finding Car 2
MIX 4 - Project 12
(Old Cards: MIX4B-08)
272
About Line Following Cars
Some of the earliest Automated Guided Vehicles (AGVs) were line following mobile robots. They might
follow a visual line painted or embedded in the floor or ceiling or an electrical wire in the floor.
Most of these robots operated a simple “keep the line in the center sensor” algorithm. They could not circumnavigate obstacles; they just stopped and waited when something blocked their path.
Source: https://en.wikipedia.org/wiki/Mobile_robot#Line-following_Car
273
Review of Modules
Line Finder
Usage
The Line Finder module is able to detect reflectivity or gray level of a surface. In general, darker or less reflective surfaces produces a higher value. While a lighter or more
reflective surface produces a lower value. It must be connected to a pin with an
“A” prefix (A0/A1, A2/A3, A6/A7).
Surface Reflectivity
Lighter,
more reflective surfaces.
Analog Read block
Darker,
less reflective surfaces.
Value Returned
1023
This block returns the value that the Line Finder detects. A value between 0 and 1023 is
returned.
Pin that Line Finder
is connected to.
274
Review of Modules
Potentiometer
A Potentiometer is a input module which can be turned or rotated right or left. Based
on the position of the knob, it produces a different signal value for the Core module to
read. It must be connected to an analog port (ports denoted with “A”).
Analog Read block
This block returns the value from the Potentiometer. A value between 0 and 1023 is returned.
If the potentiometer is turned all the way to the left, it produces a 0 value. If it is turned all
the way tot the right, it produces a 1023 value. In the middle it produces a value around 512.
Pin the Potentiometer
is connected to.
1023
275
Review of Modules
Motor
A Motor is a electrical machine which converts electrical energy to mechanical energy. It
is capable of rotating clockwise and counter clockwise. It is controlled by a Motor Controller. A Motor Controller can control up to 2 Motors. A Wheel can be attached to the
Motor.
Motor Controller
Motor - Set Speed block
Motor to configure.
Motor - Brake block
Speed to set.
Wheel
This block sets the speed of the motor. Positive values turns the Motor in one direction. While negative values turns the Motor in the opposite direction. A value of 0
stops the Motor. Values between -255 and 255 are accepted. 255 is maximum clockwise speed. -255 is maximum counter-clockwise speed.
This block sets the speed to 0 to stop the Motor.
Motor to configure.
276
Review of Blocks
Addition Block
This block returns the sum of the left input and right input.
Subtraction Block
This block returns the value of subtracting the left input by the right input.
Multiplication Block
This block returns the product of the left input and right input.
Division Block
This block returns the value of dividing the left input by the right input.
Less Than Block
This block returns TRUE if the left input is less than the right input.
Equal Block
This block returns TRUE if the left input is equal to the right input.
Greater Than Block
This block returns TRUE if the left input is greater than the right input.
277
Review of Concepts
Booleans
Booleans are a type of data, which can only either be TRUE or FALSE. Booleans are used in the condition checks
on blocks such as the “If”, “If Else”, “Wait Until” blocks.
Boolean Operators
Boolean Operators enables performing operations on boolean types. It is useful for testing multiple conditions.
Left Input
True
True
False
False
Right Input
True
False
True
False
Result
True
False
False
False
And block
Left Input
True
True
False
False
Right Input
True
False
True
False
Result
True
True
True
False
Or block
Input Result
True False
False True
This block returns TRUE, when both the inputs
are TRUE. Otherwise, it returns FALSE.
This block returns TRUE, when one of the input is
TRUE. Otherwise, it returns FALSE.
Not block
This block returns the opposite of the input. If input is TRUE, this returns FALSE. If input is FALSE,
this returns TRUE.
278
Review of Concepts
Creating a Variable in Scratch
Click on the “Variable” category.
Then click on the “Create variable...” button.
Name your variable.
279
Review of Concepts
Creating a Variable in Scratch (continued)
Several new blocks will appear which allows
access and modification of the new variable.
Variable Value block
This block returns the current value of the variable.
Variable Set block
This block sets the value of the variable. It will overwrite the current value.
Variable Change block
This block changes the variable value by adding the input value (negative values or blocks are accepted).
input value
280
The Problem
How can enhance the line following robot to increase its accuracy?
281
Project Worksheet
Complete the worksheet below to your best abilities.
1. A solution.
Add two additional Line Finders to increase the line detection accuracy.
2. List all the parts needed for the solution. What is the purpose of each part?
3. What is a simple explanation of the logic for the solution?
4. Create a flow chart of the solution.
5. How do you assemble and connect the modules for the solution?
6. Configure blocks to relate to the flow chart.
282
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part?
1x
mCenter+ - control the project, connect sensors and trinkets to project, and supply power.
1x
USB Cable - connect mCenter+ to a computer for charging and programming the project.
6x
Hub Connector Cable - connect sensors and trinkets to the mCenter+.
1x
Motor Controller - controls and drives the attached motors.
2x
Motor - to move the car.
2x
Wheel - attach to motor.
4x
Line Finder - to detect the black line.
1x
Potentiometer - to adjust speed of the truck.
283
Project Worksheet - Answers
2. List all the parts needed for the solution. What is the purpose of each part? (Continued)
1x
IO Splitter - to connect two sensors/trinkets to a single connector.
284
Project Worksheet - Answers
3. What is a simple explanation of the logic for the solution?
Use two Motors to move the car.
Use 4 Line Finders pointed downward to detect the black line.
Use a Potentiometer to configure the Line Finder threshold for registering a black line.
Leftmost Line Finder is labeled S0, Left middle is S1, Right middle is S2, Rightmost is S3.
A. Only Leftmost detects line - turn sharply to the left to get back on line.
B. Only Leftmost and Left middle detects line - turn slightly to left to get back on line.
C. Only Left middle and Right middle detects line - already on the line, go straight.
D. Only Right middle and Rightmost detects line - turn slightly to the right to get back on line.
E. Only Rightmost detects line - turn sharply to the right to get back on line.
285
Project Worksheet - Answers
4. Create a flow chart of the solution.
Start
Set variable for motor speed
Read and store Potentiometer
value for line threshold
Read and store if the 5
Line Finders detects a line
Is condition A present?
True
Set motors to
sharply turn left
False
Is condition B present?
True
Set motors to
slight turn left
False
Loop
forever.
Is condition C present?
True
Set motors to
move car forward
False
Is condition D present?
True
Set motors to
slight turn right
False
Is condition E present?
True
Set motors to
sharply turn right
False
Otherwise, unknown condition
turn off motors
(stop car)
Short delay
286
Project Worksheet - Answers
5. How do you assemble and connect the modules for the solution?
D4/D5
D8/D9
I2C
A6/A7
I2C
A2/A3
I2C
A0/A1
D6/D7
IN
D2/D3
IN
1.
2.
3.
4.
5.
6.
7.
Stack the Motor Controller onto mCenter+.
Connect a Motor to connector “1A1B” on the Motor Controller.
Connect a Motor to connector “2A2B” on the Motor Controller.
Connect a Potentiometer to pin A6/A7
Connect two Line Finders to an IO Splitter. Connect the IO Splitter to pin A0/A1.
Connect two Line Finders to an IO Splitter. Connect the IO Splitter to pin A2/A3.
Insert one end of the USB cable into mCenter+ and connect the other to a computer.
287
Project Worksheet - Answers
6. Configure blocks to relate to the flow chart.
Start
Set variable for motor speed
Read and store Potentiometer
value for line threshold
Read and store if the 5
Line Finders detects a line
Is condition A present?
True
Set motors to
sharply turn left
False
Is condition B present?
True
Set motors to
slight turn left
False
Loop
forever.
Is condition C present?
True
Set motors to
move car forward
False
Is condition D present?
True
Set motors to
slight turn right
False
Is condition E present?
True
Set motors to
sharply turn right
False
Otherwise, unknown condition
turn off motors
(stop car)
Short delay
288
The Script
Click Green Flag to activate script.
Set the variable for the speed of the motors.
Read and store Potentiometer (pin A6) for line threshold.
(Create these variables
first in the variable tab.)
Block Locator
Events
Control
Read and store Line Finder values.
“1” represents detecting line.
“0” represents” no line detected. Check for condition A.
Set motors to turn sharply to the left.
Operators
Check for condition B.
Set motors to turn slightly to the left.
Check for condition C.
Arduino
Set motors to move quickly forward.
Check for condition D.
Data
Set motors to turn sharply to the right.
Check for condition E.
mCookie
Set motors to turn slightly to the right.
Unknown condition,
turn motors off (stop car).
Short delay before looping.
Loop.
289
Testing the Program
Important:
• Ensure that mCenter+ is on. Flip the switch on mCenter+
to turn it on. An LED on mCenter+ will light up to indicate
power is being supplied.
• Ensure you have selected the Serial Port and flashed the
special firmware (mCookie) first before testing (this only
needs to be done once unless the firmware is overwritten).
• Ensure you have selected the Serial Port and connected
before testing.
Testing:
Click the green
flag to activate
the script.
Select Serial Port
Flash firmware
1. Create a straight line with black tape.
2. Make sure the Line Finders are side by side with the correct positions.
The two middle Line Finders should be detecting the black tape.
3. Place the car on the black tape. The car will trace the black tape.
Adjust the sensitivity of line
detection by adjusting the
Potentiometer.
Line Finder (pin A3)
Line Finder (pin A2)
Line Finder (pin A1)
Line Finder (pin A0)
Note: If the program is working correctly and you wish to use the program without being connected to your computer. Switch to Arduino mode
(top right), then “Flash Program” (this overrides the special firmware, you will need to reflash to use Live mode).
290
Create a Structure
Create a structure for the project using building blocks, paper, or other crafting materials.
291
Project Challenge
Add a Color LED to the project.
Have it indicate the current condition detected (A~E).
Modify the behavior to your liking when it reaches the unknown conditiion.
292
Review
Motor Controller - controls and drives attached motors. Can control up to 2 motors.
Motor - converts electrical energy into mechanical energy in the form of torque.
Wheel - attaches to the Motor.
Motor - Set Speed block - set the speed of a motor.
Line Finder - detects the reflective surface or distance of an object.
Analog Read block - returns the value of the reflective surface from the Line Finder sensor.
293
Expanding the Project
Write down a way of expanding this project. Create it on your own.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Research
Research new technologies for self driving vehicles.
What kind of methods are used in these self-driving cars?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
294
FCC Warning
This device complies with part 15 of the FCC Rules. Operation is subject to the following two conditions:
(1) This device may not cause harmful interference, and
(2) this device must accept any interference received, including interference that may cause undesired operation.
Any Changes or modifications not expressly approved by the party responsible for compliance could void the user's authority
to operate the equipment. This equipment has been tested and found to comply with the limits for a Class B digital device,
pursuant to part 15 of the FCC Rules. These limits are designed to provide reasonable protection against harmful interference
in a residential installation. This equipment generates uses and can radiate radio frequency energy and,
if not installed and used in accordance with the instructions, may cause harmful interference to radio communications.
However, there is no guarantee that interference will not occur in a particular installation.
If this equipment does cause harmful interference to radio or television reception, which can be determined by turning
the equipment off and on, the user is encouraged to try to correct the interference by one or more of the following measures:
-Reorient or relocate the receiving antenna.
-Increase the separation between the equipment and receiver.
-Connect the equipment into an outlet on a circuit different from that to which the receiver is connected.
-Consult the dealer or an experienced radio/TV technician for help.
The device has been evaluated to meet general RF exposure requirement.
The device can be used in portable exposure condition without restriction.
295

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.6
Linearized                      : No
Create Date                     : 2018:02:20 15:53:03-08:00
Creator                         : Adobe InDesign CC 13.0 (Windows)
GTS PDFX Version                : PDF/X-4
Modify Date                     : 2018:08:07 11:49:46+08:00
Language                        : en-US
Tagged PDF                      : Yes
XMP Toolkit                     : Adobe XMP Core 5.2-c001 63.139439, 2010/09/27-13:37:26
Creator Tool                    : Adobe InDesign CC 13.0 (Windows)
Metadata Date                   : 2018:08:07 11:49:46+08:00
Version ID                      : 1
Document ID                     : uuid:c214424a-c99a-47bb-8c38-da884e4d8bca
Instance ID                     : uuid:8b18e84b-6a26-4dfc-8c33-519e471541a5
Producer                        : ilovepdf.com
Trapped                         : False
Format                          : application/pdf
Title                           : MIX4 Book - 02202018 SS.indd
Page Count                      : 140
EXIF Metadata provided by EXIF.tools
FCC ID Filing: 2AKMKMIXC104E

Navigation menu