Posted on Leave a comment

Smart City Mini Project Using Arduino UNO

(Street Light Automation, Smart Gate & Air Quality Alert)

Smart cities are built by combining automation, sensing, and decision-making.
In this project, a Smart City model was developed using an Arduino UNO and commonly available sensors to demonstrate how embedded systems can be used for urban automation.

This project focuses on real-world logic, not just blinking LEDs.


📌 Project Demonstration Video

🎥 Watch the complete working demonstration here:

👉 The video shows the automatic street lights, smart gate operation, and air quality alert system working in real time.


Project Overview

The model demonstrates four smart city subsystems working together:

  1. Automatic Street Light System (LDR based)
  2. Smart Entry Gate / Traffic Control (Ultrasonic + Servo)
  3. Air Quality Monitoring System (MQ135 sensor)
  4. Alert System (Buzzer for pollution warning)

Each subsystem works independently but is controlled by a single Arduino UNO, simulating how real smart-city nodes operate.


Components Used

  • Arduino UNO
  • LDR (Light Dependent Resistor – discrete, not module)
  • Ultrasonic Sensor (HC-SR04)
  • Servo Motor (gate control)
  • MQ135 Air Quality Sensor
  • Buzzer
  • LEDs (street lights)
  • 330 Ω resistors (current limiting)
  • Breadboard, jumper wires, external LED wiring

🔌 Circuit Diagram

🧩 Complete circuit diagram for this project:

Open circuit Open circuit

The circuit includes:

  • LDR voltage divider connected to an analog input
  • Ultrasonic sensor connected to digital pins
  • Servo motor connected to a PWM pin
  • MQ135 sensor connected to an analog input
  • Buzzer connected to a digital output
  • LED street lights driven through resistors

Street Light Implementation (Important Design Detail)

To simulate street lights, multiple LEDs were used.

Instead of driving LEDs directly from the Arduino pin, the following safe current-limiting method was implemented:

  • Two GPIO pins were used for street lighting
  • Each GPIO pin was connected through a 330 Ω resistor
  • The other end of each resistor was connected to 4–5 LEDs in parallel

Why this method was used

  • The resistor limits the current drawn from the GPIO pin
  • Using two GPIOs distributes the load instead of stressing a single pin
  • Parallel LEDs represent multiple street lights connected to one junction

This approach keeps the circuit safe for the Arduino while still allowing multiple LEDs to turn ON together during night conditions.


Automatic Street Light Logic (LDR)

  • The LDR continuously measures ambient light
  • During daytime:
    • LDR value is high
    • Street LEDs remain OFF
  • During night:
    • LDR value drops below a threshold
    • Street LEDs turn ON automatically

This demonstrates energy conservation, a core principle of smart cities.


Smart Gate / Traffic Control System

An ultrasonic sensor is placed near the entry point of the model.

  • When a vehicle or object comes within a fixed distance:
    • The ultrasonic sensor detects it
    • The servo motor rotates
    • The gate opens automatically
  • When the object moves away:
    • The gate closes again

This simulates automatic toll gates, parking entry systems, and traffic barriers.


Air Quality Monitoring (MQ135 Sensor)

To introduce environmental monitoring, an MQ135 air quality sensor was added.

  • The sensor measures pollution levels in the surrounding air
  • When the pollution value crosses a preset threshold:
    • The buzzer turns ON
    • This acts as an air pollution warning

This models how pollution monitoring stations work in smart cities.


Alert System (Buzzer)

The buzzer is used as a city alert mechanism.

  • OFF during normal air conditions
  • ON when pollution exceeds safe limits

This introduces the concept of public warning systems and real-time environmental alerts.


💻 Firmware Upload (Arduino Code)

Flash the firmware directly to Arduino UNO:

👉 This allows users to upload the tested firmware without opening the Arduino IDE.

#include <Servo.h>

#define TRIG_PIN 9
#define ECHO_PIN 8
#define LED_PIN  3
#define LED_PIN1 5
#define LDR_PIN  A0
#define MQ135_PIN A1
#define BUZZER_PIN 7
#define SERVO_PIN 6

Servo gateServo;

long duration;
int distance;
int ldrValue;
int airValue;

int LDR_THRESHOLD = 500;     // adjust after testing
int DIST_THRESHOLD = 15;     // cm
int AIR_THRESHOLD  = 400;    // MQ135 threshold (adjust)

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(LED_PIN1, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  gateServo.attach(SERVO_PIN);
  gateServo.write(90);   // gate closed

  Serial.begin(9600);
  Serial.println("Smart City System Starting...");
}

