Arduino 101
Getting Started with Your First Arduino Project
Now that you have a basic understanding of Arduino hardware and software, let’s dive into some hands-on projects. Here's a simple example to get you started:
Project 1a: On-board LED Blink
Objective: Blink an LED connected to the Arduino board. This project requires only an Arduino board and a USB-B cable. We will use Arduino UNO and the on-board LED lamp connected to pin 13 of the UNO.
Components Needed:
Arduino UNO board
Steps:
Write the Code:
Open the Arduino IDE.
Write the following code:
void setup() {
pinMode(13, OUTPUT); // initialize digital pin 13 as an output.
}
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
OR
Start the Arduino IDE
Open the “LED blink” example sketch: File -> Examples -> 01.Basics -> Blink
2. Upload the Code:
Connect your Arduino board to your computer using a USB cable.
Select your board and port from the Tools menu.
Click the Upload button (right arrow icon) in the Arduino IDE toolbar.
3. Observe:
The LED should start blinking, turning on for one second and off for one second.
If it does, congratulations! You have successfully configured your Arduino hardware and software.
Project 1b. External LED Blink
This project requires an Arduino board, LED diode, 200 ohm or equivalent resistor, breadboard (optional), and a USB-B cable.
In this project, you'll learn how to make an LED blink using an Arduino board. This is a fundamental project that introduces you to the basics of Arduino programming and circuit building.
Components Needed
Arduino board (e.g., Arduino UNO)
LED diode
200-ohm resistor (or equivalent)
Breadboard (optional, for easier wiring)
USB-B cable (for connecting the Arduino to your computer)
Jumper wires
Steps to Complete the Project
Step 1: Circuit Setup
Connect the LED:
Anode (longer leg) of the LED: Connect to digital pin 13 on the Arduino.
Cathode (shorter leg) of the LED: Connect to one end of the 200-ohm resistor.
The other end of the resistor: Connect to the GND (ground) pin on the Arduino.
Using a Breadboard (Optional):
Place the LED and resistor on the breadboard.
Use jumper wires to connect the anode of the LED to pin 13 on the Arduino.
Use another jumper wire to connect the other end of the resistor to the GND pin on the Arduino.
Step 2: Write the Code
Open the Arduino IDE:
If you haven't already, download and install the Arduino IDE from the official Arduino website.
Create a New Sketch:
Open the Arduino IDE and create a new sketch.
Write the Blinking LED Code:
Enter the following code into the Arduino IDE:
void setup() {
// Initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
void loop() {
// Turn the LED on (HIGH is the voltage level).
digitalWrite(13, HIGH);
// Wait for a second.
delay(1000);
// Turn the LED off by making the voltage LOW.
digitalWrite(13, LOW);
// Wait for a second.
delay(1000);
}
Step 3: Upload the Code
Connect the Arduino:
Use the USB-B cable to connect your Arduino board to your computer.
Select the Board and Port:
In the Arduino IDE, go to Tools > Board and select your Arduino model (e.g., Arduino UNO).
Go to Tools > Port and select the port that corresponds to your Arduino.
Upload the Sketch:
Click the Upload button (right arrow icon) in the Arduino IDE toolbar.
Wait for the code to compile and upload to the Arduino board.
Step 4: Observe the Blinking LED
Once the code is uploaded, the LED connected to pin 13 should start blinking. It will turn on for one second and off for one second repeatedly.
If the LED starts to blink, You have successfully done 1b
Note: if you don’t have a resistor, you can connect the LED directly to the UNO pins but the LED will be more bright. If you do so, please be nice to your eyes!
Project 2. Controlling LED Brightness With a Potentiometer
In this tutorial, we'll learn how to control the brightness of an LED using a potentiometer with Arduino. A potentiometer is a variable resistor that can be adjusted to provide different voltage levels. By connecting it to an analog input of the Arduino, we can adjust the brightness of an LED.
What You Will Learn:
How to read analog signals from a potentiometer using Arduino.
How to control the brightness of an LED with Pulse Width Modulation (PWM).
Components Needed:
Arduino Uno (or any compatible board)
Breadboard
LED (any color)
220Ω resistor (to limit the current to the LED)
Potentiometer (10kΩ recommended)
Jumper wires
Circuit Diagram
The circuit diagram for this project can be constructed using the online Circuit CAD, a free tool by Autodesk. This online platform, known as Tinkercad Circuits, allows users to create, simulate, and test electronics circuits directly in their web browsers without needing to download any software.
Tinkercad Circuits is ideal for beginners and Arduino enthusiasts, as it provides an intuitive interface and includes a library of electronic components, including Arduino boards, LEDs, resistors, and potentiometers.
You can access the online Circuit CAD through Autodesk's Tinkercad website to build and simulate your own circuits: [Tinkercad Circuits](https://www.tinkercad.com/circuits).
Step-by-Step Instructions:
Step 1: Connect the Potentiometer
The potentiometer has three pins:
The left pin connects to 5V on the Arduino.
The right pin connects to GND (ground).
The middle pin (wiper) connects to A0 (analog input pin) on the Arduino.
Step 2: Connect the LED
Connect the long leg (anode) of the LED to digital pin 9 (this is a PWM pin on the Arduino).
Connect the short leg (cathode) to one end of the 220Ω resistor, and connect the other end of the resistor to GND.
Step 3: Upload the Code
Once the code is uploaded, observe the intensity of the LED changing as you rotate the potentiometer.
/* Control LED Brightness With a Potentiometer
By. Fekadu Debebe
Sept 20/2020
*/
// Constants
const int potPin = A0; // Potentiometer pin
const int ledPin = 9; // PWM pin connected to the LED
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the potentiometer value (0 to 1023)
int potValue = analogRead(potPin);
// Map the pot value to the PWM range (0 to 255)
int brightness = map(potValue, 0, 1023, 0, 255);
// Set the brightness of the LED
analogWrite(ledPin, brightness);
// Small delay for better stability
delay(10);
}
Step 4: How It Works
Potentiometer Reading: The analogRead() function reads the value from the potentiometer, which returns a number between 0 and 1023. This corresponds to the position of the potentiometer.
the 10K potentiometer provides values between 0 and 1023, as it is read by the analogRead() function. However, the PWM signal for controlling LED brightness expects a value between 0 and 255.
Mapping the Value: Since the PWM output expects a value between 0 and 255, we use the map() function to convert the 0-1023 range from the potentiometer to 0-255.
Controlling the LED Brightness: The analogWrite() function controls the LED brightness by outputting a PWM signal. The higher the value, the brighter the LED.
If you have enjoyed the Arduino beginner tutorial, then check out the intermediate projects under "Arduino 102" section of this website.
»»» END of Arduino 101 »»»