🛠️ IoT Projects – Complete Guide

Beginner to Advanced Projects using ESP32 & Sensors

Hands-on IoT projects with full details — components, wiring, code, working explanation, and real-world applications. Every project built with sensors and ESP32.

🌡️ Project 1: IoT Weather Station

BEGINNER

📌 Project Description

Build a weather monitoring station that measures temperature, humidity, and atmospheric pressure in real time. Data is displayed on an OLED screen and can be sent to the cloud.

🔧 Components Required

ESP32 DHT22 Sensor BMP280 Sensor 0.96" OLED Display (SSD1306) Breadboard Jumper Wires USB Cable

📐 Circuit Connections

ComponentPinESP32 Pin
DHT22 VCCVCC3.3V
DHT22 DATADATAGPIO 4
DHT22 GNDGNDGND
BMP280 VCCVIN3.3V
BMP280 GNDGNDGND
BMP280 SDASDAGPIO 21
BMP280 SCLSCLGPIO 22
OLED VCCVCC3.3V
OLED GNDGNDGND
OLED SDASDAGPIO 21
OLED SCLSCLGPIO 22

🔌 Wiring Diagram

ESP32 DHT22 BMP280 OLED (I2C) ┌──────┐ ┌─────┐ ┌──────┐ ┌──────┐ │ 3.3V ├───┬────┤ VCC │ ┌────┤ VIN │ ┌────┤ VCC │ │ │ │ │ │ │ │ │ │ │ │ │ GND ├───┼──┬─┤ GND │ ──┼──┬─┤ GND │ ──┼──┬─┤ GND │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ GP4 ├───┘ │ ┤ DAT │ │ │ │ │ │ │ │ │ │ │ │ └─────┘ │ │ │ │ │ │ │ │ │ GP21 ├──────┼────────────┼──┼─┤ SDA ├───┼──┼─┤ SDA │ │ GP22 ├──────┼────────────┘ │ ┤ SCL ├───┘ │ ┤ SCL │ └──────┘ └───────────────┘ └──────┘ └─└──────┘

⚙️ How It Works

DHT22 reads Temp & Humidity BMP280 reads Pressure & Altitude ESP32 processes data Displays on OLED

💻 Arduino Code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#include <Adafruit_BMP280.h>

#define DHTPIN 4
#define DHTTYPE DHT22
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bmp;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  Serial.begin(115200);
  dht.begin();
  bmp.begin(0x76);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
}

void loop() {
  float temp = dht.readTemperature();
  float hum  = dht.readHumidity();
  float pres = bmp.readPressure() / 100.0F;

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);

  display.setCursor(0, 0);
  display.print("Temp: ");
  display.print(temp);
  display.println(" C");

  display.print("Humidity: ");
  display.print(hum);
  display.println(" %");

  display.print("Pressure: ");
  display.print(pres);
  display.println(" hPa");

  display.display();
  delay(2000);
}

📦 Libraries Required

Library NameInstall From
DHT sensor libraryArduino Library Manager
Adafruit BMP280Arduino Library Manager
Adafruit SSD1306Arduino Library Manager
Adafruit GFX LibraryArduino Library Manager

🎯 Learning Outcomes

I2C Communication Sensor Reading OLED Display Multi-sensor Wiring

🚀 Real World Applications

💡 Project 2: Automatic Smart Lighting System

BEGINNER

📌 Project Description

An automatic lighting system that turns an LED/relay ON when it's dark and OFF when there's sufficient light, using an LDR (Light Dependent Resistor). Mimics a real automatic street light.

🔧 Components Required

ESP32 LDR (Photoresistor) 10kΩ Resistor LED / Relay Module Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
LDROne end3.3V
LDROther endGPIO 34 (via voltage divider)
10kΩ ResistorBetween GPIO 34 and GNDVoltage divider
LED (+)AnodeGPIO 2 (via 220Ω resistor)
LED (−)CathodeGND

🔌 Wiring Diagram

3.3V │ [LDR] │ GPIO 34 ───┤ │ [10kΩ] │ GND GPIO 2 ──[220Ω]──LED──GND

⚙️ How It Works

LDR detects light level ESP32 reads analog value (ADC) If dark (value < threshold) Turn ON LED/Relay