void loop() {

  /* ---------- LDR STREET LIGHT ---------- */
  ldrValue = analogRead(LDR_PIN);

  if (ldrValue < LDR_THRESHOLD) {
    analogWrite(LED_PIN, 255);     // street light ON
    digitalWrite(LED_PIN1, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);    // street light OFF
    digitalWrite(LED_PIN1, LOW);
  }

  /* ---------- ULTRASONIC SENSOR ---------- */
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  duration = pulseIn(ECHO_PIN, HIGH, 30000);
  distance = duration * 0.034 / 2;

  /* ---------- SERVO GATE CONTROL ---------- */
  if (distance > 0 && distance < DIST_THRESHOLD) {
    gateServo.write(0);    // open gate
  } else {
    gateServo.write(90);   // close gate
  }

  /* ---------- MQ135 AIR QUALITY ---------- */
  airValue = analogRead(MQ135_PIN);

  if (airValue > AIR_THRESHOLD) {
    digitalWrite(BUZZER_PIN, HIGH);   // pollution alert
  } else {
    digitalWrite(BUZZER_PIN, LOW);
  }

  /* ---------- SERIAL MONITOR ---------- */
  Serial.print("LDR: ");
  Serial.print(ldrValue);
  Serial.print(" | Distance: ");
  Serial.print(distance);
  Serial.print(" cm | Air: ");
  Serial.println(airValue);

  delay(1000);
}

Software Logic Summary

The Arduino program continuously performs:

  • Ambient light measurement (LDR)
  • Distance measurement (Ultrasonic)
  • Air quality measurement (MQ135)
  • Decision-making based on thresholds
  • Actuator control (LEDs, servo, buzzer)

All logic runs in a loop, similar to how embedded systems operate in real infrastructure.


Educational Value

This project helps learners understand:

  • GPIO usage and current limiting
  • Sensor interfacing and calibration
  • Real-world automation logic
  • Embedded decision-making
  • Power and safety considerations
  • Smart city concepts beyond theory

Unlike ready-made kits, this setup uses discrete components, encouraging deeper understanding and troubleshooting skills.


Conclusion

This Smart City project demonstrates how simple electronics and embedded programming can be combined to address urban automation challenges such as energy efficiency, traffic control, and pollution monitoring.

It serves as a reference implementation for students and educators exploring smart-city concepts using Arduino.

Posted on Leave a comment

Arduino Uno Dot Matrix Display Using MAX7219 (Scrolling Text)

In this project, we interface an 8×8 Dot Matrix Display (MAX7219) with Arduino Uno to display scrolling text using the MD_Parola library.

This setup is ideal for learning:

  • SPI communication
  • External display control
  • Library-based programming
  • Real-time visual output from code

All components, wiring, code, and flashing are available on a single page for smooth lab execution.


Circuit Diagram (Arduino Uno + MAX7219)

The circuit below shows the exact wiring required between the Arduino Uno and the dot matrix module.

👉 Open this on the board or laptop and follow the connections directly.

Open circuit Open circuit

Pin Connections

MAX7219 ModuleArduino Uno
VCC5V
GNDGND
DIND11
CS / LOADD10
CLKD13

Output Preview

The following video shows the expected output after successful wiring and code upload.

📺 Demo Video
https://youtube.com/shorts/sZoBYKpf11I


Required Libraries

This project uses the following Arduino libraries:

  • MD_MAX72XX
  • MD_Parola

How to Install Libraries

  1. Open Arduino IDE
  2. Go to Sketch → Include Library → Manage Libraries
  3. Search and install:
    • MD_MAX72XX
    • MD_Parola
  4. Restart Arduino IDE after installation

If libraries are missing, the code will not compile.


Arduino Uno Code (Scrolling Text)

Copy and paste the following code into Arduino IDE:

#include <MD_Parola.h>
#include <MD_MAX72XX.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 1   // Number of dot matrix modules
#define CS_PIN 10       // CS (LOAD) pin

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

