Arduino UNO R4 - Blink LED

This tutorial instructs you on how to control an LED using the Arduino UNO R4. You will learn how to write a program for the Arduino UNO R4 to turn an LED on and off, as well as how to make the LED blink.

Arduino UNO R4 Blink LED

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×LED
1×220 ohm resistor
1×Breadboard
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of LED

Pinout

LED has two pins:

  • Cathode (-) pin: connect to GND (0V)
  • Anode (+) pin: controls the LED's state
LED Pinout

How It Works

After connecting the negative end (cathode) to the ground (GND):

  • When the ground (GND) is connected to the positive side (anode +) of the LED, it will be OFF.
  • When the power supply (VCC) is connected to the positive side (anode +) of the LED, it will be ON.
How LED Works

Additionally, by applying a PWM signal to the anode (+), you can adjust the LED brightness based on the PWM value (explained in detail in this tutorial).

※ NOTE THAT:

Most LEDs require a resistor. You can connect the resistor to the positive side (anode) and the power supply (VCC) or to the negative side (cathode) and the ground (GND). The resistor's value varies based on the LED's specifications. Some LEDs come with a resistor already included. For these LEDs, you might not need an additional resistor.

Arduino UNO R4 - LED

When you set a pin on the Arduino UNO R4 as a digital output, you can program it to control the voltage, making it either GND (Ground) or VCC (Power). To control an LED, connect the Arduino UNO R4's pin to the positive (+) pin of the LED via a resistor.

Wiring Diagram

The wiring diagram between Arduino UNO R4 LED

This image is created using Fritzing. Click to enlarge image

How To Program

  • Set up a digital output mode for an Arduino UNO R4 pin using the pinMode() function. For instance, for pin 9:
pinMode(9, OUTPUT);
  • Set the pin to GND to switch off the LED using the digitalWrite() function.
digitalWrite(9, LOW);
  • Set the pin to VCC to switch on the LED using the digitalWrite() function.
digitalWrite(9, HIGH);

Arduino UNO R4 Code

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-blink-led */ #define LED_PIN 9 // The Arduino UNO R4 pin connected to the LED // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 9 as an output. pinMode(LED_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(500); // wait for 500 milliseconds digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(500); // wait for 500 milliseconds }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect LED to Arduino Uno R4 according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the above code and paste it into the Arduino IDE
  • Click the Upload button in Arduino IDE to send code to Arduino UNO R4.
Arduino IDE - How to Upload Code
  • Check out the LED status

Code Explanation

The explanation is in the comments section of the Arduino code above.

※ NOTE THAT:

  • The above code uses the delay() function. This function blocks the Arduino UNO R4 from doing other tasks. If your project needs to do multiple tasks at the same time, you should avoid blocking the Arduino UNO R4. Instead, use a non-blocking method for Arduino UNO R4.
  • This guide provides detailed information to help you understand how it works. To control LED easily, you can use the Arduino UNO R4 - LED library.

Video Tutorial

Additional Knowledge

Which pins on the Arduino UNO R4 can be used to control an LED as output pins?

  • Pin 0 to 13
  • Pin A0 to A5

※ NOTE THAT:

Only use each pin for one function at a time. For instance, if you already assigned a pin for tasks like digital input or PWM, do not use the same pin to control an LED as a digital output. Particularly, do not use pins 0 and 1 for other tasks if you are using the Serial.println() function, because these pins are dedicated for Serial communication.

Function References

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!