In bright light, LDR resistance is low → voltage at GPIO 34 is high → LED OFF.
In darkness, LDR resistance is high → voltage at GPIO 34 drops → LED ON.

💻 Arduino Code

#define LDR_PIN  34
#define LED_PIN  2
#define THRESHOLD 1000

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  int lightVal = analogRead(LDR_PIN);
  Serial.print("Light: ");
  Serial.println(lightVal);

  if (lightVal < THRESHOLD) {
    digitalWrite(LED_PIN, HIGH);  // Dark → LED ON
    Serial.println("LED ON - It's dark");
  } else {
    digitalWrite(LED_PIN, LOW);   // Bright → LED OFF
    Serial.println("LED OFF - Sufficient light");
  }
  delay(500);
}

🎯 Learning Outcomes

ADC Reading Voltage Divider Threshold Logic Digital Output

🚀 Real World Applications

💨 Project 3: Gas Leakage Alarm System

BEGINNER

📌 Project Description

A safety system that detects LPG, smoke, or methane gas leakage using the MQ-2 sensor. When gas is detected above a threshold, it triggers a buzzer alarm and LED warning.

🔧 Components Required

ESP32 MQ-2 Gas Sensor Buzzer (Active) Red LED 220Ω Resistor Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
MQ-2 VCCVCCVIN (5V)
MQ-2 GNDGNDGND
MQ-2 A0Analog OutGPIO 34
Buzzer (+)PositiveGPIO 18
Buzzer (−)NegativeGND
Red LED (+)AnodeGPIO 2 (via 220Ω)
Red LED (−)CathodeGND

⚙️ How It Works

MQ-2 detects gas Analog voltage rises ESP32 reads ADC value If > threshold → Buzzer ON + LED ON

MQ-2 has a tin dioxide (SnO2) sensing element. In clean air, resistance is high. When combustible gas is present, resistance drops → output voltage increases.

⚠️ Important: MQ-2 needs a preheat time of ~20 seconds after power-on for accurate readings. The sensor runs hot — do not touch during operation.

💻 Arduino Code

#define MQ2_PIN    34
#define BUZZER_PIN 18
#define LED_PIN    2
#define GAS_THRESHOLD 1500

void setup() {
  Serial.begin(115200);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.println("Gas Sensor warming up...");
  delay(20000); // 20 sec preheat
  Serial.println("Sensor ready!");
}

void loop() {
  int gasVal = analogRead(MQ2_PIN);
  Serial.print("Gas Value: ");
  Serial.println(gasVal);

  if (gasVal > GAS_THRESHOLD) {
    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);
    Serial.println("⚠ GAS DETECTED! ALARM ON!");
  } else {
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
  }
  delay(500);
}

🎯 Learning Outcomes

Analog Sensor Reading Threshold Alarm Buzzer Control Safety System Design

🚀 Real World Applications

🚨 Project 4: PIR Security Alarm System

BEGINNER

📌 Project Description

A motion-detection security system using a PIR sensor. When human movement is detected, the system triggers a buzzer, LED alert, and prints alert on Serial Monitor. Can be extended to send notifications via WiFi.

🔧 Components Required

ESP32 PIR Sensor (HC-SR501) Buzzer Red LED 220Ω Resistor Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
PIR VCCVCCVIN (5V)
PIR GNDGNDGND
PIR OUTSignalGPIO 27
Buzzer (+)PositiveGPIO 18
Buzzer (−)NegativeGND
LED (+)AnodeGPIO 2 (via 220Ω)
LED (−)CathodeGND

⚙️ How It Works

PIR detects infrared change (human body heat) Output pin goes HIGH ESP32 reads digital signal Buzzer + LED activated

PIR sensors detect changes in infrared radiation caused by warm bodies (humans/animals) moving in its field of view. The sensor has two adjustment potentiometers: Sensitivity and Delay Time.

💻 Arduino Code

#define PIR_PIN    27
#define BUZZER_PIN 18
#define LED_PIN    2

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.println("PIR warming up (30s)...");
  delay(30000); // PIR stabilization time
  Serial.println("Security System ACTIVE");
}

