Skip to content

Blinking an LED

Slides

F for fullscreen · O for overview

Arduino IDE

Robot booted setup() loop()
Arduino IDE and program flowchart

LED on the robot

LED Module

led schematic

LED is connected to pin 11 of the Arduino Uno
int ledpin=11;                 //(1)
void setup() {
  pinMode(ledpin, OUTPUT);     //(2)
}
void loop() {
  digitalWrite(ledpin, HIGH);  //(3)
  delay(1000);                 //(5)
  digitalWrite(ledpin, LOW);   //(4)
  delay(1000);
}
  1. Define a variable ledpin to be 11
  2. Initialize the ledpin as output
  3. By sending the HIGH signal, we are giving the LED a high voltage level. Typically for microcontroller, this is 3.3V or 5V.
  4. The LOW signal gives the LED a low voltage level, which is close or equal to 0V.
  5. Time delay between two commands. The time is defined with the unit of milliseconds.

Verify and upload the program to the Arduino Uno (the microcontroller of the robot)

Connecting the robot to the computer

Connect to the USB-B port of the robot

Verify COM port

port detected

Check if the Arduino IDE detects the Arduino Uno port

Verify and upload the program

Click to verify if the code has any error

You can use the "verify" button even when you are not connected to a microcontroller to check your code.

If no error, there will be "Done compiling"
Click to upload the code to Arduino Uno
If no error, there will be "Done uploading"

After the code is uploaded, you should see the LED blinking at a rate of 1 second of light on and 1 second of light off.

Bring it further

  1. How do we make the LED blinking at a faster or slower speed?
  2. Can we blink the LED with the following pattern?

    3 sec on → 1 sec off → 2 sec on → 0.5 sec off → repeat