Sample Project 1 – Traffic Light

1 x Arduino Uno R3

3 x LED (any color)

3 x Resistor

Jumper Wires

1 x Breadboard

1 x Ultrasonic Sensor HC-04

Wiring Guide:
  1. Connect the anode (longer leg) of each LED to a separate digital pin on the Arduino (pins 2, 3, and 4).
  2. Connect the cathode (shorter leg) of each LED to a separate resistor.
  3. Connect the other end of each resistor to the ground (GND) on the Arduino.
  4. Connect the ground (GND) of the Arduino to the ground rail of the breadboard.
  5. Connect the power (5V) of the Arduino to the power rail of the breadboard.
Code:

// Pin definitions
const int redPin = 2;
const int yellowPin = 3;
const int greenPin = 4;

// Time delays in milliseconds
const int redDelay = 5000; // 5 seconds for red
const int yellowDelay = 2000; // 2 seconds for yellow
const int greenDelay = 5000; // 5 seconds for green

void setup() {
// Set the LED pins as OUTPUT
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}

void loop() {
// Red light
digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
delay(redDelay);

// Yellow light
digitalWrite(yellowPin, HIGH);
delay(yellowDelay);

// Green light
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, HIGH);
delay(greenDelay);
}

 

Sample Project 2 – Buzzer Music

1 x Arduino Uno R3

1 x Female to Male Jumper Wire

1 x Active Buzzer

Wiring Guide:
  1. Connect one leg of the buzzer to digital pin 9 on the Arduino.
  2. Connect the other leg of the buzzer to the ground (GND) on the Arduino using a jumper wire
Code:
#include “pitches.h”
// Define the pins
#define BUZZER_PIN 9
// Define the simple melody notes and durations
int melody[] = {
  NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
};
// Define the corresponding durations
int noteDurations[] = {
  4, 4, 4, 4, 4, 4, 4, 4
};
void setup() {
  // Set the BUZZER_PIN as an OUTPUT
  pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
  // Play the simple melody
  playMelody();
}
void playMelody() {
  for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
    int noteDuration = 1000 / noteDurations[i];
    tone(BUZZER_PIN, melody[i], noteDuration);
    delay(noteDuration * 1.30); // add a small delay to separate the notes
    noTone(BUZZER_PIN); // stop the tone playing
  }
  delay(1000); // pause between melodies
}

Sample Project 3 – Temperature and Humidity Monitor

1 x Arduino Uno R3

Jumper Wires

1 x LCD1602 with I2C module

1 x Breadboard

Wiring Guide:
  1. Connect the I2C module to the Arduino board:
    • Connect the SDA pin on the I2C module to the A4 pin on the Arduino.
    • Connect the SCL pin on the I2C module to the A5 pin on the Arduino.
    • Connect VCC on the I2C module to the 5V pin on the Arduino (or breadboard).
    • Connect GND on the I2C module to the GND pin on the Arduino (or breadboard).
  2. Connect DHT11 to the Arduino Board:
    • Connect the VCC pin of the DHT11 to 5V on the Arduino (or breadboard).
    • Connect the data pin of the DHT11 to a digital pin 2 on the Arduino.
    • Connect the GND pin of the DHT11 to GND on the Arduino (or breadboard).
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2         // DHT11 data pin connected to D2
#define DHTTYPE DHT11    // DHT11 sensor type
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address 0x27, 16 columns and 2 rows
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.backlight();
  dht.begin();  // Initialize the DHT sensor
  delay(2000);  // Allow time for sensor to stabilize
}
void loop() {
  float temperature = dht.readTemperature();  // Reading temperature from DHT sensor
  float humidity = dht.readHumidity();        // Reading humidity from DHT sensor
  lcd.clear();  // Clear the LCD display
  lcd.setCursor(0, 0);
  lcd.print(“Temp: “);
  lcd.print(temperature, 1);  // Display temperature with one decimal place
  lcd.print(” C”);
  lcd.setCursor(0, 1);
  lcd.print(“Humidity: “);
  lcd.print(humidity, 1);     // Display humidity with one decimal place
  lcd.print(” %”);
  delay(1000);  // polling (1 second)
}

Sample Project 4 – Buzzer Sonar

1 x Arduino Uno R3

Jumper Wires

1 x Buzzer

1 x HC-06

Wiring Guide:
  1. Connect the HC-SR04 Ultrasonic Sensor:
    • Connect the VCC pin of the sensor to the 5V pin on the Arduino (or breadboard).
    • Connect the GND pin of the sensor to the GND pin on the Arduino (or breadboard).
    • Connect the TRIG pin of the sensor to digital pin 9 on the Arduino.
    • Connect the ECHO pin of the sensor to digital pin 10 on the Arduino.
  2. Connect the Buzzer:
    • Connect the positive (longer) leg of the buzzer to digital pin 8 on the Arduino.
    • Connect the negative (shorter) leg of the buzzer to the GND pin on the Arduino (or breadboard).
Code:
#define TRIG_PIN 9
#define ECHO_PIN 10
#define BUZZER_PIN 8
void setup() {
  Serial.begin(9600);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
  long duration, distance;
  // Clear the trigger pin
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  // Send a 10 microsecond pulse to the trigger pin
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  // Measure the time taken for the pulse to return
  duration = pulseIn(ECHO_PIN, HIGH);
  // Calculate the distance in centimeters
  distance = (duration / 2) / 29.1;
  // Print the distance to the Serial Monitor
  Serial.print(“Distance: “);
  Serial.print(distance);
  Serial.println(” cm”);
  // Set a longer delay if distance is above 60
  int beepDelay = (distance > 60) ? 1000 : map(distance, 2, 60, 50, 500);
  // Set a shorter beep duration
  int beepDuration = 50;
  // Control the buzzer based on the distance
  tone(BUZZER_PIN, 1000, beepDuration); // Constant frequency for the example
  delay(beepDuration);
  // Stop the buzzer after the beep duration
  noTone(BUZZER_PIN);
  // Add an additional delay for distances above 60
  if (distance > 60) {
    delay(1000); // 1-second delay between beeps
  } else {
    delay(beepDelay); // Delay between beeps
  }
}