void loop() {
  int motion = digitalRead(PIR_PIN);

  if (motion == HIGH) {
    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);
    Serial.println("🚨 MOTION DETECTED!");
    delay(3000); // Alarm for 3 seconds
  } else {
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
  }
  delay(200);
}

🎯 Learning Outcomes

Digital Input PIR Sensor Interface Alarm Logic Security Application

🚀 Real World Applications

💓 Project 5: Health Monitor (Heart Rate + SpO2)

ADVANCED

📌 Project Description

A wearable-ready health monitoring system using the MAX30102 sensor to measure heart rate (BPM) and blood oxygen level (SpO2). Data is displayed on an OLED screen and can be sent to cloud/mobile via WiFi/BLE.

🔧 Components Required

ESP32 MAX30102 Sensor 0.96" OLED Display (SSD1306) Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
MAX30102 VINVIN3.3V
MAX30102 GNDGNDGND
MAX30102 SDASDAGPIO 21
MAX30102 SCLSCLGPIO 22
OLED VCCVCC3.3V
OLED GNDGNDGND
OLED SDASDAGPIO 21
OLED SCLSCLGPIO 22
Both MAX30102 and OLED use I2C protocol and share the same SDA/SCL lines. They work together because they have different I2C addresses (MAX30102: 0x57, OLED: 0x3C).

⚙️ How It Works

MAX30102 emits Red & IR LED light Light passes through finger Photodetector reads absorption ESP32 calculates BPM & SpO2 Displays on OLED

Heart Rate: Detected by measuring the pulsatile component of blood flow using the IR LED.
SpO2: Calculated by comparing absorption of Red vs IR light — oxygenated blood absorbs more IR, deoxygenated absorbs more Red light.

💻 Arduino Code

#include <Wire.h>
#include <MAX30105.h>
#include <heartRate.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

MAX30105 particleSensor;
Adafruit_SSD1306 display(128, 64, &Wire, -1);

const byte RATE_SIZE = 4;
byte rates[RATE_SIZE];
byte rateSpot = 0;
long lastBeat = 0;
float beatsPerMinute;
int beatAvg;

void setup() {
  Serial.begin(115200);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();

  if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) {
    Serial.println("MAX30102 not found!");
    while(1);
  }
  particleSensor.setup();
  particleSensor.setPulseAmplitudeRed(0x0A);
  particleSensor.setPulseAmplitudeIR(0x0A);
}

void loop() {
  long irValue = particleSensor.getIR();

  if (checkForBeat(irValue)) {
    long delta = millis() - lastBeat;
    lastBeat = millis();
    beatsPerMinute = 60 / (delta / 1000.0);

    if (beatsPerMinute < 255 && beatsPerMinute > 20) {
      rates[rateSpot++] = (byte)beatsPerMinute;
      rateSpot %= RATE_SIZE;
      beatAvg = 0;
      for (byte x = 0; x < RATE_SIZE; x++)
        beatAvg += rates[x];
      beatAvg /= RATE_SIZE;
    }
  }

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);

  if (irValue < 50000) {
    display.println("Place finger on sensor");
  } else {
    display.print("BPM: ");
    display.println(beatsPerMinute);
    display.print("Avg BPM: ");
    display.println(beatAvg);
  }
  display.display();
}

📦 Libraries Required

Library NamePurpose
SparkFun MAX3010xMAX30102 sensor driver
Adafruit SSD1306OLED display driver
Adafruit GFX LibraryGraphics primitives

🎯 Learning Outcomes

I2C Multi-device Biomedical Sensing Signal Processing Real-time Display

🚀 Real World Applications

🌱 Project 6: Smart Irrigation System

INTERMEDIATE

📌 Project Description

An automated plant watering system that monitors soil moisture and turns a water pump ON/OFF via relay. Keeps plants healthy by watering only when soil is dry.

🔧 Components Required

ESP32 Soil Moisture Sensor 5V Relay Module Mini Water Pump (5V) Water Tube Breadboard Jumper Wires External 5V Supply (for pump)

📐 Circuit Connections

ComponentPinESP32 Pin
Soil Sensor VCCVCC3.3V
Soil Sensor GNDGNDGND
Soil Sensor A0Analog OutGPIO 34
Relay VCCVCCVIN (5V)
Relay GNDGNDGND
Relay INSignalGPIO 26
PumpVia RelayExternal 5V through relay switch