void setup() {
  P.begin();
  P.displayText("HELLO!", PA_CENTER, 70, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}

void loop() {
  if (P.displayAnimate()) {
    P.displayReset();
  }
}

Uploading Code to Arduino Uno

  1. Connect Arduino Uno using USB cable
  2. Select:
    • Board: Arduino Uno
    • Port: Correct COM port
  3. Click Upload

One-Click Arduino Flash (Recommended)

To avoid IDE and driver issues, use the flash button below to upload firmware directly.


Common Issues and Fixes

  • No display output
    • Check VCC and GND
    • Verify CS pin is set to 10 in code
  • Compilation error
    • Confirm both libraries are installed
  • Display orientation incorrect
    • Ensure FC16_HW hardware type is selected

Next Steps

You can extend this project by:

  • Adding a joystick to control text movement
  • Changing text dynamically
  • Using multiple dot matrix modules
  • Creating interactive animations

This project forms a strong foundation for input + output based embedded systems.

Posted on Leave a comment

AI Robot Head Tracking Using Browser Vision (No Training, No Server)

Turn your head left, right, up, and down.
Open circuit Open circuit

Download FreeCAD project and STL files

Introduction

Most “AI robot face” demos rely on heavy machine-learning models, cloud APIs, or large datasets.
This project explores a different approach:

Using simple geometry and browser-based vision to create an expressive robot head that reacts to human movement in real time.

The robot head tracks left, right, up, and down head motion and mirrors it using animated eyes displayed on a small OLED screen — all controlled directly from a web browser.

No dataset.
No model training.
No server.

What This Project Does

  • Detects a human face using the browser camera
  • Estimates head orientation (yaw & pitch)
  • Sends motion data to an Arduino using Web Serial
  • Animates eye movement on a 0.96″ OLED display
  • Allows direction inversion (mirror correction) at runtime

The result is a small robot head that feels responsive and alive.

System Architecture

Browser Camera
      ↓
Face Geometry (MediaPipe)
      ↓
Yaw & Pitch Calculation
      ↓
Web Serial (USB)
      ↓
Arduino UNO
      ↓
OLED Eye Animation

All computation happens locally in the browser.

Hardware Used

  • Arduino UNO
  • 0.96″ OLED (SSD1306, I2C)
  • USB cable
  • 3D-printed enclosure

Software Stack

  • HTML + JavaScript
  • MediaPipe Face Mesh
  • Web Serial API
  • Arduino (C++)

Key Design Decisions

1. Pupils Move, Not Eyeballs

Moving only the pupils inside fixed eyeballs makes the face feel more natural and expressive.

2. Face-Relative Geometry

Head motion is measured relative to facial landmarks, not camera pixels.
This makes movement symmetric and stable.

3. Runtime Direction Flip

A toggle button allows instant correction for mirrored cameras without changing code.


Educational Value

This project can be used to teach:

  • Coordinate systems
  • Geometry-based tracking
  • Browser ↔ hardware communication
  • Human-centered design

It is suitable for classrooms, labs, and exhibitions.


Conclusion

This robot head demonstrates that intelligence is not just about models, but about understanding interaction.

By combining browser vision, simple math, and embedded hardware, we can build systems that feel responsive, expressive, and intuitive — without complexity.


Try It Live

Allow camera access, connect the Arduino, and move your head left, right, up, and down.

Posted on Leave a comment

RGB LED with Arduino UNO/Nano

What is an RGB LED and What Are We Building Here?

An RGB LED is a special type of LED that contains three LEDs inside one packageRed, Green, and Blue.
Using these three colours, the Arduino can blend them at different brightness levels to produce hundreds of colours like yellow, cyan, purple, pink, white, sky-blue, etc.

In this example, we are using a Common-Cathode RGB LED, which means:

  • All three LEDs share one common negative (–) pin
  • The individual colour pins (R, G, B) must be connected through 220Ω resistors
  • The Arduino controls brightness using PWM pins
    • Red → D3
    • Green → D5
    • Blue → D6

This forms the basis for colour-mixing projects used in IoT, indicators, robots, and UI feedback systems.

Below, you can see the circuit wiring diagram, the mBlock representation, and the equivalent Arduino IDE code.
Finally, you can flash the firmware directly from this page using ExaSub’s online uploader — no Arduino IDE installation required.

Open circuit Open circuit

Arduino IDE CODE

// RGB LED with Arduino Nano
// Common Cathode RGB LED
// R -> D3, G -> D5, B -> D6

int redPin = 3;
int greenPin = 5;
int bluePin = 6;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  setColor(255, 0, 0);   // Red
  delay(800);

  setColor(0, 255, 0);   // Green
  delay(800);

  setColor(0, 0, 255);   // Blue
  delay(800);

  setColor(255, 255, 0); // Yellow (Red + Green)
  delay(800);

  setColor(80, 0, 255);  // Purple
  delay(800);

  setColor(0, 255, 255); // Cyan (Green + Blue)
  delay(800);

  setColor(255, 255, 255); // White
  delay(800);

  setColor(0, 0, 0);     // Off
  delay(800);
}

// Function to mix RGB
void setColor(int r, int g, int b) {
  analogWrite(redPin, 255 - r);    // common cathode → invert logic
  analogWrite(greenPin, 255 - g);
  analogWrite(bluePin, 255 - b);
}

Mblock Code

Flash Arduino UNO/Nano Directly From Browser Click on Button

Note: Nano with old bootloader is not supported. Use the code with the arduino IDE for the Nano with old bootloader.