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.
So, today we will learn how to program a microcontroller. Can anyone tell me what they think a microcontroller does?
Is it something like a small computer?
Yes, exactly! A microcontroller is like a mini-computer on a single chip. It can process inputs and control outputs in real-time. I'm going to use an example with the Arduino board, which is very popular for beginners.
What makes Arduino special compared to other microcontrollers?
Great question! Arduino is known for its ease of use and open-source nature, which makes it very accessible for hobbyists and beginners in robotics!
Now let’s look at a simple Arduino program to control an LED. What’s the first thing we need to do in our code?
We need to set the pin mode, right?
Correct! We use the setup function for that. Let’s write pinMode(13, OUTPUT); to set pin 13 as an output.
And then what happens in the loop function?
In the loop function, we control the LED by turning it on and off repeatedly. For instance, digitalWrite(13, HIGH); turns it on, and then we wait one second with delay(1000);. Who can tell me why we use delay here?
So that it stays on for a while before turning off?
Exactly! The delay allows us to control how long the LED remains in each state before switching.
Next, let’s talk about the tools we can use for programming. What tool do you think is commonly used for Arduino?
Is it the Arduino IDE?
Yes, it is! Arduino IDE is specifically designed to help program Arduino boards. Who can think of any other tools we can use?
Maybe Thonny for Raspberry Pi?
Absolutely! Thonny is great for programming in Python. Then, there’s also PlatformIO and MicroPython. Knowing a few options can help you choose the right environment for your projects.
Why would we need to use different tools?
Using the right tools can simplify the programming process and make it easier to integrate various technologies in your robotics projects.
A small, dedicated computer that executes control tasks.
A versatile programming tool designed for Arduino boards.
The initial setup for pin configurations in Arduino code.
A continuously executing section of code that runs after setup.
To blink an LED on and off, set pin mode, then start to scoff; in a loop it will play, on, off, every day!
Imagine a tiny skilled robot named Arduino, who loves to play with lights. Every second, he toggles an LED on and off, creating a sparkling dance show for all.
In the Arduino setup: 'Set Pin, Loop, Delay' (SPLD) to remember the order of commands.
PIL: Pin Initialization Loop - a quick acronym to remember the programming process for microcontrollers.
Term
What is a microcontroller?
Click to flip
Term
What is the purpose of the setup function?
Click to flip
Term
What does the loop function do?
Click to flip
Term
What is Arduino IDE?
Click to flip
A compact integrated circuit designed to govern a specific operation in an embedded system.
An open-source software used for programming Arduino boards using a simplified version of C/C++.
A function in Arduino used to set a digital pin as an input or output.
A function that controls the voltage level on a digital pin, effectively turning it on or off.
A function used to pause the program for a specified number of milliseconds.
The function in Arduino code that runs continuously after the setup function.
This section covers the basics of programming microcontrollers, particularly through the Arduino IDE.
In this section, the focus is on programming microcontrollers, with a detailed example using Arduino code to control an LED. The importance of utilizing various programming tools such as Arduino IDE and their role in developing robotics projects is discussed.
This section delves into the essential aspect of programming microcontrollers, specifically providing an example of Arduino programming. Microcontrollers serve as the central control unit in robotic systems, executing the algorithms that dictate operational behavior.
The provided example is structured in the Arduino programming language (C/C++), showcasing how to set up and execute tasks using microcontrollers. This includes:
void setup() {
pinMode(13, OUTPUT); // Set pin 13 as output
}void loop() {
digitalWrite(13, HIGH); // Turn LED on
delay(1000); // Wait 1 second
digitalWrite(13, LOW); // Turn LED off
delay(1000); // Wait 1 second
}Several programming environments are suggested for writing and uploading code to microcontrollers, including:
Understanding these programming practices is vital for controlling sensors and actuators, thus enabling the successful operation of robotic systems.