⚙️ How It Works

Soil sensor reads moisture ESP32 reads analog value If soil is dry (high value) Relay ON → Pump waters plant Soil wet → Pump OFF

Dry soil → high resistance → high analog value → pump ON.
Wet soil → low resistance → low analog value → pump OFF.

💻 Arduino Code

#define SOIL_PIN  34
#define RELAY_PIN 26
#define DRY_THRESHOLD 2800  // Adjust after testing
#define WET_THRESHOLD 1500

void setup() {
  Serial.begin(115200);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH); // Relay OFF (active LOW)
}

void loop() {
  int soilVal = analogRead(SOIL_PIN);
  Serial.print("Soil Moisture: ");
  Serial.println(soilVal);

  if (soilVal > DRY_THRESHOLD) {
    digitalWrite(RELAY_PIN, LOW);  // Pump ON
    Serial.println("Soil DRY → Pump ON");
  }
  else if (soilVal < WET_THRESHOLD) {
    digitalWrite(RELAY_PIN, HIGH); // Pump OFF
    Serial.println("Soil WET → Pump OFF");
  }

  delay(2000);
}

🎯 Learning Outcomes

Relay Control Analog Sensing Hysteresis Logic Actuator Integration

🚀 Real World Applications

🤖 Project 7: Obstacle Avoiding Robot

INTERMEDIATE

📌 Project Description

A mobile robot that uses an HC-SR04 ultrasonic sensor to detect obstacles and automatically avoids them by changing direction. Core robotics project.

🔧 Components Required

ESP32 HC-SR04 Ultrasonic Sensor L298N Motor Driver 2x DC Motors Robot Chassis Wheels Battery Pack (7.4V) Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
HC-SR04 VCCVCCVIN (5V)
HC-SR04 GNDGNDGND
HC-SR04 TRIGTriggerGPIO 5
HC-SR04 ECHOEchoGPIO 18 (voltage divider!)
L298N IN1Motor A DirGPIO 25
L298N IN2Motor A DirGPIO 26
L298N IN3Motor B DirGPIO 27
L298N IN4Motor B DirGPIO 32
L298N ENASpeed A (PWM)GPIO 33
L298N ENBSpeed B (PWM)GPIO 4
⚠️ HC-SR04 ECHO pin outputs 5V. Use a voltage divider (2 resistors) to step down to 3.3V before connecting to ESP32.

⚙️ How It Works

Ultrasonic sends sound pulse Pulse bounces off obstacle ESP32 calculates distance If < 20cm → Stop & Turn If clear → Move forward

Distance formula: Distance (cm) = (Time × 0.034) / 2

💻 Arduino Code

#define TRIG 5
#define ECHO 18
#define IN1  25
#define IN2  26
#define IN3  27
#define IN4  32

void setup() {
  Serial.begin(115200);
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
}

long getDistance() {
  digitalWrite(TRIG, LOW);  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  long dur = pulseIn(ECHO, HIGH);
  return dur * 0.034 / 2;
}

void moveForward()  { digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
                       digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); }
void turnRight()    { digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
                       digitalWrite(IN3,LOW);  digitalWrite(IN4,HIGH); }
void stopMotors()   { digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
                       digitalWrite(IN3,LOW); digitalWrite(IN4,LOW); }

void loop() {
  long dist = getDistance();
  Serial.print("Distance: "); Serial.print(dist); Serial.println(" cm");

  if (dist < 20) {
    stopMotors();  delay(300);
    turnRight();  delay(400);
  } else {
    moveForward();
  }
  delay(100);
}

🎯 Learning Outcomes

Ultrasonic Distance Motor Control Decision Logic Robotics Basics

🅿️ Project 8: Smart Parking System

INTERMEDIATE

📌 Project Description

A smart parking slot indicator that uses IR sensors to detect whether parking slots are occupied or vacant. Displays status on an OLED and can serve data via WiFi web page.

🔧 Components Required

ESP32 3x IR Sensor Modules 3x LEDs (Red/Green) 0.96" OLED Display Breadboard Jumper Wires

📐 Circuit Connections

