Meet the parts
| Part | Job | Projects |
|---|---|---|
| Arduino UNO (SMD, FT232 USB) + USB A-to-B cable | Runs the code; USB also powers everything | All |
| 400-point breadboard | Shares 5V and GND between the modules | All |
| Resistor pack | 220 Ω for each LED and RGB colour | 1, 2, 3, 4 |
| Capacitor pack | A 100–470 µF capacitor steadies the 5V supply when the servo moves | 2, 4 |
| Ultrasonic sensor module | Measures distance (the HC-SR04) | 1 |
| RGB LED, 5 mm, 4 legs | Green / yellow / red, or blue / green / red | 1, 3 |
| Buzzer B-10 | Beeps | 1, 2, 4 |
| PS2 joystick module | Two analog axes and a push button | 2 |
| SG-90 servo motor | Turns to an exact angle | 2, 4 |
| LED, 5 mm | Brightness control, “fan” light or “lid open” light | 2, 3, 4 |
| DHT-11 sensor | Temperature and humidity | 3 |
| 5V relay module | A switch the Arduino can click on and off | 3 |
| IR sensor module (LM358) | Notices a hand in front of it | 4 |
| 7805 voltage regulator | Not used here: it turns 7–12 V into 5 V, and this kit has no 7–12 V supply | – |
Check your relayProject 3 needs a relay module: a relay on a small board with VCC, GND and IN pins. A bare relay on its own can’t be driven from an Arduino pin without a transistor and a diode, which this kit doesn’t include.
About the ultrasonic sensorThe kit list calls it “HC-SR504”. It’s the common HC-SR04 ultrasonic module: four pins marked VCC, TRIG, ECHO and GND.
Setup and power
- Install the Arduino IDEThe Servo library is built in. Project 3 also needs the DHT sensor library by Adafruit: install it from the Library Manager and accept Adafruit Unified Sensor when asked.
- Connect the UNOThis board uses an FT232 USB chip. If no port appears, install the FTDI driver.
- Pick the board and portChoose Tools → Board → Arduino Uno, then the Port that appears when you plug it in.
One pin plan for all four projects
Every part has its own pin, so you can leave modules plugged in when you move to the next project.
| Pin | Part | Projects |
|---|---|---|
| D2 | IR sensor OUT | 4 |
| D3 | Servo signal (orange) | 2, 4 |
| D4 | DHT-11 DATA | 3 |
| D5 | LED, through 220 Ω | 2, 4 |
| D6 / D9 / D10 | RGB blue / red / green, each through 220 Ω | 1, 3 |
| D7 | Relay module IN | 3 |
| D8 | Buzzer + | 1, 2, 4 |
| D11 / D12 | HC-SR04 ECHO / TRIG | 1 |
| A0 / A1 / A2 | Joystick VRx / VRy / SW | 2 |
| 5V, GND | Breadboard + and − rails, shared by every module | All |
Steady power for the servoA moving servo draws bursts of current that can make the Arduino reset over USB. Put a 100–470 µF capacitor across the 5V and GND rails, long leg to +, as the Project 2 and 4 diagrams show. Never connect the 5V rail straight to GND.
Why the RGB LED is just on or offThe Servo library takes over PWM on pins 9 and 10, and the buzzer’s tone() takes pins 3 and 11. Simple on/off colours (red, green, blue, yellow, purple) avoid both conflicts.
Parking sensor
Like the sensor in a car bumper: green when the way is clear, yellow with slow beeps as you get closer, red with fast beeps when close, and a non-stop tone at 8 cm.
- Wire itHC-SR04 TRIG to D12 and ECHO to D11. The RGB LED’s long leg goes to GND; each colour leg gets a 220 Ω resistor to its pin. Buzzer + to D8.
- Upload and testOpen the Serial Monitor at 9600 baud and move your hand towards the sensor.
- Make it a garageTape the sensor to a box or wall, facing a toy car’s path.
// PARKING SENSOR: HC-SR04 + RGB LED + buzzer
const int TRIG = 12, ECHO = 11;
const int RED = 9, GREEN = 10, BLUE = 6;
const int BUZZER = 8;
const bool COMMON_ANODE = false; // true if the RGB long leg goes to 5V
const int SAFE = 50; // cm: further than this is green and silent
const int NEAR = 20; // cm: closer than this is red
const int STOP = 8; // cm: closer than this beeps non-stop
unsigned long lastBeep = 0;
void setColor(bool r, bool g, bool b) {
if (COMMON_ANODE) { r = !r; g = !g; b = !b; }
digitalWrite(RED, r); digitalWrite(GREEN, g); digitalWrite(BLUE, b);
}
long readCM() {
digitalWrite(TRIG, LOW); delayMicroseconds(2);
digitalWrite(TRIG, HIGH); delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long us = pulseIn(ECHO, HIGH, 30000); // give up after 30 ms
if (us == 0) return -1; // no echo
return us * 0.0343 / 2;
}
void beepEvery(int gap) { // short beep every "gap" ms
if (millis() - lastBeep >= (unsigned long)gap) {
tone(BUZZER, 1500, 50);
lastBeep = millis();
}
}
void setup() {
pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT);
pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT);
Serial.begin(9600);
}
void loop() {
long cm = readCM();
Serial.print("Distance: ");
if (cm < 0) Serial.println("no echo");
else { Serial.print(cm); Serial.println(" cm"); }
if (cm < 0 || cm > SAFE) { // clear
setColor(0, 1, 0);
noTone(BUZZER);
} else if (cm > NEAR) { // getting close: yellow, slow beeps
setColor(1, 1, 0);
beepEvery(map(cm, NEAR, SAFE, 150, 600));
} else if (cm > STOP) { // close: red, fast beeps
setColor(1, 0, 0);
beepEvery(map(cm, STOP, NEAR, 80, 150));
} else { // too close: red, non-stop tone
setColor(1, 0, 0);
tone(BUZZER, 1500);
}
delay(60);
}| Setting | Default | Meaning |
|---|---|---|
SAFE | 50 cm | Further away is green and silent |
NEAR | 20 cm | Closer turns red with fast beeps |
STOP | 8 cm | Closer beeps non-stop |
COMMON_ANODE | false | Set true if no colour lights with the long leg on GND (then move it to 5V) |
Joystick servo arm
Push the stick left and right to swing the servo arm from 0° to 180°. Push up and down to brighten or dim the LED. Hold the stick pressed to send the arm to the centre with a beep. Like a real joystick, it springs back to the middle when you let go, and the arm follows.
- Wire itJoystick VRx to A0, VRy to A1, SW to A2. Servo orange to D3, red to the 5V rail, brown to GND. LED long leg through 220 Ω to D5. Buzzer + to D8.
- Add the capacitorPlace the 470 µF (or the largest 100 µF+ in the pack) across the rails: the long leg in +, the striped side in −.
- Upload and playWatch the X and Y numbers in the Serial Monitor: about 512 in the middle, 0 and 1023 at the ends.
// JOYSTICK SERVO ARM: PS2 joystick + SG90 servo + LED + buzzer
#include <Servo.h>
const int JOY_X = A0, JOY_Y = A1, JOY_SW = A2;
const int SERVO_PIN = 3, LED = 5, BUZZER = 8;
Servo arm;
int lastAngle = -1;
void setup() {
pinMode(JOY_SW, INPUT_PULLUP); // pressed = LOW
pinMode(LED, OUTPUT);
arm.attach(SERVO_PIN);
arm.write(90);
Serial.begin(9600);
}
void loop() {
int x = analogRead(JOY_X); // 0-1023, about 512 in the middle
int y = analogRead(JOY_Y);
int angle = map(x, 0, 1023, 0, 180);
if (digitalRead(JOY_SW) == LOW) { // hold the button: centre the arm
angle = 90;
tone(BUZZER, 1200, 60);
}
if (abs(angle - lastAngle) > 2) { // ignore tiny wobbles
arm.write(angle);
lastAngle = angle;
}
analogWrite(LED, map(y, 0, 1023, 0, 255)); // up/down = brightness
Serial.print("X: "); Serial.print(x);
Serial.print(" Y: "); Serial.print(y);
Serial.print(" angle: "); Serial.println(angle);
delay(50);
}Make it your ownTape a paper pointer to the servo horn to build a dial, or a flag that waves. To keep the arm where you leave it, change the code to add a little to the angle while the stick is pushed, instead of mapping the stick directly.
Comfort monitor with fan switch
The RGB LED shows the room’s feel: blue when cool, green when comfortable, red when hot. When it reaches 30 °C the relay clicks on a “fan”. Here it’s an LED wired through the relay contacts, standing in for a real low-voltage fan.
- Install the DHT librarySee Setup above.
- Wire itDHT-11 DATA to D4. Relay IN to D7, VCC and GND to the rails. Relay COM to the 5V rail, and NO through 220 Ω to the “fan” LED, then to GND. RGB LED as in Project 1.
- Upload and listenThe relay clicks once at start-up as a test. If its LED stays on when it should be off, your module is “low level trigger”: set
RELAY_ON = LOW. - Test the fanSet
FAN_ONone or two degrees above the room temperature, then warm the DHT-11 gently with your fingers. - Plot itOpen Tools → Serial Plotter to see temperature and humidity as live graphs.
// COMFORT MONITOR: DHT11 + RGB LED + relay "fan" switch
#include <DHT.h>
const int DHT_PIN = 4, RELAY = 7;
const int RED = 9, GREEN = 10, BLUE = 6;
const bool COMMON_ANODE = false; // true if the RGB long leg goes to 5V
const int RELAY_ON = HIGH; // LOW for "low level trigger" modules
const int RELAY_OFF = (RELAY_ON == HIGH) ? LOW : HIGH;
const float COOL = 20.0; // °C: below this is blue
const float FAN_ON = 30.0; // °C: relay switches on at this or above
const float FAN_OFF = 28.0; // °C: relay switches off below this
DHT dht(DHT_PIN, DHT11);
bool fan = false;
void setColor(bool r, bool g, bool b) {
if (COMMON_ANODE) { r = !r; g = !g; b = !b; }
digitalWrite(RED, r); digitalWrite(GREEN, g); digitalWrite(BLUE, b);
}
void setup() {
pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT);
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, RELAY_ON); delay(300); // click test
digitalWrite(RELAY, RELAY_OFF);
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000); // the DHT11 needs time between readings
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(t) || isnan(h)) {
Serial.println("DHT11 read failed");
setColor(1, 0, 1); // purple = check the sensor
return;
}
if (t >= FAN_ON) fan = true; // two limits stop the relay
if (t < FAN_OFF) fan = false; // clicking on and off
digitalWrite(RELAY, fan ? RELAY_ON : RELAY_OFF);
if (t < COOL) setColor(0, 0, 1); // blue: cool
else if (t < FAN_ON) setColor(0, 1, 0); // green: comfortable
else setColor(1, 0, 0); // red: hot
// "Name:value" pairs also draw lines in the Serial Plotter
Serial.print("Temp:"); Serial.print(t, 1);
Serial.print(" Humidity:"); Serial.print(h, 0);
Serial.print(" Fan:"); Serial.println(fan ? 1 : 0);
}Low voltage onlyUse the relay only to switch the 5V LED or another small low-voltage device. Never connect mains (wall socket) power to it in a classroom project.
Smart dustbin
Wave a hand in front of the bin and the lid swings open with a beep. It stays open while the hand is there and closes slowly 3 seconds after it leaves.
- Wire itIR sensor OUT to D2. Servo orange to D3, red to 5V, brown to GND. Buzzer + to D8, LED through 220 Ω to D5, and the capacitor across the rails.
- Adjust the IR sensorTurn its small screw until its LED lights when your hand is about 10 cm away.
- Build the binUse a small box or cup. Tape the servo at the back so its horn lifts a card lid, and mount the IR sensor at the front, facing out.
- Tune the anglesChange
OPENandCLOSEDso the lid sits flat when closed and clears the hand when open.
// SMART DUSTBIN: IR sensor + SG90 servo lid + LED + buzzer
#include <Servo.h>
const int IR_PIN = 2, SERVO_PIN = 3, LED = 5, BUZZER = 8;
const int DETECTED = LOW; // most IR modules pull OUT low on detection
const int CLOSED = 0, OPEN = 100; // servo angles for the lid
const unsigned long HOLD = 3000; // ms to stay open after the hand leaves
Servo lid;
bool isOpen = false;
unsigned long lastSeen = 0;
void moveLid(int from, int to) { // move slowly so the lid doesn't slam
if (to > from) { for (int a = from; a <= to; a++) { lid.write(a); delay(8); } }
else { for (int a = from; a >= to; a--) { lid.write(a); delay(8); } }
}
void setup() {
pinMode(IR_PIN, INPUT);
pinMode(LED, OUTPUT);
lid.attach(SERVO_PIN);
lid.write(CLOSED);
Serial.begin(9600);
Serial.println("Smart dustbin ready");
}
void loop() {
bool hand = (digitalRead(IR_PIN) == DETECTED);
if (hand) lastSeen = millis();
if (hand && !isOpen) {
Serial.println("Hand detected: opening");
tone(BUZZER, 1000, 100);
digitalWrite(LED, HIGH);
moveLid(CLOSED, OPEN);
isOpen = true;
}
if (isOpen && !hand && millis() - lastSeen > HOLD) {
Serial.println("Closing");
moveLid(OPEN, CLOSED);
digitalWrite(LED, LOW);
isOpen = false;
}
delay(20);
}Troubleshooting
No port appears in the Arduino IDE
- Try another USB cable or port. Some cables only charge.
- Install the FTDI driver (link in Setup).
The Arduino resets when the servo moves
- Fit the 100–470 µF capacitor across the 5V and GND rails, long leg to +.
- Plug into a computer’s USB port directly, not through a hub.
The servo jitters or buzzes at the ends
Some SG-90s can’t reach exactly 0° or 180°. Keep the angles between about 5° and 175°.
The parking sensor always reads “no echo”
- Check TRIG is on D12 and ECHO on D11 (not swapped).
- Soft or angled surfaces scatter the sound. Test with a flat book.
The RGB LED shows no colour or the wrong colour
- No colour: set
COMMON_ANODE = trueand move the long leg to 5V. - Wrong colour: swap the wires on D9, D10 and D6.
“DHT11 read failed” and a purple light
- Check DATA is on D4 and the module’s VCC and GND.
- A white sensor is a DHT22: change
DHT11toDHT22in the code.
The relay never clicks
- Check its VCC and GND on the rails and IN on D7.
- Try
RELAY_ON = LOW.
The dustbin opens by itself, or never opens
- Turn the IR sensor’s screw and watch its LED.
- If it opens when nothing is there, change
DETECTEDtoHIGH. - Keep it out of strong sunlight, which contains infrared.
Joystick numbers jump or the arm drifts
Check the joystick’s +5V and GND. Readings around 500–520 at rest are normal; the code ignores changes under 3°.