0% found this document useful (0 votes)
524 views82 pages

Smart Car Kit For Arduino User Manual

arduino program

Uploaded by

SW
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
524 views82 pages

Smart Car Kit For Arduino User Manual

arduino program

Uploaded by

SW
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Preface

About SunFounder
SunFounder is a technology company focused on Raspberry Pi and Arduino open source
community development. Committed to the promotion of open source culture, we strive to
bring the fun of electronics making to people all around the world and enable everyone to
be a maker. Our products include learning kits, development boards, robots, sensor modules
and development tools. In addition to high quality products, SunFounder also offers video
tutorials to help you build your own project. If you have interest in open source or making
something cool, welcome to join us! Visit www.sunfounder.com for more!

About SunFounder Smart Car Kit for Arduino


This smart car can go straight, turn left and right, follow lines, seek light and avoid obstacles

er
and so on. It is controlled by the SunFounder Uno board.

d
This car kit is a great platform for you to get started with robotics. According to the assembly
un
guide in this manual, after assembling the car, you will learn how to operate the smart car
through 5 experiments corresponding to the aforementioned five types of movement. After
mastering every experiment, you can extend other more functions or build your own robot
o

platform based on this one.


nF

Note:
Go to LEARN->Get Tutorials->Smart Car Kit for Arduino on our website www.sunfounder.com
to view the related code and other materials. Please read this manual carefully before
Su

experiment. You are suggested to follow this guide to install the smart car model and carry
out each experiment taking the wiring steps with diagrams. Then, you may able to DIY
another car!

Free Support

If you have any TECHNICAL questions, add a topic under FORUM section on our website and
we'll reply as soon as possible.

For NON-TECH questions like order and shipment issues, please send an email to
[email protected]. You're also welcomed to share your projects on FORUM.

Rept 2.0
Contents
Components List ..........................................................................................................................1
Acrylic Plate ...........................................................................................................................1
Mechanical Fasteners..........................................................................................................2
Power Accessories ................................................................................................................3
Electronic Accessories .........................................................................................................4
Tools..........................................................................................................................................6
Self-provided Components ................................................................................................6
Introduction to Smart Car for Arduino ....................................................................................7
Get Started....................................................................................................................................8
Arduino ....................................................................................................................................8

er
Description .......................................................................................................................8
Arduino Board – SunFounder Compatible ...............................................................8
d
Install Arduino IDE ...........................................................................................................9
un
Add Libraries ....................................................................................................................9
Servo ......................................................................................................................................10
o

Servo Test........................................................................................................................11
nF

Sensor Shield.........................................................................................................................14
Motor Driver Module ..........................................................................................................16
Step-down DC-DC Converter Module ...........................................................................18
Su

Switch Module .....................................................................................................................20


Photoelectric Switch ..........................................................................................................21
Photosensitive Module .......................................................................................................22
Obstacle Avoidance Module ..........................................................................................22
Tracking Module..................................................................................................................24
Car Assembly ..............................................................................................................................26
Front Wheel ..........................................................................................................................26
Deflecting Plate + Front Wheels.......................................................................................27
Deflecting Plate + Rocker Arm.........................................................................................28
Rear Lower Plate + Rear Wheels......................................................................................29
Rear Upper Plate + Copper Standoffs ...........................................................................30
Deflecting Top Plate ...........................................................................................................31
Servo MG995 + Chassis + Battery Holder .......................................................................32
Chassis + Deflecting Plate .................................................................................................35
Chassis + Rear Upper Plate ...............................................................................................36
Assembling Electronic Shields and Modules .................................................................39
Experiments .................................................................................................................................40
Experiment 1 Going Forward and Backward ...............................................................40
Experiment 2 Turning Right and Left ...............................................................................46
Experiment 3 Line Following ..............................................................................................47
Experiment 4 Light Seeking ...............................................................................................58
Experiment 5 Obstacle Avoidance ................................................................................66

d er
o un
nF
Su
Components List

Acrylic Plate

d er
o un
nF
Su

1
Mechanical Fasteners

Accessory Name Qty.

M1.2*5 Self-tapping Screw 6

M2*10 Screw 4

M3*14 Countersunk Screw 4

M3*6 Screw 21

M3*8 Screw 40

M3*12 Screw 20

er
M3*30 Screw 6

d M4*12 Screw 8
un
M4*25 Screw 4

M3*10 Copper Standoff 16


o

M3*20 Copper Standoff 11


nF

M3*25 Copper Standoff 6


Su

M3*30 Copper Standoff 4

M4*30 Copper Standoff 4

M2 Nut 4

M3 Nut 25

M4 Nut 4

M3 Self-locking Nut 2

M4 Self-locking Nut 4

F694ZZ Flange Bearing 4

2
Power Accessories

Accessory Name Qty.

Tower Pro Micro Servo


1
SG90

Tower Pro Micro Servo

er
1
MG995

d
o un
nF

Gear Reducer 2
Su

Driven Wheel 2

Driving Wheel 2

3
Electronic Accessories

Accessory Name Qty.

SunFounder UNO 1

d er
un
Sensor Shield 1
o
nF
Su

DC Motor Driver
1
Module