ComponentESP32 PinPurpose
IR Sensor 1 OUTGPIO 32Slot 1 detection
IR Sensor 2 OUTGPIO 33Slot 2 detection
IR Sensor 3 OUTGPIO 34Slot 3 detection
Green LED 1GPIO 25Slot 1 vacant
Green LED 2GPIO 26Slot 2 vacant
Green LED 3GPIO 27Slot 3 vacant
OLED SDA/SCLGPIO 21 / 22Status display

⚙️ How It Works

IR sensors check each slot Object detected = Occupied No object = Vacant Display on OLED + LEDs

💻 Arduino Code

#define IR1 32
#define IR2 33
#define IR3 34
#define LED1 25
#define LED2 26
#define LED3 27

void setup() {
  Serial.begin(115200);
  pinMode(IR1, INPUT); pinMode(IR2, INPUT); pinMode(IR3, INPUT);
  pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT);
}

void checkSlot(int irPin, int ledPin, int slotNum) {
  int val = digitalRead(irPin);
  if (val == LOW) { // Object detected
    digitalWrite(ledPin, LOW);  // Red = occupied
    Serial.print("Slot "); Serial.print(slotNum);
    Serial.println(": OCCUPIED");
  } else {
    digitalWrite(ledPin, HIGH); // Green = vacant
    Serial.print("Slot "); Serial.print(slotNum);
    Serial.println(": VACANT");
  }
}

void loop() {
  checkSlot(IR1, LED1, 1);
  checkSlot(IR2, LED2, 2);
  checkSlot(IR3, LED3, 3);
  Serial.println("---");
  delay(1000);
}

🎯 Learning Outcomes

IR Sensor Usage Multi-sensor System Status Indicators Smart City Concept

👏 Project 9: Clap Switch

BEGINNER

📌 Project Description

Toggle an LED or relay ON/OFF using clap sounds detected by a sound sensor module. One clap = ON, another clap = OFF.

🔧 Components Required

ESP32 Sound Sensor Module LED / Relay 220Ω Resistor Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
Sound Sensor VCCVCC3.3V
Sound Sensor GNDGNDGND
Sound Sensor DODigital OutGPIO 27
LED (+)AnodeGPIO 2 (via 220Ω)
LED (−)CathodeGND

💻 Arduino Code

#define SOUND_PIN 27
#define LED_PIN   2
bool ledState = false;

