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.
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.
| Component | Pin | ESP32 Pin |
|---|---|---|
| DHT22 VCC | VCC | 3.3V |
| DHT22 DATA | DATA | GPIO 4 |
| DHT22 GND | GND | GND |
| BMP280 VCC | VIN | 3.3V |
| BMP280 GND | GND | GND |
| BMP280 SDA | SDA | GPIO 21 |
| BMP280 SCL | SCL | GPIO 22 |
| OLED VCC | VCC | 3.3V |
| OLED GND | GND | GND |
| OLED SDA | SDA | GPIO 21 |
| OLED SCL | SCL | GPIO 22 |
#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); }
| Library Name | Install From |
|---|---|
| DHT sensor library | Arduino Library Manager |
| Adafruit BMP280 | Arduino Library Manager |
| Adafruit SSD1306 | Arduino Library Manager |
| Adafruit GFX Library | Arduino Library Manager |
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.
| Component | Pin | ESP32 Pin |
|---|---|---|
| LDR | One end | 3.3V |
| LDR | Other end | GPIO 34 (via voltage divider) |
| 10kΩ Resistor | Between GPIO 34 and GND | Voltage divider |
| LED (+) | Anode | GPIO 2 (via 220Ω resistor) |
| LED (−) | Cathode | GND |
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.
#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); }
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.
| Component | Pin | ESP32 Pin |
|---|---|---|
| MQ-2 VCC | VCC | VIN (5V) |
| MQ-2 GND | GND | GND |
| MQ-2 A0 | Analog Out | GPIO 34 |
| Buzzer (+) | Positive | GPIO 18 |
| Buzzer (−) | Negative | GND |
| Red LED (+) | Anode | GPIO 2 (via 220Ω) |
| Red LED (−) | Cathode | GND |
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.
#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); }
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.
| Component | Pin | ESP32 Pin |
|---|---|---|
| PIR VCC | VCC | VIN (5V) |
| PIR GND | GND | GND |
| PIR OUT | Signal | GPIO 27 |
| Buzzer (+) | Positive | GPIO 18 |
| Buzzer (−) | Negative | GND |
| LED (+) | Anode | GPIO 2 (via 220Ω) |
| LED (−) | Cathode | GND |
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.
#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); }
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.
| Component | Pin | ESP32 Pin |
|---|---|---|
| MAX30102 VIN | VIN | 3.3V |
| MAX30102 GND | GND | GND |
| MAX30102 SDA | SDA | GPIO 21 |
| MAX30102 SCL | SCL | GPIO 22 |
| OLED VCC | VCC | 3.3V |
| OLED GND | GND | GND |
| OLED SDA | SDA | GPIO 21 |
| OLED SCL | SCL | GPIO 22 |
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.
#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(); }
| Library Name | Purpose |
|---|---|
| SparkFun MAX3010x | MAX30102 sensor driver |
| Adafruit SSD1306 | OLED display driver |
| Adafruit GFX Library | Graphics primitives |
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.
| Component | Pin | ESP32 Pin |
|---|---|---|
| Soil Sensor VCC | VCC | 3.3V |
| Soil Sensor GND | GND | GND |
| Soil Sensor A0 | Analog Out | GPIO 34 |
| Relay VCC | VCC | VIN (5V) |
| Relay GND | GND | GND |
| Relay IN | Signal | GPIO 26 |
| Pump | Via Relay | External 5V through relay switch |
Dry soil → high resistance → high analog value → pump ON.
Wet soil → low resistance → low analog value → pump OFF.
#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); }
A mobile robot that uses an HC-SR04 ultrasonic sensor to detect obstacles and automatically avoids them by changing direction. Core robotics project.
| Component | Pin | ESP32 Pin |
|---|---|---|
| HC-SR04 VCC | VCC | VIN (5V) |
| HC-SR04 GND | GND | GND |
| HC-SR04 TRIG | Trigger | GPIO 5 |
| HC-SR04 ECHO | Echo | GPIO 18 (voltage divider!) |
| L298N IN1 | Motor A Dir | GPIO 25 |
| L298N IN2 | Motor A Dir | GPIO 26 |
| L298N IN3 | Motor B Dir | GPIO 27 |
| L298N IN4 | Motor B Dir | GPIO 32 |
| L298N ENA | Speed A (PWM) | GPIO 33 |
| L298N ENB | Speed B (PWM) | GPIO 4 |
Distance formula: Distance (cm) = (Time × 0.034) / 2
#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); }
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.
| Component | ESP32 Pin | Purpose |
|---|---|---|
| IR Sensor 1 OUT | GPIO 32 | Slot 1 detection |
| IR Sensor 2 OUT | GPIO 33 | Slot 2 detection |
| IR Sensor 3 OUT | GPIO 34 | Slot 3 detection |
| Green LED 1 | GPIO 25 | Slot 1 vacant |
| Green LED 2 | GPIO 26 | Slot 2 vacant |
| Green LED 3 | GPIO 27 | Slot 3 vacant |
| OLED SDA/SCL | GPIO 21 / 22 | Status display |
#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); }
Toggle an LED or relay ON/OFF using clap sounds detected by a sound sensor module. One clap = ON, another clap = OFF.
| Component | Pin | ESP32 Pin |
|---|---|---|
| Sound Sensor VCC | VCC | 3.3V |
| Sound Sensor GND | GND | GND |
| Sound Sensor DO | Digital Out | GPIO 27 |
| LED (+) | Anode | GPIO 2 (via 220Ω) |
| LED (−) | Cathode | GND |
#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 } }
Use ESP32's built-in capacitive touch pins to create a touch switch panel that controls multiple LEDs — no physical buttons required.
| Touch Pad | ESP32 Pin | Controls |
|---|---|---|
| Touch Pad 1 (wire/copper) | GPIO 4 (Touch0) | LED 1 on GPIO 25 |
| Touch Pad 2 | GPIO 15 (Touch3) | LED 2 on GPIO 26 |
| Touch Pad 3 | GPIO 13 (Touch4) | LED 3 on GPIO 27 |
#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); } }
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.
| Component | Pin | ESP32 Pin |
|---|---|---|
| MPU6050 VCC | VCC | 3.3V |
| MPU6050 GND | GND | GND |
| MPU6050 SDA | SDA | GPIO 21 |
| MPU6050 SCL | SCL | GPIO 22 |
| Buzzer (+) | Positive | GPIO 18 |
| LED (+) | Anode | GPIO 2 (via 220Ω) |
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).
#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); }
Send DHT22 temperature & humidity data to ThingSpeak cloud via ESP32 WiFi. View real-time graphs from anywhere in the world.
| Component | Pin | ESP32 Pin |
|---|---|---|
| DHT22 VCC | VCC | 3.3V |
| DHT22 DATA | DATA | GPIO 4 |
| DHT22 GND | GND | GND |
#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 }
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.
| Component | ESP32 Pin | Purpose |
|---|---|---|
| HC-SR04 TRIG | GPIO 5 | Trigger pulse |
| HC-SR04 ECHO | GPIO 18 | Echo return (use voltage divider) |
| Buzzer | GPIO 19 | Overflow alarm |
| Green LED | GPIO 25 | Low level |
| Yellow LED | GPIO 26 | Medium level |
| Red LED | GPIO 27 | High / Overflow |
Ultrasonic sensor is mounted at the top of the tank, pointing downward. It measures the distance to the water surface:
#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); }
Automatically controls fan speed based on room temperature using DHT11 and PWM. As temperature increases, the fan spins faster.
| Component | Pin | ESP32 Pin |
|---|---|---|
| DHT11 DATA | DATA | GPIO 4 |
| DHT11 VCC | VCC | 3.3V |
| DHT11 GND | GND | GND |
| Motor Driver ENA | PWM Input | GPIO 25 |
| Motor Driver IN1 | Direction | GPIO 26 |
| Motor Driver IN2 | Direction | GPIO 27 |
#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); }
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.
| Component | ESP32 Pin | Purpose |
|---|---|---|
| Left IR Sensor OUT | GPIO 32 | Detect left side of line |
| Right IR Sensor OUT | GPIO 33 | Detect right side of line |
| L298N IN1 | GPIO 25 | Left Motor Forward |
| L298N IN2 | GPIO 26 | Left Motor Reverse |
| L298N IN3 | GPIO 27 | Right Motor Forward |
| L298N IN4 | GPIO 14 | Right Motor Reverse |
| Left IR | Right IR | Action |
|---|---|---|
| White (HIGH) | White (HIGH) | Move Forward |
| Black (LOW) | White (HIGH) | Turn Left |
| White (HIGH) | Black (LOW) | Turn Right |
| Black (LOW) | Black (LOW) | Stop |
#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(); }
| # | Project | Key Sensor | Difficulty | Key Concept |
|---|---|---|---|---|
| 1 | Weather Station | DHT22 + BMP280 | Beginner | I2C, OLED Display |
| 2 | Smart Lighting | LDR | Beginner | ADC, Threshold |
| 3 | Gas Alarm | MQ-2 | Beginner | Analog Sensor, Alarm |
| 4 | Security System | PIR | Beginner | Digital Input, Motion |
| 5 | Health Monitor | MAX30102 | Advanced | I2C, Biomedical |
| 6 | Smart Irrigation | Soil Moisture | Intermediate | Relay, Pump Control |
| 7 | Obstacle Robot | HC-SR04 | Intermediate | Ultrasonic, Motor |
| 8 | Smart Parking | IR Sensor | Intermediate | Multi-sensor, Display |
| 9 | Clap Switch | Sound Sensor | Beginner | Sound, Toggle |
| 10 | Touch Panel | Built-in Touch | Beginner | Capacitive Touch |
| 11 | Fall Detection | MPU6050 | Advanced | IMU, Vector Math |
| 12 | Cloud Weather | DHT22 + WiFi | Advanced | HTTP, ThingSpeak |
| 13 | Water Overflow | HC-SR04 | Beginner | Ultrasonic, Multi-LED |
| 14 | Smart Fan | DHT11 | Intermediate | PWM, Temp Mapping |
| 15 | Line Follower | IR Sensor | Intermediate | IR Array, Robotics |