π‘ Blinking LED
Your very first circuit β make an LED twinkle like a star!
π What you will make
An LED that turns ON for one second, then OFF for one second β forever! This is the classic "Hello World!" of electronics. If you can do this, you can do anything in this book.
π§ How it works
The Arduino is a tiny computer. We tell pin D13 to push electricity out (that turns the LED ON), then tell it to stop (LED OFF). The delay(1000) line makes it wait 1000 milliseconds = 1 second between changes.
The resistor protects the LED β too much electricity would make it pop! π₯
π Wire it up
π See the table below for the exact connections.
| From (Arduino / part) | To (part) | Wire color |
|---|---|---|
| D13 | Resistor one leg β LED long leg | Orange |
| GND | LED short leg | Black |
π» The Code
// PROJECT 1: Blinking LED
// The LED turns ON and OFF, again and again... like a twinkling star!
int ledPin = 13; // The LED is connected to pin 13
void setup() {
pinMode(ledPin, OUTPUT); // Tell the pin: "You send electricity out!"
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn the LED ON
delay(1000); // Wait 1 second
digitalWrite(ledPin, LOW); // Turn the LED OFF
delay(1000); // Wait 1 second
}
π‘ Copy everything from int ledPin to the last }.
π Test it!
- Connect everything exactly like the picture (power OFF!).
- Plug in the USB cable and upload the code.
- Watch the LED blink β ON, OFF, ON, OFFβ¦ β
- If it doesn't light up, turn the LED legs around!
π Try this!
- Change
delay(1000)todelay(100)β now it blinks super fast! - Make a pattern: blink twice fast, then once slow.
- Connect 3 LEDs to pins 13, 12 and 11 β make them blink in a wave π.
π¦ Traffic Light
Build a real traffic light β red, yellow, green, GO!
π What you will make
Three LEDs that change exactly like a real traffic light: Red β Yellow β Green β Yellow β Redβ¦ Cars would be very impressed. π
π§ How it works
Each LED has its own pin (D2, D3, D4). We turn one ON and the others OFF, wait, then switch. The delay() decides how long each light stays.
π Wire it up
π Tip: on a breadboard you can join all the short legs to the long black (β) rail.
| From (Arduino) | To (LED) | Wire color |
|---|---|---|
| D2 β resistor | Red LED long leg | Orange |
| D3 β resistor | Yellow LED long leg | Orange |
| D4 β resistor | Green LED long leg | Orange |
| GND | All 3 LED short legs (join them on the β rail) | Black |
π» The Code
// PROJECT 2: Traffic Light
// Red, yellow, green... just like a real crossing!
int red = 2; // Red LED on pin 2
int yellow = 3; // Yellow LED on pin 3
int green = 4; // Green LED on pin 4
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop() {
digitalWrite(red, HIGH); // Red ON
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
delay(3000); // Cars stop for 3 seconds
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH); // Yellow ON
delay(1000);
digitalWrite(yellow, LOW);
digitalWrite(green, HIGH); // Green ON - GO!
delay(3000);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH); // Yellow again
delay(1000);
digitalWrite(yellow, LOW);
}
π Test it!
- Wire the 3 LEDs exactly like the picture.
- Upload the code and watch the lights change.
- Count the seconds β is it like a real traffic light?
π Try this!
- Make the green light blink 3 times before turning yellow (like some real lights!).
- Add a 4th LED as a "walking man" πΆ that turns on when the cars stop.
π΅ Melody Maker
Press a button and the buzzer plays a real song!
π What you will make
Press the button and the buzzer plays "Twinkle Twinkle Little Star"! β¨ The Arduino becomes a little music box.
π§ How it works
Every note is just a frequency β how fast the buzzer wiggles. The tone() command plays a note, and noTone() stops it. We store the song as two lists: the notes and how long each one lasts.
The button uses INPUT_PULLUP: when pressed, the pin reads LOW (0).
π Wire it up
π Buzzer legs: one long (+), one short (β). Button: use any two opposite legs.
| From (Arduino) | To (part) | Wire color |
|---|---|---|
| D8 | Buzzer + leg | Orange |
| GND | Buzzer β leg | Black |
| D7 | Button one leg | Orange |
| GND | Button other leg | Black |
π» The Code
// PROJECT 3: Melody Maker
// Press the button and the buzzer plays Twinkle Twinkle Little Star!
int buttonPin = 7; // Button on pin 7
int buzzerPin = 8; // Buzzer on pin 8
// The notes of the song (frequency in Hertz)
int melody[] = { 262, 262, 392, 392, 440, 440, 392,
349, 349, 330, 330, 294, 294, 262 };
// How long each note plays (milliseconds)
int noteTime[] = { 400, 400, 400, 400, 400, 400, 800,
400, 400, 400, 400, 400, 400, 800 };
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Button with built-in helper
pinMode(buzzerPin, OUTPUT);
}
void loop() {
if (digitalRead(buttonPin) == LOW) { // If the button is pressed
for (int i = 0; i < 14; i++) { // Play every note one by one
tone(buzzerPin, melody[i]); // Start the note
delay(noteTime[i]); // Let it play
}
noTone(buzzerPin); // Stop playing
delay(500);
}
}
π Test it!
- Wire the buzzer and button like the picture.
- Upload the code.
- Press and hold the buttonβ¦ and sing along! π€
π Try this!
- Change the numbers in
melody[]to write your own song! Bigger number = higher note. - Make it play "Happy Birthday" β the tune is: 262,262,294,262,349,330β¦
- Add a blinking LED that flashes with the music (like a concert!).
π SOS Signal
Send a real SOS with light and sound β like a sailor in trouble!
π What you will make
Press the button and your Arduino sends SOS β the world-famous "help me!" signal: 3 short, 3 long, 3 short (β¦ --- β¦) with flashing light and beeping sound!
π§ How it works
We write two helper functions: dot() (quick blink + beep) and dash() (long blink + beep). Then sending SOS is as easy as saying: dot, dot, dot, dash, dash, dash, dot, dot, dot!
π Wire it up
| From (Arduino) | To (part) | Wire color |
|---|---|---|
| D13 β resistor | LED long leg | Orange |
| GND | LED short leg | Black |
| D8 | Buzzer + leg | Orange |
| GND | Buzzer β leg | Black |
| D7 | Button one leg | Orange |
| GND | Button other leg | Black |
π» The Code
// PROJECT 4: SOS Signal
// Press the button: ... --- ... (SOS) with light AND sound!
int ledPin = 13;
int buzzerPin = 8;
int buttonPin = 7;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(buttonPin) == LOW) { // Button pressed?
dot(); dot(); dot(); // S = short short short
dash(); dash(); dash(); // O = long long long
dot(); dot(); dot(); // S = short short short
delay(1500); // Rest before the next SOS
}
}
// A short blink + beep
void dot() {
digitalWrite(ledPin, HIGH);
tone(buzzerPin, 1000);
delay(200);
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
delay(200);
}
// A long blink + beep
void dash() {
digitalWrite(ledPin, HIGH);
tone(buzzerPin, 1000);
delay(600);
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
delay(200);
}
π Test it!
- Wire everything like the picture.
- Upload the code and press the button.
- Count the beeps: 3 short, 3 long, 3 short β that's SOS! π
π Try this!
- Make it send your name in Morse code. A = dot-dash, B = dash-dot-dot-dotβ¦
- Hold the button and let it SOS forever (loop forever instead of once).
π¦Ύ Servo with Buttons
Three buttons move a robot arm left, right⦠and back home!
Servo library
π What you will make
Three buttons control a servo (a motor that turns to exact angles): left button turns it left, right button turns it right, and home button pops it back to the middle. It's like a tiny robot arm controller! π€
π§ How it works
The Servo library is a ready-made helper. We just say myServo.write(angle) and the servo turns to that angle (0Β° to 180Β°). Each button press changes the angle a little. The servo has 3 wires: orange = signal (tells it where to go), red = power (5V), brown = ground (GND).
π Wire it up
| From (Arduino) | To (part) | Wire color |
|---|---|---|
| D9 | Servo orange wire (signal) | Orange |
| 5V | Servo red wire (power) | Red |
| GND | Servo brown wire + all 3 button one-legs | Black |
| D2 | LEFT button other leg | Orange |
| D3 | RIGHT button other leg | Orange |
| D4 | HOME button other leg | Orange |
π» The Code
// PROJECT 5: Servo with Buttons
// LEFT = turn left, RIGHT = turn right, HOME = back to the middle!
#include <Servo.h>
Servo myServo; // Make a servo object
int leftButton = 2; // Left button
int rightButton = 3; // Right button
int homeButton = 4; // Home button
int angle = 90; // Servo starts at 90 degrees
void setup() {
myServo.attach(9); // Signal wire on pin 9
pinMode(leftButton, INPUT_PULLUP);
pinMode(rightButton, INPUT_PULLUP);
pinMode(homeButton, INPUT_PULLUP);
myServo.write(angle); // Start in the middle
delay(300);
}
void loop() {
if (digitalRead(leftButton) == LOW) {
angle = angle - 5; // Turn a little to the left
}
if (digitalRead(rightButton) == LOW) {
angle = angle + 5; // Turn a little to the right
}
if (digitalRead(homeButton) == LOW) {
angle = 90; // Jump back to the middle
}
if (angle < 0) angle = 0; // Don't go past 0Β°
if (angle > 180) angle = 180; // Don't go past 180Β°
myServo.write(angle); // Move the servo!
delay(20); // A tiny pause so it feels smooth
}
π Test it!
- Wire the servo and buttons like the picture (servo red to 5V!).
- Upload the code.
- Hold LEFT or RIGHT β watch the arm swing. Press HOME β snap back!
π Try this!
- Tape a paper arrow to the arm and make a weather vane π¬οΈ.
- Change
5to20in the buttons β the arm jumps in bigger steps! - Use HOME as a "yes/no" pointer and play 20 questions with a friend.
π Ultrasonic Distance Meter
Measure how far things are β and show it on a screen!
π What you will make
A device that sends a sound "ping", listens for the echo, and shows "Distance: 25 cm" on the screen β just like a bat finding its way in the dark! π¦
π§ How it works
The sensor shoots an ultrasonic ping (too high for humans to hear) and measures how long it takes to bounce back. Sound travels about 0.034 cm per microsecond, and it goes there and back, so we halve the answer.
The LCD uses I2C β a clever "two-wire" chat system β so it only needs SDA (data) and SCL (clock) wires.
π Wire it up
| From (Arduino) | To (HC-SR04) | Wire color |
|---|---|---|
| 5V | VCC | Red |
| D7 | Trig | Orange |
| D6 | Echo | Orange |
| GND | GND | Black |
| From (Arduino) | To (LCD I2C) | Wire color |
| 5V | VCC | Red |
| GND | GND | Black |
| A4 | SDA | Green |
| A5 | SCL | Green |
π Libraries you need
For this project (and projects 13 & 14) we use the LiquidCrystal_I2C library. In the Arduino app: Sketch β Include Library β Manage Libraries, search LiquidCrystal I2C by Frank de Brabander, and click Install. Done!
π» The Code
// PROJECT 6: Distance Meter
// Measure distances and show them on the LCD screen!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Our 16x2 screen
int trigPin = 7;
int echoPin = 6;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.init(); // Start the screen
lcd.backlight(); // Turn on the light
lcd.print("Distance:"); // Write a title
}
void loop() {
// Send a little "ping"
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// How long until the echo comes back?
long time = pulseIn(echoPin, HIGH);
// Turn time into centimetres
int distance = time * 0.034 / 2;
lcd.setCursor(0, 1); // Go to line 2
lcd.print(distance);
lcd.print(" cm "); // Extra spaces wipe old numbers
delay(300);
}
π‘ If the screen shows nothing or boxes β―β―β―, your LCD address might be 0x3F instead of 0x27 β just change the number!
π Test it!
- Wire the sensor and screen like the picture.
- Install the library (see the blue box above).
- Upload the code. Move your hand closer and farther β watch the numbers change!
π Try this!
- Add a buzzer that beeps when something is closer than 20 cm.
- Measure the length of your room β point it at the wall and read the cm!
- Make it show inches too (cm Γ· 2.54).
π ΏοΈ Smart Parking Sensor
Like the beeping thing in a real car β green, yellow, REDβ¦ BEEP BEEP!
π What you will make
Put this near a wall and watch: far away = green light, getting close = yellow + slow beeps, too close! = red + fast beeps. It's exactly how a real car's parking sensor works! π
π§ How it works
The ultrasonic sensor measures the distance (like Project 6). Then the code decides what to do with if / else if: over 40 cm β green, 20β40 cm β yellow, under 20 cm β red and BEEEEEP. The closer, the faster the beeps!
π Wire it up
| Part | Pin | Arduino |
|---|---|---|
| HC-SR04 | VCC / Trig / Echo / GND | 5V / D7 / D6 / GND |
| Green LED | + leg (via resistor) / β leg | D2 / GND |
| Yellow LED | + leg (via resistor) / β leg | D3 / GND |
| Red LED | + leg (via resistor) / β leg | D4 / GND |
| Buzzer | + / β | D8 / GND |
π» The Code
// PROJECT 7: Smart Parking Sensor
// Far = green, middle = yellow, close = RED + fast beeps!
int trigPin = 7;
int echoPin = 6;
int greenLed = 2;
int yellowLed = 3;
int redLed = 4;
int buzzerPin = 8;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Send the ping and measure the distance
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long time = pulseIn(echoPin, HIGH);
int distance = time * 0.034 / 2;
if (distance > 40) {
// FAR AWAY: green light, no beeping
digitalWrite(greenLed, HIGH);
digitalWrite(yellowLed, LOW);
digitalWrite(redLed, LOW);
}
else if (distance > 20) {
// MIDDLE: yellow light, slow beeps
digitalWrite(greenLed, LOW);
digitalWrite(yellowLed, HIGH);
digitalWrite(redLed, LOW);
tone(buzzerPin, 1000);
delay(200);
noTone(buzzerPin);
delay(400);
}
else {
// VERY CLOSE: red light, fast beeps!
digitalWrite(greenLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(redLed, HIGH);
tone(buzzerPin, 1000);
delay(100);
noTone(buzzerPin);
delay(100);
}
delay(200);
}
π Test it!
- Wire everything like the picture.
- Upload the code.
- Slowly move your hand toward the sensor. Green β Yellow β RED BEEP BEEP! ποΈ
π Try this!
- Change the 20 and 40 to make it more or less scared of things.
- Show the distance on the LCD screen too (combine with Project 6!).
- Attach it to a cardboard car and make a real parking assistant.
π€ Obstacle-Avoiding Robot
A robot that drives around β and turns away when it finds a wall!
π What you will make
Your first real robot! It drives forward, and when it sees something close, it stops, looks left, looks right, picks the open side and turns away. Put it on the floor and watch it explore! π§
π§ How it works
The servo turns the ultrasonic sensor left and right like a neck. The L293D chip is the muscle that drives the two motors. The brain (Arduino) asks: "Is the way clear?" If yes β GO. If not β look around and turn.
π Wire it up
π Wires may cross in the picture β that's fine, they don't actually touch. Follow the table!
| L293D module pin | Connect to |
|---|---|
| IN1 / IN2 | D4 / D5 (Arduino) |
| IN3 / IN4 | D6 / D7 (Arduino) |
| 5V (module) | Arduino 5V |
| GND (module) | Arduino GND + battery β |
| A1, A2 (motor A) | Left motor wires |
| B1, B2 (motor B) | Right motor wires |
| VM | Battery + (6V) |
| Other parts | Connect to |
| Servo orange / red / brown | D8 / 5V / GND |
| HC-SR04 VCC / Trig / Echo / GND | 5V / D11 / D12 / GND |
π» The Code
// PROJECT 8: Obstacle Avoiding Robot
// Drives forward, and turns away when something is in the way!
#include <Servo.h>
Servo lookServo; // The servo that looks left and right
int in1 = 4, in2 = 5; // Left motor
int in3 = 6, in4 = 7; // Right motor
int trigPin = 11;
int echoPin = 12;
void setup() {
pinMode(in1, OUTPUT); pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT); pinMode(in4, OUTPUT);
pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT);
lookServo.attach(8);
lookServo.write(90); // Look straight ahead
delay(500);
}
void loop() {
int distance = getDistance();
if (distance > 25) {
driveForward(); // Road is clear - GO!
} else {
stopRobot(); // Oops, something is there!
lookServo.write(30); // Look left
delay(500);
int left = getDistance();
lookServo.write(150); // Look right
delay(500);
int right = getDistance();
lookServo.write(90); // Look straight again
if (left > right) {
turnLeft(); // More space on the left
} else {
turnRight(); // More space on the right
}
delay(400);
}
}
// ---------- HELPERS ----------
int getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long time = pulseIn(echoPin, HIGH);
return time * 0.034 / 2;
}
void driveForward() {
digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
}
void stopRobot() {
digitalWrite(in1, LOW); digitalWrite(in2, LOW);
digitalWrite(in3, LOW); digitalWrite(in4, LOW);
}
void turnLeft() {
digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Left motor forward
digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Right motor backward
}
void turnRight() {
digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Left motor backward
digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Right motor forward
}
π Test it!
- Build the chassis: wheels, motors and battery box (ask a grown-up for the hot glue!).
- Wire the L293D, servo and sensor like the picture.
- Plug in the battery and the USB cable. Upload the code.
- Put the robot on the floor. Make a wall with your hands β watch it turn away! π§±
π Try this!
- Change
25to10β now it only avoids things right in front of it. - Make it turn the other way when space is equal (it likes the left!).
- Put a small box on top and make it a delivery robot π.
β« Line-Following Robot
Draw a black track on paper β this robot follows it like a puppy!
π What you will make
A robot with two "eyes" that look down at the floor. Make a black line (tape or marker), and the robot drives along it, correcting itself left and right so it never loses the track!
π§ How it works
The two IR sensors tell us what's under them: black line or white floor. If the right eye leaves the line, the robot turns right. If the left eye leaves it, it turns left. Both on the line β go straight. It's a tiny "brain" making decisions many times per second!
π Wire it up
| Part | Pin | Arduino |
|---|---|---|
| IR LEFT | VCC / GND / OUT | 5V / GND / D2 |
| IR RIGHT | VCC / GND / OUT | 5V / GND / D3 |
| L293D | IN1 / IN2 / IN3 / IN4 | D4 / D5 / D6 / D7 |
| L293D | 5V / GND / VM | 5V / GND / battery + |
| L293D | A1, A2 / B1, B2 | Left / right motor |
π§ First, tune the sensors!
Each IR sensor has a small blue knob. Put the sensor on the floor (black line under it) and turn the knob slowly until its little LED goes OFF. Do this before running the robot.
π» The Code
// PROJECT 9: Line Following Robot
// Two IR eyes keep the robot on the black line!
int leftSensor = 2; // IR sensor on the LEFT
int rightSensor = 3; // IR sensor on the RIGHT
int in1 = 4, in2 = 5; // Left motor
int in3 = 6, in4 = 7; // Right motor
void setup() {
pinMode(leftSensor, INPUT);
pinMode(rightSensor, INPUT);
pinMode(in1, OUTPUT); pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT); pinMode(in4, OUTPUT);
}
void loop() {
int left = digitalRead(leftSensor); // 0 = on the black line
int right = digitalRead(rightSensor);
if (left == 0 && right == 0) {
forward(); // Both on the line - GO STRAIGHT!
}
else if (left == 0 && right == 1) {
turnLeft(); // Right eye lost the line - turn LEFT
}
else if (left == 1 && right == 0) {
turnRight(); // Left eye lost the line - turn RIGHT
}
else {
forward(); // Lost the line - keep going straight
}
}
void forward() {
digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
}
void turnLeft() {
digitalWrite(in1, LOW); digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
}
void turnRight() {
digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
digitalWrite(in3, LOW); digitalWrite(in4, HIGH);
}
π‘ If the robot zig-zags the wrong way, swap the leftSensor and rightSensor pins (or just swap the two motor plugs).
π Test it!
- Build the chassis and wire everything like the picture.
- Tune the two IR sensors (see the blue box).
- Make a track with black tape or a thick marker on white paper.
- Put the robot on the line, add powerβ¦ and watch it follow! πΎ
π Try this!
- Make the track tighter (smaller curves) β can your robot handle it?
- Add a beep when it has to turn.
- Time it racing around the track β beat your own record! β±οΈ
π± Bluetooth Robot
Drive your robot from your PHONE β no wires, just magic!
π What you will make
A robot you drive like a remote-control car β but the remote is your phone! Install a free "Bluetooth RC" app, connect, and press F (forward), B (back), L (left), R (right), S (stop).
π§ How it works
The HC-05 is a tiny Bluetooth radio. Your phone sends letters through the air; the HC-05 catches them and passes them to the Arduino. The Arduino reads each letter and tells the motors what to do. We use SoftwareSerial so the radio can talk on pins D2 and D3.
π Wire it up
| HC-05 pin | Arduino | L293D | Arduino |
|---|---|---|---|
| VCC / GND | 5V / GND | IN1 / IN2 / IN3 / IN4 | D4 / D5 / D6 / D7 |
| TX / RX | D2 / D3 | 5V / GND / VM | 5V / GND / battery + |
| A1,A2 β left motor Β· B1,B2 β right motor | |||
π» The Code
// PROJECT 10: Bluetooth Robot
// Phone sends letters: F=forward B=back L=left R=right S=stop
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3); // HC-05: TXβpin2, RXβpin3
int in1 = 4, in2 = 5; // Left motor
int in3 = 6, in4 = 7; // Right motor
char command; // The letter from your phone
void setup() {
pinMode(in1, OUTPUT); pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT); pinMode(in4, OUTPUT);
bluetooth.begin(9600); // Start talking to the HC-05
stopRobot();
}
void loop() {
if (bluetooth.available()) { // A letter arrived?
command = bluetooth.read(); // Read it
if (command == 'F') forward();
else if (command == 'B') backward();
else if (command == 'L') turnLeft();
else if (command == 'R') turnRight();
else if (command == 'S') stopRobot();
}
}
void forward() {
digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
}
void backward() {
digitalWrite(in1, LOW); digitalWrite(in2, HIGH);
digitalWrite(in3, LOW); digitalWrite(in4, HIGH);
}
void turnLeft() {
digitalWrite(in1, LOW); digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
}
void turnRight() {
digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
digitalWrite(in3, LOW); digitalWrite(in4, HIGH);
}
void stopRobot() {
digitalWrite(in1, LOW); digitalWrite(in2, LOW);
digitalWrite(in3, LOW); digitalWrite(in4, LOW);
}
π Test it!
- Wire everything like the picture (HC-05 and module).
- Upload the code (with HC-05 RX unplugged, then reconnect it).
- On your phone: turn ON Bluetooth. Open a free "Bluetooth RC" / "Arduino Bluetooth Controller" app and connect to "HC-05" (password is usually 1234).
- Press the buttons β your robot drives! ποΈ
π Try this!
- Add your own letters: make 'H' do a happy spin!
- Add a buzzer that beeps when you send 'B'.
- Put a cardboard body on it and have a robot race with a friend.
πΆ Motion-Activated Light
Walk past and the light turns ON by itself β magic? No, PIR!
π What you will make
Point the PIR at your door. When someone walks in, the relay switches the lamp ON for 10 seconds, then OFF again. Real buildings use exactly this for hallway lights! (You'll also see the little LED built into the Arduino light up as a sign.)
π§ How it works
The PIR feels the tiny bit of heat (infrared) that people give off. When something warm moves in front of it, its OUT pin goes HIGH. The relay is an electric switch: the Arduino flips it, and the relay turns the big lamp on or off.
π Wire it up
| PIR | Arduino | Relay | Arduino |
|---|---|---|---|
| VCC / OUT / GND | 5V / D2 / GND | VCC / GND / IN | 5V / GND / D7 |
| Lamp: one wire β relay COM, other wire β relay NO (you can test with an LED + resistor instead) | |||
π Relay acting backwards?
Some relay modules turn ON when the signal is LOW instead of HIGH. If your lamp is on when it should be off (or off when it should be on), just swap HIGH β LOW in the code. The same trick works for Projects 12 and 15!
π§ͺ Try it safely first
For your first test, don't use mains power! Use a small LED + resistor or a 6V bulb on the relay's COM/NO. Only a grown-up should ever touch wall electricity.
π» The Code
// PROJECT 11: Motion-Activated Light
// When someone moves, the light turns ON for 10 seconds!
int pirPin = 2; // PIR sensor output
int relayPin = 7; // Relay switch
int ledPin = 13; // Small LED built into the Arduino
void setup() {
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(relayPin, LOW); // Light starts OFF
delay(2000); // Give the PIR 2s to wake up!
}
void loop() {
int motion = digitalRead(pirPin); // 1 = movement!
if (motion == HIGH) {
digitalWrite(relayPin, HIGH); // Light ON
digitalWrite(ledPin, HIGH);
delay(10000); // Stay ON for 10 seconds
digitalWrite(relayPin, LOW); // Light OFF
digitalWrite(ledPin, LOW);
}
}
π Test it!
- Wire the PIR and relay like the picture.
- Upload the code and wait 2 seconds (PIR is waking up!).
- Wave your hand in front of the PIR β the lamp lights up! π
- Stand still for 10 seconds β it turns OFF. Move again β ON!
π Try this!
- Change
delay(10000)todelay(30000)β light stays on 30 seconds. - Add a buzzer on D8 for a "intruder alarm" version.
- Make a cookie jar alarm β hide the PIR and see who sneaks a cookie! πͺ
π Clap Switch
Clap once⦠light ON. Clap again⦠light OFF. Applause required!
π What you will make
A lamp you switch with a clap! Clap-clap to turn it on, clap-clap to turn it off. You'll feel like a wizard. π§
π§ How it works
The sound sensor has a tiny microphone. When it hears a loud sound (a clap), its DO (digital out) pin goes HIGH for a moment. The Arduino flips a switch in the code each time: on β off β on β off. That's called toggling.
π Wire it up
| Sound sensor | Arduino | Relay | Arduino |
|---|---|---|---|
| VCC / GND / DO | 5V / GND / D2 | VCC / GND / IN | 5V / GND / D7 |
| Lamp: one wire β relay COM, other wire β relay NO | |||
π§ Tune the sensitivity
Turn the sound sensor's blue knob to choose how loud a clap must be. Too sensitive β every cough switches it. Too quiet β even shouting won't work!
π Acts backwards? A few sensors send LOW instead of HIGH when they hear a clap. If the lamp flips when it's quiet, just change HIGH to LOW in the code.
π» The Code
// PROJECT 12: Clap Switch
// Clap to turn the lamp ON... clap again to turn it OFF!
int soundPin = 2; // Sound sensor digital output
int relayPin = 7; // Relay switch
int ledPin = 13; // Arduino's little built-in LED
bool lightOn = false; // The light starts OFF
void setup() {
pinMode(soundPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(relayPin, LOW);
}
void loop() {
int sound = digitalRead(soundPin); // 1 = loud sound (a clap!)
if (sound == HIGH) {
lightOn = !lightOn; // Flip the switch!
digitalWrite(relayPin, lightOn);
digitalWrite(ledPin, lightOn);
delay(500); // One clap = one switch (not five!)
}
}
π Test it!
- Wire the sound sensor and relay like the picture.
- Upload the code.
- Clap near the sensorβ¦ the lamp turns ON. πβ¨
- Clap again⦠OFF!
π Try this!
- Make a two-clap switch: only turn on after 2 quick claps.
- Add a buzzer that does a little "ding-dong" when you clap.
- Use it with a fan or music β clap to start your playlist! πΆ
π‘οΈ Temperature & Humidity Monitor
Your own weather station β hot or cold, wet or dry?
π What you will make
A screen that shows the temperature (Β°C) and humidity (how wet the air is, in %) right now. Breathe on the sensor and watch the numbers jump!
π§ How it works
The DHT11 is a little weather scientist. It measures temperature with a tiny thermometer and humidity with a tiny moisture sensor, then sends both to the Arduino on one wire. The library DHT does the tricky reading for us.
π Wire it up
| DHT11 | Arduino | LCD I2C | Arduino |
|---|---|---|---|
| VCC / DATA / GND | 5V / D2 / GND | VCC / GND | 5V / GND |
| SDA / SCL | A4 / A5 | ||
π Libraries you need
Install LiquidCrystal I2C (like Project 6) and DHT sensor library by Adafruit (Sketch β Include Library β Manage Libraries β search "DHT sensor library" β Install).
π Two kinds of DHT11: if yours is the small blue 4-pin module, wire it straight to the board. If it's the bare white 3-pin sensor, also add a 10kΞ© resistor between the DATA pin and 5V (that's called a pull-up β it helps the sensor talk).
π» The Code
// PROJECT 13: Temperature & Humidity Monitor
// Shows temperature and humidity on the LCD!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2 // DHT11 data pin
#define DHTTYPE DHT11 // Type of sensor
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
dht.begin(); // Start the weather scientist
lcd.init();
lcd.backlight();
}
void loop() {
float temp = dht.readTemperature(); // Read temperature in Β°C
float hum = dht.readHumidity(); // Read humidity in %
if (isnan(temp) || isnan(hum)) { // If the reading failed
lcd.setCursor(0, 0);
lcd.print("Sensor error! ");
} else {
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C ");
lcd.setCursor(0, 1);
lcd.print("Hum: ");
lcd.print(hum);
lcd.print(" % ");
}
delay(2000); // DHT11 is slow - wait 2 seconds
}
π‘ Screen showing boxes β―β―β―? Try 0x3F instead of 0x27 in lcd(0x27, 16, 2).
π Test it!
- Wire the DHT11 and LCD like the picture.
- Install both libraries and upload the code.
- Watch the screen. Now breathe on the DHT11 β humidity shoots up! π¬οΈ
- Put it in the fridge for 1 minute β temperature drops!
π Try this!
- Add a buzzer that warns when it's hotter than 30Β°C.
- Show "It's warm π₯΅" or "It's cool βοΈ" on the second line.
- Record the morning vs evening temperature and make a little chart.
π· Alcohol Detector
A nose that smells alcohol in the air β and sounds the alarm!
π What you will make
A device that smells alcohol and other gases in the air. When the smell is too strong, it shows "ALCOHOL!" on the screen and the buzzer warns: BEEP BEEP! (Real police breathalyzers work on this idea!)
π§ How it works
The MQ3 has a special plate inside that changes its electrical resistance when it smells alcohol. The analogRead() turns that into a number from 0β1023. Bigger number = stronger smell. We compare it to a limit: over the limit β alarm!
π Wire it up
π *DO is the digital output β we don't use it in this project. The LCD is optional: without it the project still works (the buzzer still alarms!).
| MQ3 | Arduino | LCD I2C | Arduino |
|---|---|---|---|
| VCC / GND / AO | 5V / GND / A0 | VCC / GND / SDA / SCL | 5V / GND / A4 / A5 |
| Buzzer + / β | D8 / GND | ||
π» The Code
// PROJECT 14: Alcohol Detector
// Smells alcohol in the air and warns with the buzzer!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int mq3Pin = A0; // MQ3 analog output
int buzzerPin = 8;
int limit = 300; // Above this number = ALARM!
void setup() {
pinMode(buzzerPin, OUTPUT);
lcd.init();
lcd.backlight();
lcd.print("Warming up...");
delay(30000); // Let the sensor warm up (30s)
}
void loop() {
int value = analogRead(mq3Pin); // Read the smell level (0-1023)
lcd.setCursor(0, 0);
lcd.print("Gas: ");
lcd.print(value);
lcd.print(" ");
if (value > limit) {
// STRONG smell - alarm!
lcd.setCursor(0, 1);
lcd.print("ALCOHOL! BEEP! ");
tone(buzzerPin, 2000); // Beep! (tone works with any buzzer)
delay(200);
noTone(buzzerPin);
delay(200);
} else {
// Air is fine
lcd.setCursor(0, 1);
lcd.print("All clear ");
delay(500);
}
}
π Test it!
- Wire the MQ3, buzzer and LCD like the picture.
- Upload the code and wait 30 seconds for warm-up.
- Wave your hand near the sensor β the number stays low.
- Now wave it near a bottle of hand sanitizer (it contains alcohol!) β the number jumps and the buzzer BEEPS! π¨
π Try this!
- Change
limitto make it more or less sensitive. - Add a red LED that lights up during the alarm.
- Make it say "OK" / "SMELLY" β your choice of words!
π Home Automation Switchboard
Three buttons control a lamp, a fan and a night light β your own smart home!
π What you will make
A mini smart home! Button 1 turns the lamp (relay) on/off. Button 2 switches the fan (a blue LED). Button 3 switches the night light (a small LED). Press once β ON, press again β OFF.
π§ How it works
Each button toggles (flips) its own thing using bool variables that remember "on" or "off". The relay controls the real lamp; the LEDs show what the fan and night light would be doing. This is how real home automation starts!
π Wire it up
| Part | Pin | Arduino |
|---|---|---|
| LAMP button | one leg / other leg | D2 / GND |
| FAN button | one leg / other leg | D3 / GND |
| NIGHT button | one leg / other leg | D4 / GND |
| Relay | VCC / GND / IN | 5V / GND / D7 |
| Fan LED (blue) | + (via resistor) / β | D8 / GND |
| Night LED (yellow) | + (via resistor) / β | D9 / GND |
| Lamp | COM / NO on the relay | β |
π» The Code
// PROJECT 15: Home Automation Switchboard
// 3 buttons control a lamp (relay), a fan LED and a night LED!
int button1 = 2; // Lamp button
int button2 = 3; // Fan button
int button3 = 4; // Night light button
int relayPin = 7; // Controls the real lamp
int fanLed = 8; // Stands for the fan
int nightLed = 9; // Night light
bool lampOn = false;
bool fanOn = false;
bool nightOn = false;
void setup() {
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
pinMode(fanLed, OUTPUT);
pinMode(nightLed, OUTPUT);
}
void loop() {
if (digitalRead(button1) == LOW) { // Lamp button pressed?
lampOn = !lampOn; // Flip it!
digitalWrite(relayPin, lampOn);
delay(300); // So one press = one flip
}
if (digitalRead(button2) == LOW) { // Fan button pressed?
fanOn = !fanOn;
digitalWrite(fanLed, fanOn);
delay(300);
}
if (digitalRead(button3) == LOW) { // Night light button pressed?
nightOn = !nightOn;
digitalWrite(nightLed, nightOn);
delay(300);
}
}
π Test it!
- Wire the buttons, relay and LEDs like the picture.
- Upload the code.
- Press the LAMP button β the relay clicks and the lamp turns on!
- Press FAN and NIGHT β their LEDs light up. Press again β everything off!
π Try this!
- Add a 4th button that turns everything OFF at once ("goodnight mode" π΄).
- Make the fan LED blink like a spinning fan when it's on.
- Combine with the sound sensor: clap to turn on the lamp!
π You did it! You built 15 projects!
From a blinking LED to robots that avoid walls, follow lines and listen to your phone. That's not "playing with a kit" β that's engineering!
π What's next?
- Mix projects together β obstacle robot + Bluetooth = a robot you drive that never crashes!
- Change the numbers β speeds, delays, limits. Breaking things to learn is part of the fun.
- Draw your own invention on paper first, then build it. Every great engineer starts with a sketch.
- Teach someone else β the best way to truly learn something is to explain it to a friend.
Made with β€οΈ for curious young makers Β· Always keep learning, keep building, and keep asking "what ifβ¦?"