Step-down DC-DC
1
Converter Module

4
Switch Module 1

Photoelectric
1
Switch

Photosensitive
4
Module

d er
Obstacle Avoidance
un
2
Module
o
nF

Tracking Module 5
Su

18650x2 Battery
1
Holder

Ribbon 2 (13cm)

USB Data Cable 1

5
14cm Male-to-
6
Male
10cm Male-to-
4
Female
Dupont 10cm Female-
12
Wires to-Female
20cm Female-
7
to-Female
40cm Female-
18
to-Female

Tools
Accessory Name Qty.

Cross
1

er
Screwdriver

d Cross Socket Wrench 1


o un
nF

Heat Shrink
1
Tubing
Su

Self-provided Components
The following components are not included in this kit.

Accessory Name Qty.

18650 Rechargeable
Li-ion Battery 3.7V
Note: 2
Please DO NOT use a battery
which has a protection board.

6
Introduction to Smart Car for Arduino
The smart car is a great platform for you to get started with robotics. According to the
instructions in this manual, you will learn not only how to assemble a robot car but also play
the smart car through 5 experiments. After mastering every experiment, you can extend its
functions or build your own platform based on our smart car platform.

d er
o un
nF
Su

With the modules and sensors added, the smart car can go forward, go backward, turn left
and right, follow lines, seek light, avoid obstacles and so on. Many boards and sensors are
used in this project such as the sensor shield, motor driver module, step-down DC-DC
converter module, switch module, ranging module, photosensitive module, obstacle
avoidance module, and tracking module. Different modules are used to achieve
corresponding functions. And the car is controlled by SunFounder Uno board. Next let's first
check these modules in detail.

7
Get Started
Note:
Before starting your own project, you must download the Smart_Car_for_Arduino.zip
package on our website by visiting LEARN -> Get Tutorials -> Smart Car Kit for Arduino and
unzip it.

Arduino
Description
Arduino is an open source platform that applies simple software and hardware. You can get
it in a short even when you know little of it. It provides an integrated development
environment (IDE) for code editing and compiling, compatible with multiple control boards.
So you can just download the Arduino IDE, upload the sketches (i.e. the code files) to the

er
board, and then you can see experimental phenomena. For more information, refer to
http://www.arduino.cc.

Arduino Board – SunFounder Compatible


d
un
In this kit, SunFounder Uno R3 board is used and it is completely compatible with Arduino Uno
Board.
o
nF
Su

8
Install Arduino IDE
The code in this kit is made based on Arduino, so you need to install the IDE first. Skip it if you
have done this.

Now go to the arduino.cc website and click DOWNLOAD. On the page, check the software
list on the right side under Download the Arduino Software.

d er
o un
Find the one that suits your operation system and click to download. There are two versions
of Arduino for Windows: Installer or ZIP file. You're recommended to download the former.
nF

Just download the package, and run the executable file to begin installation. It will
download the driver needed to run Arduino IDE. Then do the install as suggested. For details
of steps, refer to the guide on Learning->Getting Started ->Arduino, scroll down and see Install
Su

the Arduino Software.

After install is done, you can see an Arduino icon on your desktop. Double click to open it.

Add Libraries
1) Select Sketch -> Include Library -> Add ZIP Library

9
2) Find the file MsTimer2.zip under Smart Car for Arduino\Code\library. Click it open and then
you'll be prompted by "Library added to your libraries. Check 'Import libraries'”. You also can

er
see the libraries just imported have appeared on the list by Sketch->Include
Library->MsTimer2.

d
o un
nF
Su

Servo
Servo is a set of automatic control system composed of DC motors, reduction gear set,
sensors and control circuits. The output shaft can be rotated to a certain angle by sending
signals. The servo can only rotate in a certain range, for example, 180°. It cannot rotate any
circles like the DC motor. The servo enables you to easily rotate an object in a certain angle,
so it is widely used in model planes and robot joints.
10
In this car kit, two types of servo are used: Tower Pro Micro Servo (blue ones) for obstacle
avoidance experiment, and Micro Servo MG995 SG90 (black) in the car front to control the
its direction.

er
Servo Test

d
1) You may find a long rocker arm packaged with the servo, mount it onto the servo, and
spin it to the maximum angle.
o un
nF
Su

2) Connect the circuit as follows:

11
Power Source
Red to +
Black to - Servo
Brown to GND
Red to VCC
Orange to Signal
(pin2)

Servo Power

er
+ to VCC
- to GND
d
oun
nF
Su

12
3) Connect the SunFounder Uno board to your computer via a USB cable. Open the file
Car_Forward.ino under the path Smart Car for Arduino\Code\1.Car_Forward\
Car_Forward. Before uploading the sketch to the board, you need to select the right
Board and Port through Tools->Board->Arduino/Genuino Uno.

d er
Then click to Tools->Port->COM29 (your port may be different)
o un
nF
Su

4) Click the Upload icon. The code is uploaded successfully when you are prompted
"Done Upload" at the bottom.

13
d er
o un
5) After uploading the code successfully, you can hear a sound of the gear moving when
nF

the servo rotates. It means the adjustment succeeds.

Sensor Shield
Su

