Session 1: Exploring Sensors and Movement
Duration: 60 minutes
Equipment Required:
- M3D Robotics kit with various sensors (e.g., distance, line)
- Laptops with Arduino IDE pre-installed
- USB/OTG cables to connect the robot to the laptop
- Projector for live code demonstration
- Paper and pencils for students to document their observations
Learning Objectives:
- Familiarize students with Arduino IDE setup and basic code structure.
- Introduce basic movement commands and data collection from sensors.
- Enable students to display sensor readings on the robot’s screen.
- Build foundational understanding of syntax, comments, and code organization in C++.
1. Introduction to Robots and Sensors (5 minutes)
You can begin the session by starting a discussions about robots with the students. You may say:
“What do you think robots are? What do they actually do?”
Build up on their responses and ask them if they can think of examples of robots in their daily life.
Once students have an idea of what robots are, you can ask them how robots like self-driving cars, or automatic doors know or ‘sense’ when something is nearby.
How do you think robots sense their environment? Does it have senses like we do?"
Lead them to the answer that robots have different types of sensors.
“Can you think of everyday items that might have sensors, like your phone or even a microwave?”
After responses, summarize by explaining what robots are and that sensors help robots (or devices) gather information from their environment, just like how humans use their senses to understand what’s around them.
You may say:
“Exactly! Just like we use our eyes to see and ears to hear, a robot uses its sensors to ‘see’ and ‘feel’ around it. Today, we’ll start exploring how our robot can use these sensors to move and react to its surroundings!”
2. Setting Up the Arduino IDE and Code Structure (10 minutes)
Activity:
Open the Arduino IDE in their laptops and introduce the following code structure:
#include <M3DGo.h>
void setup() {
go.begin();
}
void loop() {
// Robot's actions will go here
}
Instructions:
You may say:
“Think of this code as a guidebook for the robot. First, we need to give it the tools it needs to understand our commands, and that’s what this line
#include <M3DGo.h>does.”
Explain that setup() is where the robot “wakes up” and gets ready to perform tasks, while loop() is like a to-do list that repeats until they stop it.
You may say:
“In between these curly brackets
{}, we’ll be writing the instructions for the robot. Each action will be separated by a semicolon;, just like ending a sentence. Now, who can tell me why adding comments (text after//) might be useful in a code?”
Encourage responses, and then emphasize how comments help others (and themselves) understand each part of the code when they review it.
3. Exploring Basic Movement and Display Commands (15 minutes)
Activity:
Introduce movement commands to make the robot move in different directions:
go.forward()- Move forwardgo.reverse()- Move backwardgo.spinClockwise()- Spin clockwisego.stop()- Stop movementgo.display()- Show text/value on the robot’s screen
Demonstrate through a simple code how by writing a number between the small parenthesis () can change the behavior of the command:
- In the
go.forward()orgo.backward()command, we can control the speed by which the robot moves. - in
go.stop()orgo.spinClockwise()command, the robot takes that many seconds to stop or spin.
Demonstration Code Example:
void setup() {
go.begin(); // Start the robot
}
void loop() {
go.forward(50); // Move forward at 50% speed
go.delay(2000); // Wait for 2 seconds
go.stop(2); // Robot stops moving in 2 seconds
}
Discussion:
You may say:
“Look at the command
go.forward(50);. This makes the robot go forward at 50% speed. Can anyone guess what might happen if we change that number to 100?”
After their responses, run the code and observe. Emphasize the role of go.delay(2000); for timing.
To help them understand the concept of time values smaller than a second, you can set up an activity where students use the stopwatch inside their laptop to measure how quickly there team members can blink their eyes:
Point out the time on the far right and how it is much smaller than 1 second:
You can also relate it to things they know, like sports timers or video games, where milliseconds are often displayed during speed runs or races like F1 and MotoGP . This explanation will help them understand how milliseconds relate to time intervals in programming.
You may say:
“Notice how the robot pauses for exactly 2 seconds? That’s because of this delay command. Think of it like a brief ‘wait’ for the robot between movements.”
Encourage students to try different speeds and delays to see how it changes the robot’s movement.
4. Introducing Sensors and Data Display (15 minutes)
Discussion:
Introduce the concept of collecting and displaying data from sensors:
You may say:
“Just like we see and hear, robots can sense objects or paths using sensors. Today, we’ll use two of them—the distance sensor and the line sensor—to see what they can do.”
Explain how the distance sensor measures how far away an object is, and the line sensor can detect lines on the floor.
Activity:
Guide students to connect the sensors and use sensor commands to read data and display it:
- Distance Sensor: Measure the distance from an object
For distance sensors, we have the following commands:
range.getmm()Gives distance to the object in millimeters.range.getm()Gives distance to the object in meters.range.getcm()Gives distance to the object in centimeters.range.getinches()Gives distance to the object in inches.range.getft()Gives distance to the object in feet.
Sample Code:
void setup() {
go.begin(); // Start the robot
}
void loop() {
display.text(range.getcm()); // Display distance
go.delay(1000); // Wait for a second
}
You may say:
“Here, we’re telling the robot to read the distance from its sensor and show it on its screen. This is how it knows what’s around it. Now, let’s see what happens when we place an object at different distances!”
Teacher’s Role:
Guide students through testing the sensor, adjusting its position, and noting how the displayed value changes.
5. Hands-On Challenges (15 minutes)
Challenge 1: Simple Movement Control**
- Task: Ask students to make the robot move forward for 3 seconds, then stop, and display “Moving Forward” while it’s moving and “Stopped” when it stops.Example Code:
void setup() {
go.begin();
}
void loop() {
display.text("Moving Forward"); // Display message while moving
go.forward(50); // Move forward at 50% speed
go.delay(3000); // Move for 3 seconds
go.stop(); // Stop the robot
display.text("Stopped"); // Display "Stopped" message
go.delay(2000); // Pause before repeating
}
Challenge 2: Turn and Display
- Task: Program the robot to spin clockwise for 2 seconds, stop, display “Turning Right,” then wait for 2 seconds before repeating.Example Code:
void setup() {
go.begin();
}
void loop() {
display.text("Turning Right"); // Display message while turning
go.spinClockwise(50); // Spin clockwise at 50% speed
go.delay(2000); // Spin for 2 seconds
go.stop(); // Stop the robot
display.text("Stopped"); // Display "Stopped" message
go.delay(2000); // Pause before repeating
}
6. Conclusion and Reflection (5 minutes)
Reflection Questions:
You may say:
- “What was something interesting you observed about the distance today?”
- “How might these sensors be useful in everyday technology?”
Discuss how sensors allow robots to make decisions based on real-world information.
Teacher’s Role:
Wrap up by highlighting the practical uses of sensors and how they add “senses” to robots, enabling them to interact with the environment.
Learning Outcome:
By the end of this session, students will have learned to set up and control their robot using basic commands and sensor data, displaying feedback on the robot’s screen. This foundation will support their future exploration of robotics and sensor-based programming.