void setup() {
  Serial.begin(115200);
  pinMode(SOUND_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  int soundVal = digitalRead(SOUND_PIN);

  if (soundVal == HIGH) {
    ledState = !ledState;
    digitalWrite(LED_PIN, ledState);
    Serial.println(ledState ? "CLAP → LED ON" : "CLAP → LED OFF");
    delay(300); // Debounce
  }
}

🎯 Learning Outcomes

Sound Detection Toggle Logic Debouncing Digital Input

🖐️ Project 10: Touch-Based Switch Panel

BEGINNER

📌 Project Description

Use ESP32's built-in capacitive touch pins to create a touch switch panel that controls multiple LEDs — no physical buttons required.

🔧 Components Required

ESP32 3x LEDs 3x 220Ω Resistors Copper tape / Metal pads Jumper Wires

📐 Circuit Connections

Touch PadESP32 PinControls
Touch Pad 1 (wire/copper)GPIO 4 (Touch0)LED 1 on GPIO 25
Touch Pad 2GPIO 15 (Touch3)LED 2 on GPIO 26
Touch Pad 3GPIO 13 (Touch4)LED 3 on GPIO 27
ESP32 has 10 built-in capacitive touch pins (T0–T9). No external touch sensor module needed! Simply attach a wire or copper tape to the GPIO pin.

💻 Arduino Code

#define TOUCH1 4
#define TOUCH2 15
#define TOUCH3 13
#define LED1   25
#define LED2   26
#define LED3   27
#define THRESH 30

bool state1=false, state2=false, state3=false;

void setup() {
  Serial.begin(115200);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
}

void loop() {
  if (touchRead(TOUCH1) < THRESH) {
    state1 = !state1;
    digitalWrite(LED1, state1);
    delay(300);
  }
  if (touchRead(TOUCH2) < THRESH) {
    state2 = !state2;
    digitalWrite(LED2, state2);
    delay(300);
  }
  if (touchRead(TOUCH3) < THRESH) {
    state3 = !state3;
    digitalWrite(LED3, state3);
    delay(300);
  }
}

🎯 Learning Outcomes

Capacitive Touch ESP32 Hardware Feature Toggle Logic No External Module

🤸 Project 11: Fall Detection System

ADVANCED

📌 Project Description

An accelerometer-based fall detection system using MPU6050. When a sudden acceleration change (fall) is detected, it triggers an alert — ideal for elderly care and medical wearables.

🔧 Components Required

ESP32 MPU6050 (Accelerometer + Gyroscope) Buzzer LED Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
MPU6050 VCCVCC3.3V
MPU6050 GNDGNDGND
MPU6050 SDASDAGPIO 21
MPU6050 SCLSCLGPIO 22
Buzzer (+)PositiveGPIO 18
LED (+)AnodeGPIO 2 (via 220Ω)

⚙️ How It Works

MPU6050 reads acceleration (X, Y, Z) Calculate total acceleration magnitude If sudden spike > threshold Fall detected → Alert!

Fall detection formula: magnitude = √(ax² + ay² + az²)
Normal standing ≈ 1g (~9.8 m/s²). A fall causes sudden spike to 2–3g followed by freefall (near 0g).

💻 Arduino Code

#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>

#define BUZZER 18
#define LED    2
#define FALL_THRESHOLD 2.5  // in g-force

Adafruit_MPU6050 mpu;

void setup() {
  Serial.begin(115200);
  pinMode(BUZZER, OUTPUT);
  pinMode(LED, OUTPUT);

  if (!mpu.begin()) {
    Serial.println("MPU6050 not found!");
    while(1);
  }
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  Serial.println("Fall Detection Active");
}

void loop() {
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  float ax = a.acceleration.x / 9.8;
  float ay = a.acceleration.y / 9.8;
  float az = a.acceleration.z / 9.8;
  float magnitude = sqrt(ax*ax + ay*ay + az*az);

  Serial.print("Accel magnitude: ");
  Serial.println(magnitude);

  if (magnitude > FALL_THRESHOLD) {
    Serial.println("⚠ FALL DETECTED!");
    digitalWrite(BUZZER, HIGH);
    digitalWrite(LED, HIGH);
    delay(5000);  // Alert for 5 seconds
    digitalWrite(BUZZER, LOW);
    digitalWrite(LED, LOW);
  }
  delay(100);
}

🎯 Learning Outcomes

IMU Sensor Vector Magnitude Medical IoT Threshold Detection

☁️ Project 12: IoT Cloud Weather Logger (WiFi)

ADVANCED

📌 Project Description

Send DHT22 temperature & humidity data to ThingSpeak cloud via ESP32 WiFi. View real-time graphs from anywhere in the world.

🔧 Components Required

ESP32 DHT22 Sensor WiFi Network ThingSpeak Account (free) Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
DHT22 VCCVCC3.3V
DHT22 DATADATAGPIO 4
DHT22 GNDGNDGND

⚙️ How It Works

DHT22 reads data ESP32 connects to WiFi HTTP GET to ThingSpeak API Data logged in cloud View graphs online

Setup Steps

Create ThingSpeak account at thingspeak.com
Create a new Channel with 2 fields: Temperature, Humidity
Copy the Write API Key from API Keys tab
Upload code with your WiFi credentials and API key

💻 Arduino Code

#include <WiFi.h>
#include <HTTPClient.h>
#include <DHT.h>

#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

const char* ssid     = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* apiKey   = "YOUR_THINGSPEAK_API_KEY";
const char* server   = "http://api.thingspeak.com/update";

void setup() {
  Serial.begin(115200);
  dht.begin();
  WiFi.begin(ssid, password);

  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" Connected!");
}

void loop() {
  float temp = dht.readTemperature();
  float hum  = dht.readHumidity();

  if (isnan(temp) || isnan(hum)) {
    Serial.println("DHT read failed!");
    return;
  }

  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = String(server) + "?api_key=" + apiKey
               + "&field1=" + String(temp)
               + "&field2=" + String(hum);

    http.begin(url);
    int code = http.GET();
    Serial.print("Sent! Response: ");
    Serial.println(code);
    http.end();
  }
  delay(20000); // ThingSpeak free: 15s min interval
}