It is convenient to place components on a breadboard. However, you need to have some


electronic foundation to build various kinds of circuit. By using this sensor shield, you only need
to wire components to the shield with some jumper wires, and then you can build your own
project quickly. The sensor shield is one of the most common Arduino peripheral devices, as
shown below:

14
Its schematic diagram is as shown below: note that VCC only supplies power to the devices
connected to D2 (hooked to the black servo) and D3. Other components are powered by
5V.

d er
o un
nF
Su

15
Motor Driver Module
The motor driver module is used to drive two motors to rotate. The driver chip used here is
L298N.

d
Its schematic diagram is as shown below:
er
o un
nF
Su

16
L298N is a high voltage, large current driver chip manufactured by ST, which uses a 15-pin
package.

Its main features are as follows:


• High operating voltage, which can be up to 40 volts;
• Large output current - the instantaneous peak current can be up to 3A;
• With 25W rated power;
• Two built-in H-bridge, high voltage, large current, full bridge driver, which can be used
to drive DC motors, stepper motors, relay coils and other inductive loads.
• Using standard logic level signal to control.
• Able to drive a two-phase or four-phase stepper motor, and two-phase DC motors.

Its pin functions are as shown below:

er
Pin Name Description

1 Sense A
d
The sense resistor is connected between this pin and ground to
un
15 Sense B control the current of the load.

2 Out 1 Outputs of the Bridge A; the current that flows through the load
o

3 Out 2 connected between these two pins is monitored at pin 1.


nF

Supply Voltage for the Power Output Stages.


4 Vs A non-inductive 100nF capacitor must be connected between this
pin and ground.
Su

5 Input1
TTL Compatible Inputs of the Bridge A.
7 Input2

6 Enable A TTL Compatible Enable Input: the L state disables the bridge A
11 Enable B (enable A) and/or the bridge B (enable B).

8 GND GND

Supply Voltage for the Logic Blocks. A100nF capacitor must be


9 Vss
connected between this pin and ground.

10 Input3
TTL Compatible Inputs of the Bridge B.
12 Input4

13 Out 3 Outputs of the Bridge B. The current that flows through the load
14 Out 4 connected between these two pins is monitored at pin 15.
17
The driver module can drive two motors. The enabled terminals ENA and ENB are effective
at high level. The control mode and state of motor A are as shown below:

ENA IN1 IN2 The State of DC Motor A

0 X X Stop

1 0 0 Brake

1 0 1 Rotate Clockwise

1 1 0 Rotate Counterclockwise

1 1 1 Brake

If you want to regulate the speed of motor A by PWM, you need to set IN1 and IN2, confirm

er
the rotational direction of the motor, and then output PWM pulses for enabled terminals.
Please note that the motor is in the free stop state when the signal of enabled terminal is 0.
d
When the enabled signal is 1, if IN1 and IN2 are 00 or 11, the motor is in brake state, and the
un
motor stops rotating. If IN1 is 0 and IN2 is 1, the motor A rotates clockwise; if IN1 is 1 and IN2 is
0, the motor A rotates counterclockwise. This is the control method for motor A. The control
method for motor B is the same as that for motor A.
o
nF

Step-down DC-DC Converter Module


Su

The DC-DC module is used to reduce the input voltage and output a stable 5 volts voltage.
Here the LM2596 switching voltage regulator is used to regulate the voltage.

18
The corresponding schematic diagram:

d er
un
The LM2596 regulator is a monolithic integrated circuit ideally suited for easy and convenient
design of a step−down switching regulator (buck converter). It is capable of driving a 3.0A
o

load with excellent line and load regulation. It is internally compensated to minimize the
nF

number of external components to simplify the power supply design.

Since LM2596 converter is a switch−mode power supply, its efficiency is significantly higher in
Su

comparison with popular three−terminal linear regulators, especially with higher input
voltages. The LM2596 operates at a switching frequency of 150 kHz thus allowing smaller sized
filter components than what would be needed with lower frequency switching regulators. It
is available in a standard 5−lead TO−220 package with several different lead bend options,
and D2PAK surface mount package.

Features

• Fixed Output Voltage: 5V


• Guaranteed 3.0 A Output Load Current
• Wide Input Voltage Range up to 40 V
• 150 kHz Fixed Frequency Internal Oscillator
• TTL Shutdown Capability
• Low Power Standby Mode, typically 80 μA
• Thermal Shutdown and Current Limit Protection
19
Its pin functions are as shown below:

Pin Name Description

This is the positive input supply for the IC switching regulator. A suitable
input by pass capacitor must be present at this pin to minimize voltage
1 VIN
transients and to supply the switching currents needed by the
regulator.

2 GND Circuit ground

Internal switch. The voltage at this pin switches between (+V IN − V


SAT) and approximately −0.5V, with a duty cycle of approximately V
3 OUTPUT OUT /V IN. To minimize coupling to sensitive circuitry, the PC board
copper area connected to this pin should be kept to a minimum

er
4 Feedback Senses the regulated output voltage to complete the feedback loop
d
un
Allows the switching regulator circuit to be shut down using logic level
signals thus dropping the total input supply current to approximately
80 µA. Pulling this pin below a threshold voltage of approximately 1.3V
o

