Blink Built-In LED on UNO
Introduction
In this exercise, you will learn how to write a simple C program to control the built-in LED on the Arduino Uno. This is a common introductory project that helps beginners get familiar with basic programming and interfacing with hardware. The program will make the built-in LED blink on and off at regular intervals, showcasing how to control digital outputs on the Arduino.
Objectives
By the end of this exercise, you will:
- Understand how to write a basic C program for an Arduino.
- Learn how to control digital output pins on the Arduino Uno.
- Gain hands-on experience in uploading and running programs on the Arduino platform.
- Understand the basic concepts of embedded programming.
Materials
To complete this exercise, you will need:
- Computer: A desktop or laptop for writing, compiling, testing, and debugging code.
- Monitor: A display to visualize the Arduino IDE and observe program outputs.
- Arduino Uno: The microcontroller board used for running the program and controlling the hardware.
Preparation Steps
- Install the Arduino IDE on your computer if it's not already installed.
- Connect your Arduino Uno to the computer via a USB cable.
- Launch the Arduino IDE and ensure the correct board and port are selected:
- Go to Tools > Board > Arduino Uno.
- Go to Tools > Port and select the appropriate port for your Arduino.
- Open the Arduino IDE and start a new sketch (program).
Execution Steps
In the Arduino IDE, write the following code:
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the built-in LED pin as an output
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second (1000 milliseconds)
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off
delay(1000); // Wait for 1 second (1000 milliseconds)
}
Click the Upload button (right arrow) in the Arduino IDE to compile and upload the program to the Arduino Uno.
- Once uploaded, you should see the built-in LED on the Arduino Uno blink on and off every second.
Further Reading
For further study, you can explore the following resources:
- Arduino Official Website – A comprehensive resource for everything Arduino.
- Arduino IDE Documentation – Learn more about using the Arduino IDE.
- Introduction to C Programming for Arduino – A beginner's guide to programming in C for Arduino.