Table of Contents
- Project 1: Blinking LED
- Project 2: Button-Controlled LED
- Project 3: Temperature Sensor Display
- Project 4: Servo Motor Control
- Project 5: Ultrasonic Distance Sensor
- Conclusion
Project 1: Blinking LED
The blinking LED is the "Hello, World!" of Arduino projects. It introduces you to basic programming and hardware connections. This project requires minimal components and teaches you how to control a digital output pin.
Components Needed
- Arduino Uno
- LED
- 220-ohm resistor
- Breadboard
- Jumper wires
Steps
- Connect the LED’s anode (longer leg) to Arduino pin 13 via the resistor.
- Connect the LED’s cathode (shorter leg) to the Arduino’s GND pin.
- Upload the following code to your Arduino.
Code
void setup() {
pinMode(13, OUTPUT); // Set pin 13 as output
}
void loop() {
digitalWrite(13, HIGH); // Turn LED on
delay(1000); // Wait for 1 second
digitalWrite(13, LOW); // Turn LED off
delay(1000); // Wait for 1 second
}
How It Works
The setup()
function configures pin 13 as an output. The loop()
function repeatedly turns the LED on and off with a one-second delay. This project helps you understand the Arduino IDE, pin configuration, and basic timing functions. It’s a great starting point because it’s simple yet demonstrates the core concepts of Arduino programming.
Project 2: Button-Controlled LED
This project builds on the first by adding a pushbutton to control the LED. It introduces digital input and conditional statements, key concepts for interactive projects.
Components Needed
- Arduino Uno
- LED
- 220-ohm resistor
- Pushbutton
- 10k-ohm resistor
- Breadboard
- Jumper wires
Steps
- Connect the LED as in Project 1 (anode to pin 13 via resistor, cathode to GND).
- Connect one side of the pushbutton to Arduino pin 2 and the other to GND via the 10k-ohm resistor (pull-down resistor).
- Connect the same side of the pushbutton to 5V.
- Upload the code below.
Code
int buttonPin = 2; // Button connected to pin 2
int ledPin = 13; // LED connected to pin 13
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(buttonPin, INPUT); // Set button pin as input
}
void loop() {
buttonState = digitalRead(buttonPin); // Read button state
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
}
How It Works
The code reads the button’s state using digitalRead()
. When the button is pressed (HIGH), the LED turns on; otherwise, it stays off. The pull-down resistor ensures a stable LOW state when the button isn’t pressed. This project teaches you about digital inputs, conditional logic, and basic circuit design, making it a natural progression from the blinking LED.
Project 3: Temperature Sensor Display
This project uses a temperature sensor to measure ambient temperature and display it on the Serial Monitor. It introduces analog inputs and sensor interfacing, which are essential for environmental monitoring projects.
Components Needed
- Arduino Uno
- TMP36 temperature sensor
- Breadboard
- Jumper wires
Steps
- Connect the TMP36’s VCC pin to Arduino’s 5V pin.
- Connect the TMP36’s GND pin to Arduino’s GND pin.
- Connect the TMP36’s signal pin to Arduino’s A0 pin.
- Upload the code below and open the Serial Monitor (9600 baud).
Code
int sensorPin = A0; // TMP36 connected to analog pin A0
void setup() {
Serial.begin(9600); // Start Serial communication
}
void loop() {
int reading = analogRead(sensorPin); // Read sensor value
float voltage = reading * (5.0 / 1024.0); // Convert to voltage
float temperatureC = (voltage - 0.5) * 100; // Convert to Celsius
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" C");
delay(1000); // Update every second
}
How It Works
The TMP36 outputs a voltage proportional to the temperature. The Arduino’s analog-to-digital converter (ADC) reads this voltage, which is converted to Celsius using the sensor’s formula. The result is printed to the Serial Monitor. This project introduces analog inputs, sensor calibration, and Serial communication, providing a foundation for more complex sensor-based projects.
Project 4: Servo Motor Control
This project uses a servo motor to create controlled motion, useful for robotics or automation. It introduces the Servo library and PWM (pulse-width modulation) control, which are critical for precise actuator control.
Components Needed
- Arduino Uno
- Servo motor (e.g., SG90)
- Breadboard
- Jumper wires
Steps
- Connect the servo’s red wire to Arduino’s 5V pin.
- Connect the servo’s brown/black wire to Arduino’s GND pin.
- Connect the servo’s orange/yellow (signal) wire to Arduino pin 9.
- Upload the code below.
Code
#include <Servo.h>
Servo myServo; // Create Servo object
void setup() {
myServo.attach(9); // Attach servo to pin 9
}
void loop() {
myServo.write(0); // Move to 0 degrees
delay(1000); // Wait 1 second
myServo.write(90); // Move to 90 degrees
delay(1000); // Wait 1 second
myServo.write(180); // Move to 180 degrees
delay(1000); // Wait 1 second
}
How It Works
The Servo library simplifies motor control by generating PWM signals. The write()
function sets the servo’s angle (0 to 180 degrees). This project demonstrates how to use libraries and control actuators, making it a stepping stone for robotics and automation projects. The smooth motion of the servo also makes it engaging for beginners.
Project 5: Ultrasonic Distance Sensor
This project uses an ultrasonic sensor to measure distance, a common technique in robotics and proximity detection. It introduces timing-based sensor interfacing and data processing, building on the skills from previous projects.
Components Needed
- Arduino Uno
- HC-SR04 ultrasonic sensor
- Breadboard
- Jumper wires
Steps
- Connect the HC-SR04’s VCC pin to Arduino’s 5V pin.
- Connect the HC-SR04’s GND pin to Arduino’s GND pin.
- Connect the HC-SR04’s TRIG pin to Arduino pin 11.
- Connect the HC-SR04’s ECHO pin to Arduino pin 12.
- Upload the code below and open the Serial Monitor (9600 baud).
Code
int trigPin = 11; // TRIG pin
int echoPin = 12; // ECHO pin
void setup() {
Serial.begin(9600); // Start Serial communication
pinMode(trigPin, OUTPUT); // Set TRIG pin as output
pinMode(echoPin, INPUT); // Set ECHO pin as input
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH); // Measure echo duration
float distance = duration * 0.034 / 2; // Convert to distance (cm)
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000); // Update every second
}
How It Works
The HC-SR04 sends an ultrasonic pulse when the TRIG pin is activated. The ECHO pin measures the time it takes for the pulse to return after bouncing off an object. This duration is converted to distance using the speed of sound (approximately 0.034 cm/µs). The result is printed to the Serial Monitor. This project teaches you about timing, sensor interfacing, and real-world applications like obstacle detection.
Conclusion
These five Arduino projects provide a solid foundation for beginners, covering essential concepts like digital and analog inputs, outputs, sensors, actuators, and libraries. Starting with the simple blinking LED, you’ve progressed to interactive buttons, environmental sensing, precise motor control, and distance measurement. Each project builds on the previous one, introducing new skills while keeping the complexity manageable.
Arduino’s open-source ecosystem makes it easy to expand on these projects. Try combining them—perhaps add a button to control the servo or display the ultrasonic sensor’s data on an LCD. The possibilities are endless, and the skills you’ve learned here are transferable to more advanced projects like home automation or robotics.
To continue your Arduino journey, explore the Arduino community forums, experiment with new sensors, and consider adding displays or wireless modules to your projects. With practice, you’ll be building sophisticated systems in no time. Happy tinkering!