5 ON/OFF turns the regulator on, and pulling this pin above 1.3V (up to a
maximum of 25V) shuts the regulator down. If this shutdown feature is
nF

not needed, the ON /OFF pin can be wired to the ground pin or it can
be left open; in either case the regulator will be in the ON condition
Su

Switch Module

The switch module is used to turn on/off the power. A self-locking switch is used. It is a single-
pole double-throw switch. When the button is not pressed, pin 1 and 3 are connected, and
pin 4 and 6 are connected, as shown in figure (a). When the button is pressed, pin 2 and 3
are connected, and pin 4 and 5 are connected, as shown in figure (b).

20
(a) When the button is NOT PRESSED (b) When the button is PRESSED

er
Photoelectric Switch
d
o un
nF
Su

This is a photoelectric sensor including both transmitting and receiving parts. You can adjust
the sensor as required if you want to detect a distance. With the advantage of long
detection distance, less interference by visible light, cheap price, and easiness to assemble
and use, it can be widely applied in robot obstacle avoidance, assembly line piece counting,
and many other occasions.

Electrical Feature Lead Description


Voltage: 5VDC Red: Positive Pole
Current: 100mA Green: Negative Pole
Distance: 3-80CM Yellow: Signal Output

21
Photosensitive Module

Operating Principle
The resistance of the photoresistor decreases as the incident light intensity increases. The
stronger the light is, the lower the resistance of the photoresistor is, and the voltage division
on the analog port is larger. Also the value transformed from the voltage on the analog port
to digital value by A/D convertor increases. The change of the light intensity can be
displayed on LED bar by programming.

er
The schematic diagram for photosensitive module is as shown below. D is connected to the
analog port of the sensor shield.
d
o un
nF
Su

Obstacle Avoidance Module

The detection distance of IR obstacle avoidance module is 3-30 cm.

22
Operating Principle
After power on, the LED on the board goes out and enters into operating state after blinking
once. Pin EN is at high level by default and the enabled sensor works. When an obstacle is
detected ahead, the LED on the board will light up and the pin OUTPUT will output low level
signals. When no obstacle is detected, the LED on the board keeps off and the pin OUTPUT
outputs high level signals.

Features:
• Various installations and connections (vertical or horizontal), expanding applications.
• With a potentiometer, able to adjust the detection distance.
• Sensors with an enabled port, convenient for signal lines used as bus applied in circuits.
• After power on, the enabled port is at high level by default. The enabled sensor detects
output signals.

Its pin functions are as shown below:

er
Pin Name Description
1 GND Ground
2 VCC
d Power supply (5V)
un
3 OUT Signal output pin
4 EN Signal output pin, enabled terminal
o

The schematic diagram:


nF
Su

23
Tracking Module

The TCRT5000 sensor (or infrared photoelectric sensor) is used, including a blue transmitting
tube and a black receiving tube (its resistance will change with the amount of infrared light
received).

er
The IR transmitting tube of TCRT5000 sensor constantly launches infrared light. Since the black
receiving tube absorbs light, when the IR transmitting tube shines on a black surface, the
reflected light is less and the IR rays received by the receiving tube is less. This indicates the
d
resistance gets larger, the comparator outputs high level, and the indicator LED goes out.
un
Similarly, when it shines on a white surface, the reflected light is more, which indicates the
resistance of the receiving tube is lower, the comparator outputs low level, and the indicator
LED lights up.
o
nF

The pin functions are as shown below:

Pin Name Description


Su

1 VCC Power supply

2 GND Ground

3 D0 TTL switching signal output

4 A0 Analog signal output

24
The schematic diagram for tracking module:

d er
o un
nF
Su

25
Car Assembly

Front Wheel

1. Fasten the bearing, the following acrylic plates and driven wheel with an M4*25 screw
and an M4 self-locking nut.

d er
o un
nF

2. After assembly, it is as shown below: 3. Do not over tighten the nuts so that the
wheel can spin smoothly.
Su

26
Deflecting Plate + Front Wheels

1. Fasten the following acrylic plates and the assembled front wheel with M3*8 screws and
M3*20 copper standoffs.
And fasten M3*8 screws and an M3*30 copper standoff to the smaller acrylic plate.

d er
o un
2. After assembly, it is as shown below:
nF
Su

3. Connect another front wheel, as shown below:

27
Deflecting Plate + Rocker Arm

1. Fasten the following rocker arm of the MG995 servo (the black one) to the deflecting
plate with servo screws.
Packaged with the MG995 servo, the servo screws are within the longer four of five
screws.
The rocker arm is packaged with the MG995 servo together.

d er
o un
2. After assembly, it is as shown below:
nF
Su

28
Rear Lower Plate + Rear Wheels

1. Assemble the following acrylic plates together.

2. After assembly, it is as shown below:

d er
3. Fasten the following acrylic plates and gear reducer with M3*30 screws and M3 nuts.
un
Assemble the driving wheel to the gear reducer.
o
nF
Su

4. After assembly, it is as shown below:

5. Connect another driving wheel, as shown below:

29
Rear Upper Plate + Copper Standoffs

