Arduino Robotics Beginner Level
Lesson 8
Robot Car Program I
Presented by Advanced Superlogic Team
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 1
Learning Outcome
1. Understand DC motor for the robot car
2. Able to program DC motor with analogWrite and
digitalWrite
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 2
Controlling a DC Motor
The speed of a DC motor can be controlled by changing
its input voltage. A common technique to do this is to use
PWM (Pulse Width Modulation).
PWM is a technique where the average value of the input
voltage is adjusted by sending a series of ON-OFF pulses.
The average voltage is proportional to the width of the
pulses known as the Duty Cycle.
The higher the duty cycle, the higher the average voltage
applied to the DC motor (resulting in higher speed) and
the shorter the duty cycle, the lower the average voltage
applied to the DC motor (resulting in lower speed).
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 3
Arduino Driver board Pinout
With this driver board, we don’t need to do any
wiring on the chip, all connection already done.
Motor M1:
PIN number:
DIR1 = 4
PWM1 = 5
Motor M2:
PIN number:
DIR2 = 7
PWM2 = 6
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 4
Lesson Example
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 5
Setup
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 6
Challenges
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 7
L8 – Challenge 1
Please do the program:
When give input “1”, then DC motor turn clockwise;
When give input “2, then DC motor turn counterclockwise;
When give input “0”, then DC motor stop
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 1 8
Program
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 9
L8 – Challenge 2
Please do the program:
When give input “1”, then DC motor 1 turn clockwise;
When give input “2, then DC motor 1turn counterclockwise;
When give input “3”, then DC motor 2 turn clockwise;
When give input “4, then DC motor 2 turn counterclockwise;
When give input “0”, then both DC motor stop
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 1 10
L8 – Challenge 3
Please do the program:
When give input “1”, then the robot car move forward
When give input “2, then the robot car move backward
When give input “3”, then the robot car turn right
When give input “4, then the robot car turn left
When give input “0”, then both DC motor stop
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 1 11
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 12
STEM | IR4.0 | Robotics Copyright 2023 © Advanced Superlogic Sdn Bhd. All right reserved. Arduino Beginner Lesson 13