The Arduino Uno is a versatile microcontroller used in a wide range of applications, from simple LED control to complex IoT and automation projects. In this section, we’ll explore some practical use cases for the Arduino Uno, discussing the components, code, and steps required for each project. These examples will help illustrate the potential of the Arduino platform for real-world applications.
LED Blinking and Control
Controlling LEDs is one of the most basic but essential Arduino projects. It demonstrates fundamental programming concepts and introduces students to working with digital pins.
Project Overview
- Objective: To control the blinking of an LED and vary its brightness using Pulse Width Modulation (PWM).
- Components:
- 1 LED
- 1 220Ω resistor
- Jumper wires
- Arduino Uno
#STEPS:
- Connect the LED:
- Connect the positive (longer) leg of the LED to pin 9 through a 220Ω resistor.
- Connect the negative (shorter) leg to the GND pin.
- Write the Code:
- The code below turns the LED on and off and then uses PWM to adjust brightness.
void setup() {
pinMode(9, OUTPUT); // Set pin 9 as an output
}
void loop() {
digitalWrite(9, HIGH); // Turn LED on
delay(500); // Wait 500 ms
digitalWrite(9, LOW); // Turn LED off
delay(500); // Wait 500 ms
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(9, brightness); // Adjust brightness
delay(10); // Small delay for gradual increase
}
}
This project teaches essential concepts, such as using digitalWrite() for turning the LED on and off and analogWrite() for PWM control. It’s ideal for beginners who want to get comfortable with Arduino programming.
Temperature and Humidity Monitoring
This project demonstrates how to use the Arduino Uno to measure environmental conditions. By connecting a DHT11 or DHT22 sensor, students can monitor temperature and humidity levels and display the data on the Serial Monitor.
Project Overview
- Objective: To measure temperature and humidity and display the data in the Serial Monitor.
- Components:
- DHT11 or DHT22 sensor
- Jumper wires
- Arduino Uno
#STEPS:
- Connect the DHT Sensor:
- Connect the VCC pin of the DHT sensor to the 5V pin on the Arduino.
- Connect the GND pin of the sensor to the GND pin.
- Connect the data pin of the sensor to digital pin 2.
- Install the DHT Library:
- In the Arduino IDE, go to Sketch > Include Library > Manage Libraries… and search for “DHT sensor library” by Adafruit. Install it.
- Write the Code:
- The code below reads the temperature and humidity values from the sensor and displays them.
#include <DHT.h>
#define DHTPIN 2 // DHT sensor connected to pin 2
#define DHTTYPE DHT11 // Define the sensor type (DHT11 or DHT22)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(2000); // Wait 2 seconds before repeating
}
This project introduces students to working with libraries, handling analog and digital sensors, and reading serial output. Such a setup is useful for weather monitoring or indoor environment control systems.
Light-Activated Automation with an LDR
An LDR (Light Dependent Resistor) can detect light levels, making it useful for projects that need to react to lighting conditions. This project uses an LDR to automatically turn on an LED when it’s dark.
Project Overview
- Objective: To create a light-sensitive system that turns on an LED when ambient light levels drop.
- Components:
- 1 LDR
- 1 10kΩ resistor
- 1 LED
- Jumper wires
- Arduino Uno
#STEPS:
- Set Up the Circuit:
- Connect the LDR in series with the 10kΩ resistor, creating a voltage divider.
- Connect one end of the voltage divider to 5V and the other to GND.
- Connect the point between the LDR and resistor to analog pin A0.
- Connect the LED to digital pin 9 through a 220Ω resistor.
- Write the Code:
- The code reads the LDR value and controls the LED accordingly.
int LDRPin = A0;
int LEDPin = 9;
int threshold = 500; // Define a threshold for darkness
void setup() {
pinMode(LEDPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int LDRValue = analogRead(LDRPin);
Serial.println(LDRValue); // Print LDR value to Serial Monitor
if (LDRValue < threshold) {
digitalWrite(LEDPin, HIGH); // Turn LED on in darkness
} else {
digitalWrite(LEDPin, LOW); // Turn LED off in light
}
delay(1000);
}
This project demonstrates how sensors can be used to create automated responses, a foundational concept in robotics and IoT applications.
Motion Detection with an Ultrasonic Sensor
An ultrasonic sensor can detect obstacles or measure distances, making it valuable in security or automation projects. This project uses an ultrasonic sensor to measure distance and turn on an LED when an object is detected within a specific range.
Project Overview
- Objective: To detect the presence of an object within a certain range.
- Components:
- HC-SR04 ultrasonic sensor
- 1 LED
- Jumper wires
- Arduino Uno
#STEPS:
- Connect the Ultrasonic Sensor:
- Connect VCC to 5V, GND to GND, Trig to pin 9, and Echo to pin 10.
- Write the Code:
- The code below measures the distance and lights up an LED if an object is closer than 30 cm.
#define trigPin 9
#define echoPin 10
#define LEDPin 13
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
int distance = duration * 0.034 / 2; // Calculate distance in cm
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance < 30) {
digitalWrite(LEDPin, HIGH); // Turn on LED if object is close
} else {
digitalWrite(LEDPin, LOW);
}
delay(500);
}
This project introduces students to the concepts of time-based measurements and ultrasonic distance calculation. Applications include proximity alarms, automatic doors, and obstacle detection systems.
IoT Data Logging with a DHT Sensor and Wi-Fi Module
Using the Arduino Uno with a Wi-Fi module like the ESP8266 allows students to create IoT projects where data is logged or monitored remotely. This project sends data from a DHT11 sensor to a cloud server for remote access.
Project Overview
- Objective: To send temperature and humidity data to a remote server for IoT-based data logging.
- Components:
- DHT11 sensor
- ESP8266 Wi-Fi module
- Jumper wires
- Arduino Uno
#STEPS:
- Connect the DHT11 and ESP8266:
- Connect the DHT sensor as in the previous example.
- Connect the ESP8266 module’s TX to Arduino RX, RX to Arduino TX (using a voltage divider if necessary for 3.3V logic), VCC to 3.3V, and GND to GND.
- Write the Code:
- This code sends data to a remote server (replace YOUR_SERVER with the server URL or IP).
#include <DHT.h>
#include <SoftwareSerial.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial espSerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
espSerial.begin(115200);
dht.begin();
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
String data = "Temperature=" + String(temperature) + "&Humidity=" + String(humidity);
espSerial.print("AT+CIPSTART=\"TCP\",\"YOUR_SERVER\",80\r\n");
delay(1000);
espSerial.print("AT+CIPSEND=" + String(data.length() + 16) + "\r\n");
delay(1000);
espSerial.print("POST /data HTTP/1.1\r\n");
espSerial.print("Host: YOUR_SERVER\r\n");
espSerial.print("Content-Length: " + String(data.length()) + "\r\n\r\n");
espSerial.print(data);
delay(2000);
}
This project introduces IoT concepts and demonstrates how to send data over the internet, making it highly relevant in the context of smart home and data logging applications.