1. Fasten the following acrylic plate with M3*8 screws and M3*10 copper standoffs.
The plate is to connect the electric modules and shields later.

d er
un
2. After assembly, it is as shown below:
o
nF
Su

3. The top view is as follows. Please pay attention to the direction of the acrylic plate.

30
Deflecting Top Plate

1. Fasten the following acrylic plates with an M3*12 screw and an M3 self-locking nut.

d er
o un
nF

2. After assembly, it is as shown below:


Do not over tighten the screws so that the acrylic plate can move smoothly.
Su

31
Servo MG995 + Chassis + Battery Holder

1. Fasten the following acrylic plates, the chassis and the MG995 servo with M4*12 screws,
M4 nuts and M4*30 copper standoffs.

d er
un
2. After assembly, it is as shown below:
o
nF
Su

3. Fasten the following acrylic plates with an M3*12 screw and an M3 nut.

32
4. After assembly, it is as shown below:

5. Connect the other acrylic plates symmetrically.

d er
o un
nF
Su

6. Fasten the chassis with M3*8 screws and M3*10 copper standoffs.

33
7. After assembly, it is as shown below.

8. Cross the ribbon through the following acrylic plate. Please note that one side of the
ribbon should be longer and the other is shorter.
With the ribbon, you can remove the batteries easily. Also you can skip this step.

d er
un
9. Fasten the chassis and the battery holder with M3*14 countersunk screws and M3 nuts.
o
nF
Su

34
10. After assembly it's like:

Chassis + Deflecting Plate

1. Plug the servo wires to pin 2 of the Sensor Shield, as shown in Servo Test previously.
Fasten the following acrylic plates with M3*8 screws and servo screws.
Packaged with MG995 servo, the servo screws are within the shorter ones of five screws.
Note: The central vertical lines of the Chassis and Deflecting Plate should be

er
perpendicular; otherwise, the front wheel will not be able to go straight as you control.

d
o un
nF
Su

2. After assembly, it is as shown below:

35
3. The bottom view:

Chassis + Rear Upper Plate

1. Fasten the following acrylic plate with two M3*12 screws and M3 nuts.
Then fasten an M3*12 screw and an M3*10 copper standoff to the rear plate.

d er
o un
nF
Su

2. After assembly, it is as shown below:

36
3. The top view:

4. Fasten the following front and rear parts with M3*8 screws and M3*25 copper standoffs.

d er
o un
nF
Su

2. After assembly, it is as shown below:

37
3. The top view:

d er
o un
nF
Su

38
Assembling Electronic Shields and Modules

1. Fasten the sensor shield, switch module, step-down DC-DC converter module, and L298N
motor driver module to the car with M3*6 screws.
2. After assembly, it is as shown below:

d er
o un
nF
Su

39
Experiments

Experiment 1 Going Forward and Backward


In this experiment, the car begins to walk, but it is just the simplest movements: going forward
and backward and then stopping. This is the first and most important step for car walking.
The subsequent experiments are all based on this experiment. You need to download the
Smart Car for Arduino zip file on LEARN->Get Tutorials->Smart Car Kit for Arduino on our
website, which contains the code and user manual for each experiment. After the assembly
and circuits are finished, if you feel the wires are too messy, you may wrap them with the
heat shrink tubing so the car can look more adorable with neat wiring. Now let's get started!

The physical diagram for the car to go forward and backward is as shown below:

d er
o un
nF
Su

40
Components
- 1 * Smart Car for Arduino
- 2 * 18650 battery
- 1 * USB cable
- Several Dupont wires

Experimental Principle
The batteries output 7.2V to the switch module. When you press the button of the switch
module, 7.2V will be input to the step-down DC-DC converter module which then outputs 5V
after lowering the voltage. 5V is input to the sensor shield to supply for the servo. The MG995
servo at the front is to control the direction the car walks in. In this experiment, the car keeps
walking straight forward/backward. The motor driver module is used to drive the two gear
reducers connected to the rear wheels of the car, of which the rotation drives that of the
wheels. Thus, the car begins to walk.

er
Experimental Procedures

1) d
Connect the motor driver module and sensor shield
un
Motor Driver Module Sensor Shield

5v 5v
o
nF

ENA 5

INT1 8
Su

INT2 9

INT3 10

INT4 11

ENB 6

41
Su
nF

42
oun
der
2) Connect the motor driver module and two motors:

d er
o un
Note:
nF

Please pay attention to that diagram. Each gear reducer has two wiring terminals. You
should wire them correctly. The wiring will affect the rotational direction of the gear
reducers. If you do not know how to distinguish, you can try wiring them randomly first.
Su

Then burn the code under the path Smart Car for Arduino\Code\1.Car_Forward
\Car_Forward to the board to see whether the car moves forward. If it does, you've wired
them correctly. If not, you may need to change the wiring until the car moves forward.

3) Connect the sensor shield and the servo

Servo Sensor Shield

+ (Red Wire) 5v

- (Brown Wire) GND

Signal Output (Orange Wire) 2

43
d er
o un
nF
Su

4) Connect the step-down DC-DC converter module and switch module

Note: The two pins of the battery holder should not be in contact; otherwise it will cause
a short circuit and the battery will be burnt.