🎯 Learning Outcomes

WiFi Connectivity HTTP API Calls Cloud IoT Platform Remote Monitoring

💧 Project 13: Water Tank Overflow Alert

BEGINNER

📌 Project Description

Uses a water level sensor and HC-SR04 ultrasonic sensor to monitor water level in a tank. Alerts with buzzer when the tank is about to overflow.

🔧 Components Required

ESP32 HC-SR04 Ultrasonic Sensor Buzzer 3x LEDs (Green, Yellow, Red) 220Ω Resistors Breadboard Jumper Wires

📐 Circuit Connections

ComponentESP32 PinPurpose
HC-SR04 TRIGGPIO 5Trigger pulse
HC-SR04 ECHOGPIO 18Echo return (use voltage divider)
BuzzerGPIO 19Overflow alarm
Green LEDGPIO 25Low level
Yellow LEDGPIO 26Medium level
Red LEDGPIO 27High / Overflow

⚙️ How It Works

Ultrasonic sensor is mounted at the top of the tank, pointing downward. It measures the distance to the water surface:

💻 Arduino Code

#define TRIG 5
#define ECHO 18
#define BUZZ 19
#define GREEN  25
#define YELLOW 26
#define RED    27

void setup() {
  Serial.begin(115200);
  pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT);
  pinMode(BUZZ, OUTPUT);
  pinMode(GREEN, OUTPUT); pinMode(YELLOW, OUTPUT); pinMode(RED, OUTPUT);
}

long getDistance() {
  digitalWrite(TRIG, LOW);  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  return pulseIn(ECHO, HIGH) * 0.034 / 2;
}

void loop() {
  long dist = getDistance();
  Serial.print("Water distance: "); Serial.print(dist); Serial.println(" cm");

  // Reset all
  digitalWrite(GREEN, LOW); digitalWrite(YELLOW, LOW);
  digitalWrite(RED, LOW);   digitalWrite(BUZZ, LOW);

  if (dist > 20) {
    digitalWrite(GREEN, HIGH); // Low level
  } else if (dist > 8) {
    digitalWrite(YELLOW, HIGH); // Medium
  } else {
    digitalWrite(RED, HIGH);  // Overflow!
    digitalWrite(BUZZ, HIGH);
    Serial.println("⚠ TANK OVERFLOW WARNING!");
  }
  delay(1000);
}

🎯 Learning Outcomes

Ultrasonic Sensor Multi-level Logic LED Indicators Home Automation

🌀 Project 14: Smart Fan Controller

INTERMEDIATE

📌 Project Description

Automatically controls fan speed based on room temperature using DHT11 and PWM. As temperature increases, the fan spins faster.

🔧 Components Required

ESP32 DHT11 Sensor DC Fan / Motor L298N Motor Driver or MOSFET External Power Supply Breadboard Jumper Wires

📐 Circuit Connections

ComponentPinESP32 Pin
DHT11 DATADATAGPIO 4
DHT11 VCCVCC3.3V
DHT11 GNDGNDGND
Motor Driver ENAPWM InputGPIO 25
Motor Driver IN1DirectionGPIO 26
Motor Driver IN2DirectionGPIO 27

⚙️ How It Works

DHT11 reads temperature ESP32 maps temp to PWM duty Higher temp = higher PWM Fan speed increases

💻 Arduino Code

#include <DHT.h>

#define DHTPIN  4
#define DHTTYPE DHT11
#define ENA     25
#define IN1     26
#define IN2     27
#define PWM_CH  0
#define PWM_FREQ 5000
#define PWM_RES  8

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);

  ledcSetup(PWM_CH, PWM_FREQ, PWM_RES);
  ledcAttachPin(ENA, PWM_CH);
}

void loop() {
  float temp = dht.readTemperature();
  Serial.print("Temp: "); Serial.print(temp); Serial.println(" °C");

  int speed = 0;
  if (temp < 25) speed = 0;
  else if (temp < 30) speed = 100;
  else if (temp < 35) speed = 180;
  else speed = 255;

  ledcWrite(PWM_CH, speed);
  Serial.print("Fan Speed: "); Serial.println(speed);

  delay(2000);
}

