PAGE 1 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
ONE DAY OF ROBOTICS
#1 DC MOTOR CONTROL
COACH MICHAEL
[THIS BOOKLET FOR USE WITH SciBOT + DC MOTORS]
A rapid introduction to the world of robotics and mechatronics where you learn to write and
upload text-based programs to a pre-built robot to control its movements, and participate in
a robotics challenge to inspire you to consider a career in engineering
PAGE 2 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
NOTES
PAGE 3 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
ONE DAY OF ROBOTICS
CONTENTS
PART 1: Getting Connected
PART 2: Upload LED code
PART 3: Motor Control
PART 4: Moving Forward
PART 5: Turns and Pivots
PART 6: Mini Challenge
NOTES
PAGE 4 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
PAGE 5 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
ONE DAY OF ROBOTICS
CODING AND ROBOTICS WITH ARDUINO
INTRODUCTION
How much robotics can be taught in a just a few hours? Quite a lot.
Participants, equipped with quality notes, can quickly acquire skills in this exciting field through tackling
challenges that are difficult, but not impossible.
OUTCOMES
Learn how to operate a small desktop robot.
Write and upload program code on a computer.
Upload the code to an Arduino PRIMO robot
Control the speed and direction of rotation of motors to control movements of the robot.
How does a robotics challenge work?
What is a competition maze?
Learn how to navigate using a simple method called dead reckoning.
Write program code to get through the maze.
See how far into the maze on can get, can one complete?
Robot motors
Coding session
Challenge
Break
Robot Sensors
Coding session
Challenge
www.robotscience.co.za
www.youtube.com/electronicsafrica
PAGE 6 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
NOTES
PAGE 7 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
1 DAY OF ROBOTICS: PART 1 CONNECT THE PRIMO ROBOT TO PC WITH USB
Welcome to ONE DAY OF ROBOTICS where you learn to write a few lines of code to control the movements of a
small desktop robot with the minimum of code. By learning how to change the numeric values in the code, and
observing the effect of the changes on the movements of the robot every time you upload the new code, you
can control the distance the robot travels in a straight line and even make it execute some turns and drive into
a maze.
Using the “trial and error” method you can learn how to control the robot without too much difficulty. Pay
attention and understand the notes … after the “code and upload” session there’s a navigation challenge.
If you read these notes very carefully – and take your time to properly understand the explanations of how the
code [and especially the numbers contained in the code] control the hardware – you should be able to
complete the mission.
SciBOT is based on a microcontroller programming board called Arduino UNO. More than 10 million Arduino
UNO controllers have been bought by professional electronics engineers [and hobbyists] over the past decade
making Arduino the most widespread controller in the world. Arduino can be programmed with C++ type text
code using a free software integrated development environment [IDE] and there’s an easy graphics code
option.
PAGE 8 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
When you connect the robot to the computer, its always a good idea to first start the Windows Device
Manager to see which COM port the robot is on. You should see these screens:
Before uploading your Arduino program to the robot, in the Arduino code editor click on the <TOOLS> menu,
then <PORT> and make sure the active COM port is selected, and is showing a check mark like this screenshot:
If there’s more than one active COM port, and youre not sure which one the Arduino is connected to, then
disconnect and then re-connect the robot and observe which COM port vanishes and comes back. Thats the
COM port you need to select in the Arduino IDE.
If you open Device Manager and look at Ports (COM & LPT) and you’re not seeing the COM port as per above
right Device Manager screenshot, or there’s an exclamation mark with a yellow triangle, speak to your
instructor because they will have to check the correct driver for your USB adapter is installed.
When you upload code to the robot, if the screen turns orange at the bottom, that means there are error
which can be mistakes in your code, etc.
Check your code very carefully for wrong characters and brackets and semicolons and keep trying until it
compiles without errors. Speak to your instructor if you can’t find the error.
PAGE 9 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
1 DAY OF ROBOTICS: PART 2 PROGRAM TO FLASH LED ON ARDUINO D13
The brain of your robot is a microcontroller chip ATMEL ATMEGA 328P-PU. The ATMEGA 328 is the heart of the
Arduino UNO system which is an open source prototyping controller that allows you to control a range of on-
board and off-board systems. There is an on-board LED on the Arduino UNO, the motors on the robot are an
off-board system.
The Arduino UNO has a huge community of users around the world, many of whom help beginners get started
with online forums, there are almost endless low cost accessories, and if you wanted to invent something it’s
quite likely someone somewhere in the world might be able to help and advise you.
If you look carefully at the robot you will see it has ON-OFF switches for POWER and MOTORS. When you
connect the robot to the computer used to program it make sure the MOTORS switch is in the OFF position.
In the image on the previous page there’s a green POWER LED on the left and a red MOTORS LED on the right.
The middle LED is orange and is connected to digital pin 13. There is a breadboard where you can put
electronic parts which we will learn more about in a future robotics session.
To upload your first program to the robot go to the <FILE> menu at the top of the Arduino IDE, scroll down to
the <EXAMPLES> option and then <BASICS> and finally select the program called <BLINK> which should look
like this:
EXAMPLE CODE to MAKE LED ON D13 FLASH ON AND OFF
//
// FLASH LED ON D13
//
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);---
}
void loop()
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Change the above code’sdelay” time (the numeric values you see are in milliseconds) and re-upload to the
Arduino PRIMO controller to see what happens. Remove the code from the loop and paste it into the setup
function to see what happens. Make sure the code is nested inside a set of curly brackets so you don’t get error
codes.
Watch some YouTube videos to learn more about the examples code in the Arduino IDE.
www.robotscience.co.za
www.youtube.com/mikerobotscience
www.youtube.com/electronicsafrica
PAGE 10 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
NOTES
PAGE 11 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
1 DAY OF ROBOTICS: PART 3 HOW DC MOTORS WORK
In mechatronics [a fancy word for robotics] movement is produced using motors or actuators.
The robot does not have a steering mechanism like in a regular car, but turns using ‘differential
steering’ which is where the wheels turn at different rates just like an army tank in the illustration.
When the wheel on one side of the robot turns at a faster rate than the other side, then the robot
will pivot towards the side where the wheel is rotating slower. The motors on the robot have two
wires, black [or brown] is GND or 0 volts, the red wire is positive [+ or 5 volts].
Explanation of DC motors here.
CONTROLLING MOVEMENTS OF THE ROBOT
Because the servo motors are mounted on opposite sides of the PRIMO, in order to get the robot to
move forward both wheels need to turn the same way but because the motors are mounted on
opposite sides of the robot one motor will in fact be counter-rotating when compared with the other.
If you are looking at an electronic version of this page imagine folding it down the middle between
the motors to visualise how the wheels are actually rotating in the same direction. If you have a
photocopy in front of you then fold it down down the middle between the servos to see which way
the wheels are rotating on the robot.
PAGE 12 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
NOTES
PAGE 13 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
1 DAY OF ROBOTICS: PART 4 PROGRAM PRIMO ROBOT TO MOVE FORWARD
In the previous section we understood how HIGH pulses control the speed and direction of the wheels. The ball
is at the back of the robot, and follows the driven wheels. If you put the ball in front it tends to force the robot
off course, which makes accurate and repeatable robot movements hard to achieve.
TEST EXAMPLE CODE THAT SHOULD DRIVE THE ROBOT FORWARD FOR TWO SECONDS:
// this code is for the yellow Keyes L298 motor shield
// this code will run the motors FWD for 1 second
// this code runs to motors at 50% duty cycle
// code last tested 20 sep 2025
int DIRA = 12; // rotation direction depends on whether this pin is HIGH or LOW
int DIRB = 13; // rotation direction depends on whether this pin is HIGH or LOW
int ENA = 3; // PWM signal is addressed to the enable pin [3]
int ENB = 11; // PWM signal is addressed to the enable pin [11]
void setup()
{
delay(2000); // STARTING WAIT-OR-DELAY
// ------------- STAGE 1 --------- drive robot forward -----------------
digitalWrite(DIRA, LOW);
analogWrite(ENA, 99); // 0 = 0% 128 = 50% 255 = 100%
digitalWrite(DIRB, HIGH);
analogWrite(ENB, 99); // was: 200
delay(1000); // original value: 1000
analogWrite(ENA, 0); // was: 200
analogWrite(ENB, 0); // was: 200
}
void loop()
{
// one shot program so nothing required here
}
ARDUINO TWO WHEEL DIFFERENTIAL STEERING ROBOT WITH DC MOTORS
If the robot reverses when you upload the drive forward program from the previous page into the PRIMO then
you need to swap the wires around, in other words the plug of the motor that is connected to D10 needs to
move to D11 and the plug of the motor that is connected to D10 needs to be connected to D11.
PAGE 14 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
1 DAY OF ROBOTICS: PART 5 CONTROLLING PRIMO ROBOT: PIVOTS + TURNS
Once you have tested the code and understand how to move the robot forwards, its a good idea to learn how
to execute pivots + turns. If you can drive forward and turn left and right you will be able to navigate a course.
PROGRAM 1: ROBOT DRIVES FORWARD, THEN TURNS:
// this code is for the yellow Keyes L298 motor shield
// this code will run the motors FWD for 1 second
// this code runs to motors at 50% duty cycle
// code tested 20 September 2025
int DIRA = 12; // rotation direction depends on whether this pin is HIGH or LOW
int DIRB = 13; // rotation direction depends on whether this pin is HIGH or LOW
int ENA = 3; // PWM signal is addressed to the enable pin [3]
int ENB = 11; // PWM signal is addressed to the enable pin [11]
void setup()
{
delay(1111); // STARTING WAIT-OR-DELAY
// ------------- STAGE 1 --------- drive robot forward -----------------
digitalWrite(DIRA, LOW);
analogWrite(ENA, 99); // 0 = 0% 128 = 50% 255 = 100%
digitalWrite(DIRB, HIGH);
analogWrite(ENB, 99); // was: 200
delay(1111); // original value: 1000
analogWrite(ENA, 0); // this line of code stops the PWM function
analogWrite(ENB, 0); // this line of code stops the PWM function
delay(1000); // original value: 1000
// ------------- STAGE 2 --------- pivot robot to the right -----------------
digitalWrite(DIRA, HIGH);
analogWrite(ENA, 99); // 0 = 0% 128 = 50% 255 = 100%
digitalWrite(DIRB, HIGH);
analogWrite(ENB, 99); // was: 200
delay(300); // original value: 1000
analogWrite(ENA, 0); // this line of code stops the PWM function
analogWrite(ENB, 0); // this line of code stops the PWM function
delay(1000); // original value: 1000
// ------------- STAGE 3 --------- drive robot forward -----------------
digitalWrite(DIRA, LOW);
analogWrite(ENA, 99); // 0 = 0% 128 = 50% 255 = 100%
digitalWrite(DIRB, HIGH);
analogWrite(ENB, 99); // was: 200
delay(555); // original value: 1000
analogWrite(ENA, 0); // this line of code stops the PWM function
analogWrite(ENB, 0); // this line of code stops the PWM function
delay(1000); // original value: 1000
// ------------- STAGE 4 --------- pivot robot to the right -----------------
digitalWrite(DIRA, LOW);
analogWrite(ENA, 99); // 0 = 0% 128 = 50% 255 = 100%
digitalWrite(DIRB, LOW);
analogWrite(ENB, 99); // was: 200
delay(300); // original value: 1000
analogWrite(ENA, 0); // this line of code stops the PWM function
analogWrite(ENB, 0); // this line of code stops the PWM function
delay(1000); // original value: 1000
}
void loop()
{
}
PAGE 15 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
To control the DC motors you use HIGH and LOW commands to switch the power ON and OFF.
The reason why one motor needs to be run forwards and the other back is because they are mounted on
opposite sides of the robot, if you send both motors the same values the robot will pivot instead of driving
forward. Now it is your turn – see if you can make the robot drive a square and triangle.
www.robotscience.co.za
www.youtube.com/electronicsafrica
www.youtube.com/mikerobotscience
1 DAY OF ROBOTICS: PART 6 ROBOTICS MAZE AND CHALLENGE RULES
1. The objective of the challenge is to evaluate the training and confirm newly acquired skills.
2. The challenge consists of a table with a start and an end point to which the robot must drive
autonomously.
3. The winner of the challenge is the robot that completes the maze first.
4. Alternately, the winner of the challenge will be the robot that drives deepest into the maze.
5. A team consists of a group of learners with one robot.
6. The competition will start at the designated time, which will be signalled by the whistle.
7. The competition will end at the designated time, when the whistle blows.
8. During practice teams will bring their robots to the competition table, and without delay place their
robot on the table and trigger the execution of the program once.
9. If a team wishes to re-test their robot [without going to their base to change and re-upload their
program] that team must go to the back of the line of teams waiting to test robots at the maze.
10. The objective of Rule 8 is to ensure everyone can access the maze without undue delay.
11. During the competition the teams will bring their robots to the competition table, and without delay
place their robot on the table and trigger the execution of the program.
12. Each team will get one start, if things go wrong and that team decides not to go back to their base to
change their code that team must go to the back of the line of teams waiting at the maze.
PAGE 16 | ROBOTICS 101: ONE DAY ©2022 M I C H A E L E T T E R S H A N K
1 DAY OF ROBOTICS: PART 7 USING STRATEGY TO CONQUER THE CHALLENGE
Now you can move the robot forwards, and execute turns and pivots, its time to test your skills against the
maze challenge. There are many ways to conquer the maze, follow this method or try your own approach.
One method, that has proven effective for many teams that succeeded at this challenge, is to break your code
up into stages. Code the robot to drive forward just one fwd stage, and the first turn [Stage 2]. Upload the code
to the robot and take it to the maze and place it on the start markings. Place the robot in exactly the same
place every time you take it to the maze when testing your code. Start the robot. Observe the robot carefully.
When the robot stops after executing the first two stages it should be pointing to the next stage.
Add one more stage, then re-test the robot taking note of where it ends up. Calling out each stage of the
program code as the robot travels into the maze helps identify a stage that may require adjustment. Turns and
pivots are also stages...
Resist the temptation to add a whole bunch of stages in a hurry thinking that will save time and somehow you
will be able to unscramble the code. Yes, there is pressure because you’re competing against other robots, but
it is best to resist the temptation to simply dump a whole bunch of untested code into your robot. Rather add
one stage at a time, making sure each new stage is correct before adding the next. Below is an example of what
the starting code might look like, on the next page is an example of what the code might look like once more
stages have been added.