44
d er
o un
nF
Su

After you have finished all the connections, connect the SunFounder Uno board to your
computer. Download the sketch under the path Smart Car for Arduino\Code
\1.Car_Forward\Car_Forward, and then remove the USB cable. Press the button on the
switch module, and the car starts running.

Experimental Phenomena
When you press down the button of the switch module, the car starts to go straight. 2 seconds
later, it starts to go backwards and then stops after another 2 seconds. If you press down the
button for a second time, the car will start to walk again. If you want to change the time the
car walks, you can modify the sketch as you like.

45
Experiment 2 Turning Right and Left
The principle and connection diagram for this experiment are the same as those for the first
experiment. Only a turning function is added. After going forward for one second, the car
turns right. After another second, the car turns left. One second later, it goes forward, and
then backward. Two seconds later, it stops. Simply put, the car does: go forward for one
second, turn right for one second, go forward for one second, and then turn left for one
second, finally go forward and then backward, and stop two seconds later.

Components
- 1 * Car model
- 2 * 18650 battery
- 1 * USB cable
- Several Dupont wires

er
Experimental Principle
Change the rotational angle by sketch to make the car turn.
d
un
Experimental Procedures
After you have finished all the connections, connect the SunFounder Uno board to your
computer. Download the sketch under the path Smart Car for Arduino\Code\2.Car_Turn
o

\Car_Turn, and then remove the USB cable. Press down the button on the switch module,
nF

and the car will start running.

Experimental Phenomena
Su

When you press down the button on the switch module, the car will go forward. 1 second
later, it turns right, and then goes forward for 1 second again. Then it turns left. 1 second later,
the car goes forward for 1 second and then goes backward. Two seconds later, it stops.

The routine: go forward for one second, then turn right for one second, go forward for one
second, and then turn left for one second. Finally go backward. Two seconds later, stop.

46
Experiment 3 Line Following
This experiment adds five tracking modules to the first experiment to make the car follow the
black line. After the assembly and circuits, you may wrap the wires up with the heat shrink
tubing so the car can be lovelier in order with neat wiring.

The physical diagram of this experiment is as shown below:

d er
o un
nF
Su

Components
-1 * Car model
-5 * Tracking module
-2 * 18650 battery
-1 * USB cable
- Serial Dupont wires

Experimental Principle
When one of the tracking module encounters a black line, the corresponding indicator will
light up. The servo turns to the direction detected by the tracking module, and then the car
will walk towards this direction.

47
Experimental Procedures
Step 1: Assemble Front Plate

1. Fasten the following acrylic plates with M3*12 screws and M3 nuts.

er
2. After assembly, it is as shown below:

d
o un
nF

Step 2. Connect 5 tracking modules: connect GND of the 5 modules to GND, VCC to 5V, and
D0 to A0-A4.
Su

Tracking Module Sensor Shield

D0 A0/A1/A2/A3/A4

GND GND

VCC 5V

48
1) Connect the first tracking module:

d er
o un
nF
Su

49
2) Connect the second tracking module:

d er
o un
nF
Su

50
3) Connect the third tracking module:

d er
o un
nF
Su

51
4) Connect the fourth tracking module:

d er
o un
nF
Su

52
5) Connect the fifth tracking module:

d er
o un
nF
Su

53
Step 3. The front plate is used to grab the sensors module.

1. Assemble the 5 tracking modules to the front plate with M3*8 screws, M3*20 copper
standoffs, and M3*6 screws.

d er
un
2. After assembly, it is as shown below:
o
nF
Su

54
Step 4. Mount the Front Plate to Car

1.Assemble the front plate to the car with M3*12 screws and M3 nuts

2. After assembly, it is as shown below:


d er
o un
nF
Su

55
The figure of completed assembly (no wire) is as shown below:

d er
un
Connect the SunFounder Uno board to your computer. Download the sketch under the path
Smart Car for Arduino\Code\3.Car_LineFollowing\Car_LineFollowing, and then remove the
USB cable. Pressed the button on the switch module.
o
nF

Notes:
After you have finished all the connections, you need to adjust the sensitivity of the tracking
module. You can draw a black line (it is better wider than or equally wide with the tracking
Su

module) on a white surface. Place the car on the white surface, and adjust the
potentiometer on a tracking module. Then switch on the car.

If the following situation happens, the module is pretty sensitive: when the tracking module is
over a white surface, the switch indicator will stay dim; once it encounters a black line, the
LED will light up immediately, and go out the moment the module passes the black line. If
the case is not like this, like the module being insensitive, spin the potentiometer in the
opposite direction. In the same way, adjust the rest four tracking modules.

Now draw a black line on a large white board, and the car will go following the line.

56
Su
nF

57
oun
der
Experiment 4 Light Seeking
This experiment adds four photosensitive modules based on the first experiment to make the
car walk towards the light source. The photosensitive modules can show the change of light
intensity on the LED bar. After all the assembly and circuits, if you feel the wires are too messy
and should be more organized, you may wrap them with the heat shrink tubing.

The physical diagram of light-seeking experiment is as shown below:

d er
o un
nF
Su

