Curriculum Guide
Part of:
Inquiry Science with Dartmouth
Developed by: David Qian, MD/PhD Candidate
Department of Biomedical Data Science
Overview
Using existing knowledge of computer science, students will design an Arduino robot that stops
and turns either left or right upon approaching an obstacle.
Science Standards (NH Science Curriculum Frameworks)
S:SPS4:12:3.2 - "Generate solutions to scientific questions and challenges through developing,
modeling and revising investigations"
S:SPS4:12:3.3 - "Apply scientific knowledge and skills to make reasoned decisions about the use
of science and scientific innovations"
S:SPS4:12:4.2 - "Plan and conduct practical tests to solve problems or answer a question, collect
and analyze data using appropriate instruments and techniques safely and accurately"
S:SPS4:12:9.1 - "Collaborate with interested learners using appropriate web resources and
publication media such as journals"
Focus Question
How does a robot avoid hitting obstacles?
Objectives
Through this lesson, students will:
Learn that coding is rarely ever perfect on the first try. They will develop code, evaluate
robot performance, identify unexpected and undesired behaviors, re-assess the logical flow of
their scripts, and repeat many times. (S:SPS4:12:3.2)
Allow students to recognize the complex decisions that humans make but are hardly aware of
on a daily basis. During design of if/then statements, the following reflective questions are
inevitable: "When I personally encounter something in my way, how close do I get before
committing to move around it?" "How do I decide which direction to go next?"
(S:SPS4:12:3.3)
Find ways to test whether individual chunks of code are correctly implemented. For example,
students will need to calibrate the duration and polarity of current delivered to the motors in
order to achieve proper forward movement, left turn, right turn, etc. (S:SPS4:12:4.2)
Appreciate the public domain of shared knowledge. For example, the robot is intended to
measure obstacle distance using an ultrasonic transceiver. The Arduino Internet community
has already developed many libraries that convert signals from the hardware into values that
can be easily incorporated in code. Anyone can find and import these libraries.
(S:SPS4:12:9.1)
Background
Students will have learned how to write loops (for-loops and while-loops), conditional
statements (tests of equality or inequality), and functions (call commands and/or compute and
return a value based on input parameters) in the coding language Processing, which is essentially
Java except simpler. Basic understanding of Arduino-specific commands in Processing is also
encouraged. The gold-standard resource for Arduino beginners:
https://drive.google.com/file/d/0B6tK_RpFvHI5b2NnNUstNWlWaGs/view?usp=sharing
The robots that accompany this module have one input and three outputs. The input is distance to
nearest object as detected by an ultrasonic transceiver. Two of the outputs are motors that control
the robot's movement. The third output is a servo motor (rotation angle can be finely regulated)
on which the ultrasonic transceiver is installed; this motor can be thought of as the "neck" of the
robot, which allows it to measure distances in different directions from the robot's perspective.
Materials
1) The following obstacle course that anyone can borrow and assemble from DCAL
(acknowledgment: originally constructed using supplies from Kimball Union Academy).
a
*
c
b
2) The following robot kits that anyone can borrow and assemble from DCAL (acknowledgment:
five of these were purchased using GK12 funding).
3) Installation of Arduino on a computer (website: www.arduino.cc/en/Main/Software).
Preparation
Print out and distribute attached worksheet. Divide the class into 5 groups, each with a robot.
Depending on the previous group that used this module, the robot kits may need to be assembled
ahead of time or during a separate class period.
Procedure
1) Introduction: Load the maze game from
http://www.labyrinthmaze.com/flash_games/3d_maze_survival.htm on a projector screen.
Tell students to help you navigate through the maze by providing explicit directions.
Intentionally make very incremental movements so that students must constantly shout out
updating directions, such as "keep going straight", "turn right", "turn right even more",
"stop", "look around", etc.
2) Hook: Tie in the relevance of robots. Robots have been created because they are more precise
than humans and do not tire from tedious tasks. However, in order for them to function
autonomously, they must be given very clear instructions. Have the students reflect on what
they had to see in the maze environment to decide subsequent actions.
3) Now that students know all of the possible actions of the robot, they have the foundation for
filling out the attached worksheet. Emphasize that an Arduino microcontroller cannot
understand commands such as "go straight" or "turn left". These movements must be
conveyed in terms of motor rotations activated by the microcontroller. The worksheet is
intended to lay out the pseudocode for each of the 4 action functions that will be required in
the Arduino script. Understanding this worksheet is the most important step for ensuring
module success and preventing logic-flow headaches later. So it would be ideal to patiently
walk through many of the boxes in the worksheet.
4) Code! Example [abbreviated] code is provided below. Have the groups try to maneuver their
robots through one of the right-angle turns of the map on page 2. For example, starting at the
marked *, a robot should move straight, stop, look left and right, and choose to turn right.
Timing how long the motors need to spin will require frequent trials and re-calibration.
int safety = 5;
% How far to stay away from obstacles. Customizable.
int straightT = 100;
int turnT = 2000;
% Number of milliseconds to spin wheel motors for turn
% Value is unique for motor and ground surface
void setup() {
servoMotor(90);
goStraight();
int aheadDistance = sensorMeasure();
}
void loop() {
if (aheadDistance > safety) {
% Keep going straight if farther than
goStraight();
% 5 cm away from obstacle ahead
} else {
stopObserve();
}
aheadDistance = sensorMeasure();
}
void goStraight() {
leftMotor(forward, straightT);
rightMotor(forward, straightT);
}
void turnLeft() {
leftMotor(reverse, turnT);
rightMotor(forward, turnT);
}
void turnRight() {
leftMotor(forward, turnT);
rightMotor(reverse, turnT);
}
void stopObserve() {
servoMotor(0);
int leftDistance = sensorMeasure();
servoMotor(180);
int rightDistance = sensorMeasure();
servoMotor(90);
if (leftDistance > rightDistance) {
turnLeft();
} else {
turnRight();
% Unlikely to get ties ....
}
}
Assessment
Robot does not bump into anything
Robot distance sensor looks for alternative directions to turn upon approaching an obstacle
Robot correctly chooses new direction to turn based on distance to next obstacle
Robot only turns when it cannot proceed further ahead
Extensions
This module is intended for students with little to no Arduino exposure, and some exposure to
programming in Java/Processing.
More advanced students may pursue in the map on page 2:
Route a: nimble navigation through tight turns.
Route b: line-following (ex. using Arduino infrared sensors). Bonus − make line-following
override the distance-sensing trigger to turn, so the robot pushes through the blue flag.
Route c: be able to dodge not only walls but also obstacles that are low on the ground, hidden
from detection by the ultrasonic transceiver (ex. using Arduino pressure sensors).
Autonomous navigation from beginning to end.
Anything else in between! Get creative! This flexible map can facilitate easy learning trials
on small segments, as well as challenging competitions that use the whole area.
Distance sensor facing forward = 90°
F = forward
S = stop
R = reverse
What is the robot
currently doing?
Drive straight
Stop; distance sensor
looks left and right, and
then returns to center
0°
180°
What to do next if the distance sensor detects:
Left
motor
(F, S, R)
F
Motor action
Right
motor
Servo motor
(F, S, R)
(integer angles)
F
Stay at 90°
S
S
Turn left if distance sensor perceives there is more
space to go on the left side compared to the right side
(distance to nearest object)
0, 180, 90
obstruction > 5 cm away
Drive straight
obstruction < 5 cm away
Stop; distance sensor
looks left and right, and
then returns to center
Turn right if distance sensor perceives there is more
space to go on the right side compared to the left side
Turn left
R
F
Stay at 90°
Drive straight
Stop; distance sensor
looks left and right, and
then returns to center
Turn right
F
R
Stay at 90°
Drive straight
Stop; distance sensor
looks left and right, and
then returns to center
Distance sensor facing forward = 90°
F = forward
S = stop
R = reverse
What is the robot
currently doing?
Drive straight
Stop; distance sensor
looks left and right, and
then returns to center
0°
180°
What to do next if the distance sensor detects:
Left
motor
(F, S, R)
F
Motor action
Right
motor
Servo motor
(F, S, R)
(integer angles)
F
Stay at 90°
S
S
Turn left if distance sensor perceives there is more
space to go on the left side compared to the right side
(distance to nearest object)
0°, 180°, 90°
obstruction > 5 cm away
Drive straight
obstruction < 5 cm away
Stop; distance sensor
looks left and right, and
then returns to center
Turn right if distance sensor perceives there is more
space to go on the right side compared to the left side
Turn left
R
F
Stay at 90°
Drive straight
Stop; distance sensor
looks left and right, and
then returns to center
Turn right
F
R
Stay at 90°
Drive straight
Stop; distance sensor
looks left and right, and
then returns to center
© Copyright 2026 Paperzz