Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
Today, we're going to learn how to write a simple program for a robot. Can anyone tell me what a program does in robotics?
It tells the robot what to do!
Exactly! Programming is like giving instructions. One example we will explore is how to make an LED blink using Arduino. Does anyone know what the Arduino platform is?
Is it a type of microcontroller?
Correct! By programming it correctly, we can get the robot to perform tasks like blinking an LED. This example will help us understand basic loops and conditionals. Remember, in programming, we often use loops to repeat actions.
What if we want the LED to blink differently?
Good question! We can adjust the delay to change the blink speed. Let's summarize what we've learned today: 1. A program gives instructions to a robot, and 2. We use loops to repeat actions.
Now, let's look at the LED blink code together. Who can identify what pinMode(13, OUTPUT) does?
It sets pin 13 as an output pin to control the LED!
Exactly! Now, the loop() function repeats indefinitely, turning the LED on and off. Why do you think we used delay(500)?
To wait half a second between on and off states?
Yes! This gives us the blinking effect. Remember, to control time in programming, we use delays. Can anyone summarize what we've done in this example?
We programmed an LED to blink on and off continuously!
Well done! You've grasped the concept. Let's move on to another programming example.
Next, let's tackle the obstacle avoidance pseudocode. What is pseudocode?
It's a way to plan code without worrying about syntax.
Exactly! It helps us focus on the logic. Can anyone explain how the program works based on the pseudocode I shared?
It checks distance from an object and decides to stop or turn based on that!
Great job! The if statement allows the robot to make decisions based on sensor input. This is where conditionals come into play. Who can break down the loop for us?
It keeps checking the distance repeatedly.
Correct! This is fundamental for robotic behavior. Let's recap: 1. Pseudocode helps in planning, and 2. Conditionals let robots make decisions. Any questions?
The act of writing instructions for a robot to execute tasks.
A popular platform for creating electronic projects.
A basic program to test output behavior on a robot.
Descriptive code that outlines logic without strict syntax rules.
Logic structures that enable decision-making in programming.
When the LED shines bright, it’s a beautiful sight; On and off in a blink, it makes our robots think!
Imagine a robot walking down a pathway. It sees a wall ahead and uses its sensors to decide whether to stop or turn. This decision-making is like choosing a path in life!
Remember the phrase 'BLOOM' to recall: Blink (LED), Loop (repeat), Obstacle avoid (turn), Move (forward), and is a Program (set of instructions).
R.O.B.O.T: Respond to inputs, Operate on commands, Behave intelligently, Output actions, and Task performance.
Term
What is a program in robotics?
Click to flip
Term
What does the term 'pseudocode' mean?
Click to flip
Term
What function does a loop serve in programming?
Click to flip
A set of instructions that a computer or robot follows to perform specific tasks.
A compact integrated circuit designed to govern a specific operation in an embedded system.
A programming structure that repeats a sequence of instructions until a certain condition is met.
A statement that controls the flow of execution based on certain conditions being true or false.
A human-readable description of the steps in an algorithm or program.
This section introduces how to write a basic program for robotics, using examples like LED blinking and obstacle avoidance.
In this section, we learn to write simple programs that allow a robot to perform specific tasks. We explore examples like blinking an LED using Arduino and pseudocode for obstacle avoidance, highlighting crucial programming concepts such as loops and conditionals.
In this section, we dive into the practical side of robot programming by creating simple programs. Programs can range from very basic tasks to complex functionalities. Understanding how to write these programs is vital for enabling robots to perform tasks autonomously.
This example demonstrates how to blink an LED on an Arduino board:
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // LED on
delay(500);
digitalWrite(13, LOW); // LED off
delay(500);
}In this code:
setup() function runs once when you power the robot, while the loop() function runs continuously.This pseudocode example provides a logical sequence for avoiding obstacles:
while True:
distance = read_ultrasonic_sensor()
if distance < 10:
stop()
turn_right()
else:
move_forward()In this example:
By mastering these simple programming techniques, students will lay the groundwork for more complex robot behaviors.