Components
-1 * Car model
-4 * Photosensitive module
-2 * 18650 battery
-1 * USB cable
-Several Dupont wires

Experimental Principle
When you shine the flashlight onto the car, the photoresistor on four photosensitive modules
senses the light. The resistance of the photoresistor decreases as the light intensity increases,
and more voltage is assigned to the analog port. Then a larger voltage is transformed into
digital value by A/D convertor. You can tell the direction of the light source by this digital
58
value and make the car move forward along the direction of light source by programming.
You can also display the change of light intensity on LED bar.

Experimental Procedures

Step 1. Connect the circuit. This experiment adds four photosensitive modules based on the
first experiment.

1) Connect the first photosensitive module

Photosensitive Module Sensor Shield


VCC 5V
GND GND
ST_CP 3
SH_CP 4

er
DS 7
Q7’ Connected to DS of next module
D d A0
o un
nF
Su

59
2) Connect the second photosensitive module

Photosensitive Module Sensor Shield


VCC 5V
GND GND
ST_CP 3
SH_CP 4
Q7’ Connected to DS of next module

D A1

d er
o un
nF
Su

60
3) Connect the third photosensitive module

Photosensitive Module Sensor Shield


VCC 5V
GND GND
ST_CP 3
SH_CP 4
Q7’ Connected to DS of next module
D A2

d er
o un
nF
Su

61
4) Connect the fourth photosensitive module, namely, the one at the back:

Photosensitive Module Sensor Shield


VCC 5V
GND GND
ST_CP 3
SH_CP 4
D A3

d er
o un
nF
Su

62
Step 2. Assemble the photosensitive module
1. Assemble the photosensitive modules to the front plate with M3*12 screws and M3 nuts.

d er
o un
2. After assembly, it is as shown below:
nF
Su

63
The figure of completed assembly (no wire) is as shown below:

d er
Step 3. After you have finished all the connections, connect the SunFounder Uno board to
your computer with a USB data cable. Download the corresponding sketch under the Smart
un
Car for Arduino\Code\4.Car_Lightseeking\Car_Lightseeking path, and then remove the
USB cable.
o

Test before running:


nF

Switch on the power. To make the car work steadily, some adjustments need to be made.
First, turn the potentiometer on the sensor shield till the car stays still under the current ambient
Su

light condition, which means if there is no brighter light shining on the car, it will not move.
Then test the car with a flashlight. Shine the flashlight on the car and it will move accordingly;
withdraw the light and the car stops right away. If you get these results, it means the test
succeeds and the car can seek light and move accordingly.

64
Experimental Phenomena
On the car, there are four photosensitive modules that control the car to move forward,
backward, left and right. When you shine the flashlight onto a specific module, the car will
move accordingly. Thus, you can control the car to move as you want!

After the adjustment, the car keeps still. Then shine the flashlight on the middle photosensitive
module at the back, and the car moves backwards; shine on the left module and it turns
counterclockwise; shine on the right module and it turns clockwise; shine on the module at
the front and it moves forward. If you withdraw the light away from the modules, the car will
stop right away.

d er
o un
nF
Su

65
Experiment 5 Obstacle Avoidance
This experiment adds an obstacle avoidance module based on the first experiment. In this
experiment, when the car detects an obstacle, it will turn automatically in case of crash.
After the assembly and circuits are completed, if you feel the wires are too messy, you may
wrap them with the heat shrink tubing so the car can be more organized.

The physical diagram is as shown below:

d er
o un
nF
Su

Components

-1 * Car model
-2 * Obstacle Avoidance Module
-1 * Photoelectric Switch
-1 * Small Servo (blue),
-2 * 18650 Battery
-1 * USB Cable
-Several jumper wires

66
Experimental Principle

When the car detects no obstacle, the MG90 servo with a photoelectric switch module
rotates back and forth between 60 and 120 degrees. When it detects an obstacle, the car
will stop and the MG90 servo rotates from 0 to 180 degrees.

From the perspective of programming, the range of 0-180 degrees is divided into two parts.
For example, 0-90 degree is one part, and 91-180 degree is the other part. The photoelectric
switch module can detect obstacles constantly in a certain angle range. Then the results are
divided into two parts, and the low level 0 is counted – the number means how many times
the obstacle is detected in the range. The MG995 servo then turns to the side with the smaller
number. The motors of the car start to drive the wheels moving.

At the same time, the MG90 servo still rotates constantly to detect the obstacle on the other
side until it cannot detect any obstacle. This means the car turns away successfully. In order
to assist that process, two short-distance IR obstacle avoidance modules are added to set a

er
secure turning distance for car turning. Since the car is likely to hit the obstacle due to a short
turning distance, the car backs in the case until it reaches a secure turning distance, and
then runs forward bypassing the obstacle.
d
un
Tips:
Since the obstacle avoidance module and photoelectric switch are sensed via IR light, it is
o

not suggested to apply on a black background or use a black obstacle for better effects.
nF

Experimental Procedures

Step 1. Assemble the mount


Su

1. Fasten the following rocker arm to the acrylic plate with M1.2*5 self-tapping screws.
The rocker arm is packaged with the MG90 servo together.

67
2. After assembly, it is as shown below:

Step 2. Connect the MG90 servo, as shown in the following table:

Servo MG90 Sensor Shield

Red (Power supply) 5V

er
Brown (Ground) GND

d
Orange (Signal line) 3
o un
nF
Su

68
Connect the SunFounder Uno board to the computer via a USB cable. Then upload the
sketch under Smart Car for Arduino\Code\Servo to the board, remove the USB cable and
then press the button on the switch module.

Step 3. Assemble the servo

1. Fasten SG90 servo to the following acrylic 2. After assembly, it is as shown below:
plate with M2*10 screws and M2 nuts.

d er
o un

3. Fasten the acrylic plate with a round hole 4. After assembly, it is as shown below:
nF

by M3*12 screws and M3 nuts.


Su

69
5. Fasten the MG90 servo and its base acrylic 6. After assembly, it is as shown below:
plate with servo screw. Note: Though the acrylic plate and servo
Packaged with MG90 servo, the servo can be assembled directly, the screw
should still be used to avoid the gear
screw is within the shorter ones of three
wear.
screws. The two plates should be in parallel
as shown by the arrows.

d er
o un
nF
Su

Step 5. Connect the photoelectric switch

Photoelectric Switch Sensor Shield

Red (Power Supply) 5v

Green (Ground) GND

Yellow (Signal line) 12

70
d er
o un
nF

After the photoelectric switch is connected, you need to adjust it for use. Place it flat on the
desk, set an obstacle in white in its front. Since its detection distance is farther than that of
the two obstacle avoidance modules, you're suggested to place the obstacle 30-40cm
Su

away from switch. Adjust the potentiometer at its back. When it detects obstacles, the LED
at its back will brighten. Therefore, you need to do the adjustment that it detects objects
steadily at a distance of 30-40cm, and detection completed at the instant when the
obstacle appears. So you can calibrate the switch by the LED. Move the obstacle forward,
backward, to the left and to the right. During this course, if the LED dims at once when it's
moved away and brightens again when it's placed back, it means it's adjusted successfully.

71
Step 6. Assemble the photoelectric switch

1. Unscrew one nut on the photoelectric switch.

2. After unscrewing, it is as shown below:

er
3. Stick the photoelectric switch to the mount and screw the nut back.
d
o un
nF
Su

4. After assembly, it is as shown below:

72
Step 7. Assemble Mount

Fasten the mount to the smart car with M3*12 screws and M3 nuts.

After assembly, it is as shown below: d er


o un
nF
Su

Step 8. Connect two obstacle avoidance modules

Pin OUT of the two obstacle avoidance modules is respectively connected to pin 4 and pin
7 of the sensor shield.

Obstacle Avoidance Module Sensor Shield

GND GND

VCC VCC

OUT 4/7

73
d er
o un
nF
Su

Note:

After the IR obstacle avoidance sensor module is wired to the car, you need to adjust its
sensitivity.
There are two LEDs on the obstacle avoidance module: power indicator LED, which brightens
when the module is powered, and signal indicator LED, which does so when the module
encounters an obstacle. There are also two potentiometers on the module; facing the front
74
of the car, the left pot is to adjust the sensibility and the right one is to do the detection range.

Place the obstacle avoidance sensor module on a flat surface, and an object (better in
white) in its front, about 7 or 8 cm away (not suggest to set it too far from the modules).

First adjust the left pot. Move the obstacle left and right, out of the detection range and
move it back. Check whether the LED on the right side (i.e. the signal indicator, when you're
facing the car front) of the module brightens steadily when an obstacle appears in front,
and dims after the obstacle is gone.

Then adjust the pot at the right. Place the obstacle in front of the module, move it closer and
farther. Check whether the signal LED simply brightens and dims as the obstacle approaches
and moves away. Repeat the steps until the car can detect an obstacle beyond 7 or 8 cm
stably.

Step 9. Assemble the two obstacle avoidance modules

er
Place the two obstacle avoidance modules below the chassis on two directions and fix
them with M3*8 screws, M3*20 copper standoffs, and M3*6 screws.
d
o un
nF
Su

75
After assembly, it is as shown below:

d er
o un
The figure of physical objects:
nF
Su

Front View

76
er
Top View

d
The car when the assembly of this experiment is done (no wire):
o un
nF
Su

Top View

77
Now that the assembly is done, switch off the car. Organize the wires – for elegant
appearance, you may wrap the wires with the cable pipe.

Plug in the USB cable, upload the sketch under Smart Car for Arduino\Code
\5.Car_avoidobstacle\Car_avoidobstacle to the board. Press the button on the switch
module, and you can see the photoelectric switch sways when there's no obstacle detected,
and the car goes forward continuously; it will stop and scan when obstacles detected.

d er
o un
nF
Su

78
Copyright Notice

All contents including but not limited to texts, images, and code in this manual are owned by the
SunFounder Company. You should only use it for personal study, investigation, enjoyment, or other
non-commercial or nonprofit purposes, under the related regulations and copyrights laws, without
infringing the legal rights of the author and relevant right holders. For any individual or organization
that uses these for commercial profit without permission, the Company reserves the right to take
legal action.

d er
o un
nF
Su

79

You might also like