🎯 Learning Outcomes

PWM Motor Control Temperature Mapping ESP32 LEDC PWM Automation Logic

🏎️ Project 15: Line Follower Robot

INTERMEDIATE

📌 Project Description

A robot that follows a black line on a white surface using 2 IR sensors. The left and right sensors guide steering by controlling two DC motors.

🔧 Components Required

ESP32 2x IR Sensor Modules L298N Motor Driver 2x DC Motors Robot Chassis + Wheels Battery Pack Jumper Wires

📐 Circuit Connections

ComponentESP32 PinPurpose
Left IR Sensor OUTGPIO 32Detect left side of line
Right IR Sensor OUTGPIO 33Detect right side of line
L298N IN1GPIO 25Left Motor Forward
L298N IN2GPIO 26Left Motor Reverse
L298N IN3GPIO 27Right Motor Forward
L298N IN4GPIO 14Right Motor Reverse

⚙️ How It Works

Left IRRight IRAction
White (HIGH)White (HIGH)Move Forward
Black (LOW)White (HIGH)Turn Left
White (HIGH)Black (LOW)Turn Right
Black (LOW)Black (LOW)Stop

💻 Arduino Code

#define LEFT_IR  32
#define RIGHT_IR 33
#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14

void setup() {
  pinMode(LEFT_IR, INPUT); pinMode(RIGHT_IR, INPUT);
  pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
}

void forward()  { digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
                   digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); }
void left()     { digitalWrite(IN1,LOW);  digitalWrite(IN2,LOW);
                   digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); }
void right()    { digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
                   digitalWrite(IN3,LOW);  digitalWrite(IN4,LOW); }
void stopBot()  { digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
                   digitalWrite(IN3,LOW); digitalWrite(IN4,LOW); }

void loop() {
  int L = digitalRead(LEFT_IR);
  int R = digitalRead(RIGHT_IR);

  if (L == HIGH && R == HIGH) forward();
  else if (L == LOW && R == HIGH) left();
  else if (L == HIGH && R == LOW) right();
  else stopBot();
}

🎯 Learning Outcomes

IR Sensor Array Motor Control Decision Table Robotics Navigation

📊 All Projects – Quick Reference

# Project Key Sensor Difficulty Key Concept
1Weather StationDHT22 + BMP280BeginnerI2C, OLED Display
2Smart LightingLDRBeginnerADC, Threshold
3Gas AlarmMQ-2BeginnerAnalog Sensor, Alarm
4Security SystemPIRBeginnerDigital Input, Motion
5Health MonitorMAX30102AdvancedI2C, Biomedical
6Smart IrrigationSoil MoistureIntermediateRelay, Pump Control
7Obstacle RobotHC-SR04IntermediateUltrasonic, Motor
8Smart ParkingIR SensorIntermediateMulti-sensor, Display
9Clap SwitchSound SensorBeginnerSound, Toggle
10Touch PanelBuilt-in TouchBeginnerCapacitive Touch
11Fall DetectionMPU6050AdvancedIMU, Vector Math
12Cloud WeatherDHT22 + WiFiAdvancedHTTP, ThingSpeak
13Water OverflowHC-SR04BeginnerUltrasonic, Multi-LED
14Smart FanDHT11IntermediatePWM, Temp Mapping
15Line FollowerIR SensorIntermediateIR Array, Robotics

🏆 Recommended Learning Path

Start with Project 2 (Smart Lighting) — simplest ADC + LED project
Then Project 9 (Clap Switch) — learn digital input & toggle
Then Project 1 (Weather Station) — learn I2C & OLED
Then Project 3 & 4 (Gas Alarm + Security) — learn safety systems
Then Project 6 & 14 (Irrigation + Smart Fan) — relay & PWM
Then Project 7 & 15 (Robots) — motors & navigation
Finally Project 5, 11, 12 (Health, Fall, Cloud) — advanced medical & IoT

🧰 Master Tools & Concepts After All Projects

ADC & DAC I2C & SPI PWM UART Serial WiFi & HTTP Bluetooth / BLE Relay Control Motor Driving OLED Display Cloud IoT (ThingSpeak) Alarm Systems Biomedical Sensing Robotics Navigation Deep Sleep Capacitive Touch