Solar-Powered ESP32 Security System with RFID & Laser Detection – Kids Robotics Project

Solar-Powered ESP32 Security System with RFID & Laser Detection – Kids Robotics Project
☀️
Kids Robotics Project

Solar-Powered ESP32
Security System

Build your own super-smart security robot with RFID card access and a laser trip-wire alarm — powered by the Sun! ☀️

⚡ ESP32 🪪 RFID 🔴 Laser Detection ☀️ Solar Power 🔔 Arduino IDE ⏱ ~3 Hours 🧒 Age 12+
Overview

🤔 What Are We Building?

Imagine a secret base that only lets you in if you tap the right RFID card — and shoots off an alarm if anyone sneaks through the laser beam without permission! That's exactly what we're making today. It even runs on solar power so it never needs batteries you plug in!

☀️
Solar Panel
charges battery
🧠
ESP32
brain thinks
🪪
RFID reader
checks card
🔴
Laser beam
watches door
🔔
Alarm &
LED alert!
🌍
Fun Fact! RFID stands for Radio Frequency Identification. It's the same tech in your school ID card, library books, and even pet microchips! Radio waves you can't even see carry the secret code. 🤯
Shopping List

🛍️ Parts You Need

Ask a grown-up to help you order these. Most are cheap and easy to find!

🧠
ESP32 Dev Board
× 1 — the brain!
🪪
MFRC522 RFID Module
× 1 + 2 cards
🔴
KY-008 Laser Diode
× 1 (5V, 650nm)
💡
LDR (Light Sensor)
× 1 (laser receiver)
☀️
6V Solar Panel
× 1 (≥1W)
🔋
TP4056 Charger Module
× 1
🔋
18650 Li-ion Battery
× 1 (3.7V)
🔊
Passive Buzzer
× 1 (alarm!)
🟢
Green LED
× 1 (access OK)
🔴
Red LED
× 1 (access denied)
220Ω Resistors
× 4
🧪
10kΩ Resistor
× 1 (LDR divider)
🍞
Breadboard
× 1
🌈
Jumper Wires
× ~30
🔌
MT3608 Boost Module
× 1 (3.7V → 5V)
💰
Budget Tip! All these parts together cost around ₹800 – ₹1,200 (about $10–15 USD). You can find them on Amazon, Robu.in, or your local electronics shop!
Wiring

🔌 Circuit Connections

Follow these tables carefully. Always connect GROUND (GND) wires first!

☀️ Solar Power Circuit

FROMTOWIRE
Solar Panel +TP4056 IN+🔴 Red
Solar Panel –TP4056 IN–⚫ Black
TP4056 B+Battery +🔴 Red
TP4056 B–Battery –⚫ Black
TP4056 OUT+MT3608 IN+🔴 Red
MT3608 OUT+ESP32 VIN🔴 Red (5V)
MT3608 OUT–ESP32 GND⚫ Black

⚙️ Set MT3608 boost module output to exactly 5V using the tiny screwdriver before connecting to ESP32!

🪪 MFRC522 RFID Module → ESP32

RFID PinESP32 PinWIRE
SDA (SS)GPIO 5🟣 Purple
SCKGPIO 18🟡 Yellow
MOSIGPIO 23🔵 Blue
MISOGPIO 19🟠 Orange
IRQNot used
GNDGND⚫ Black
RSTGPIO 4⚪ White
3.3V3.3V🔴 Red (3.3V only!)

⚠️ The RFID module uses 3.3V — NOT 5V! You'll fry it if you use 5V.

🔴 Laser + LDR (Trip-Wire Circuit)

ComponentESP32 PinNotes
Laser + GPIO 26via 220Ω resistor
Laser –GND
LDR pin 13.3Vone side
LDR pin 2GPIO 34 (ADC)analog read
LDR–GND junctionGNDvia 10kΩ resistor

💡 LEDs & Buzzer → ESP32

ComponentESP32 PinResistor
🟢 Green LED (+)GPIO 25220Ω
🔴 Red LED (+)GPIO 27220Ω
🔊 Buzzer (+)GPIO 14none needed
All (–) / cathodeGND
   ☀️ SOLAR PANEL (6V)
   [+]────────────►[TP4056 IN+]
   [–]────────────►[TP4056 IN–]
         │
   [TP4056 B+]──►🔋 Battery (+)
   [TP4056 B–]──►🔋 Battery (–)
         │
   [TP4056 OUT+]──►[MT3608 IN+]
                   [MT3608]──► 5V OUT
                                │
   ┌───────────────────────────┘
   │         ┌─── 3.3V
   │         │
   ▼         ▼
   ╔══════════════════╗
   ║    ESP32 DevKit  ║
   ║  VIN  ◄── 5V    ║──► GPIO26 ──┐
   ║  GND  ◄── GND   ║             │ 220Ω
   ║  3.3V ──────────╫─────────┐   ▼
   ║  GPIO34 (ADC) ◄──╫── LDR ──┤  [LASER]───►🔴 beam ──►[LDR]
   ║                  ║         │            
   ║  GPIO5  ──SDA───►║RFID     │
   ║  GPIO18 ──SCK───►║MFRC     └── 10kΩ ──► GND
   ║  GPIO23 ──MOSI──►║522
   ║  GPIO19 ◄─MISO──║
   ║  GPIO4  ──RST───►║
   ║  GPIO25 ──220Ω──►🟢 Green LED ──► GND
   ║  GPIO27 ──220Ω──►🔴 Red LED   ──► GND
   ║  GPIO14 ─────────►🔊 Buzzer   ──► GND
   ╚══════════════════╝
      
Instructions

🛠️ Step-by-Step Build Guide

01

Install Arduino IDE & ESP32 Board

Download Arduino IDE from arduino.cc. Then go to File → Preferences and paste this URL into "Additional Boards Manager URLs":

Board URL
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Then go to Tools → Board → Boards Manager, search "esp32" and install it. Select "ESP32 Dev Module" as your board.

02

Install Required Libraries

Go to Sketch → Include Library → Manage Libraries and install:

📚 MFRC522 by GithubCommunity

📚 ESP32 built-in (comes with the board package)

03

Set Up the Solar Charging Circuit

Connect the solar panel to the TP4056 charger IN+ and IN– pins. Connect the battery to B+ and B–. Adjust the MT3608 boost converter output to exactly 5.0V using a multimeter before connecting to the ESP32. This keeps your ESP32 safe! ⚡

☀️
How Solar Charging Works! The solar panel turns sunlight into electricity. The TP4056 chip acts like a traffic cop — it lets the right amount of electricity flow into the battery so it doesn't get too full (overcharged) and break!
04

Wire the RFID Module

The RFID module connects via SPI (a special language chips use to talk to each other). Follow the table above carefully. Remember: only use 3.3V for the RFID module, never 5V! Use purple/yellow/blue/orange wires to remember which is which.

05

Build the Laser Trip-Wire

Place the laser diode on one side of your "door" or box opening. Place the LDR (light sensor) exactly opposite, so the laser beam hits it. Add a 10kΩ resistor between the LDR output and GND to create a "voltage divider" — this lets the ESP32 read how much light is hitting the sensor.

When someone steps through and blocks the laser, the LDR reading drops — that triggers the alarm! 🚨

06

Connect LEDs & Buzzer

Always put a 220Ω resistor in series with each LED (between the ESP32 pin and the LED's long leg). Without it, too much current flows and burns the LED! The short leg of each LED goes to GND.

07

Find Your RFID Card's Secret UID

Before uploading the main code, upload a simple UID scanner sketch to find your card's unique ID. Open Serial Monitor (115200 baud) and tap your RFID card — you'll see something like UID: A3 2F 91 B7. Write it down! 📝

UID Scanner (upload first!)
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN  5
#define RST_PIN 4

MFRC522 rfid(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  Serial.println("Tap your RFID card!");
}

void loop() {
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
  Serial.print("UID: ");
  for (byte i = 0; i < rfid.uid.size; i++) {
    Serial.print(rfid.uid.uidByte[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
  rfid.PICC_HaltA();
}
08

Upload the Main Security Code

Copy the full code below. Replace 0xA3, 0x2F, 0x91, 0xB7 with your actual card's UID bytes. Then click Upload! ⬆️

Arduino Code

💻 Full Project Code

solar_security_system.ino
// ══════════════════════════════════════════════════════════════
// 🤖 Solar-Powered ESP32 Security System
//    RFID Access Control + Laser Trip-Wire Alarm
//    For Kids Robotics Projects!
// ══════════════════════════════════════════════════════════════

#include <SPI.h>
#include <MFRC522.h>

// ─── PIN DEFINITIONS ───────────────────────────────────────────
#define SS_PIN       5    // RFID SDA/SS
#define RST_PIN      4    // RFID RST
#define LASER_PIN    26   // Laser diode control
#define LDR_PIN      34   // Light sensor (ADC)
#define GREEN_LED    25   // Access granted
#define RED_LED      27   // Access denied / alarm
#define BUZZER_PIN   14   // Buzzer

// ─── SETTINGS ──────────────────────────────────────────────────
#define LASER_THRESHOLD  500  // ADC below this = beam broken!
#define ALARM_DURATION  3000  // Alarm plays for 3 seconds
#define ACCESS_DURATION 2000  // Green light for 2 seconds

// ─── RFID OBJECT ───────────────────────────────────────────────
MFRC522 rfid(SS_PIN, RST_PIN);

// ─── AUTHORISED CARD UID ───────────────────────────────────────
// 👇 CHANGE THESE TO YOUR OWN CARD'S UID BYTES!
byte authorisedUID[] = {0xA3, 0x2F, 0x91, 0xB7};
const int UID_SIZE = 4;

// ─── STATE ─────────────────────────────────────────────────────
bool systemArmed     = true;
bool alarmActive     = false;
unsigned long alarmStart   = 0;
unsigned long accessStart  = 0;
bool showingAccess   = false;

// ═══ SETUP ═══════════════════════════════════════════════════
void setup() {
  Serial.begin(115200);
  Serial.println("🤖 Security System Starting...");

  // Initialise SPI & RFID
  SPI.begin();
  rfid.PCD_Init();
  Serial.println("✅ RFID Ready");

  // Set pin modes
  pinMode(LASER_PIN,  OUTPUT);
  pinMode(GREEN_LED,  OUTPUT);
  pinMode(RED_LED,    OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LDR_PIN,    INPUT);

  // Turn laser ON at startup
  digitalWrite(LASER_PIN, HIGH);
  Serial.println("🔴 Laser armed!");

  // Quick startup beep
  startupBeep();
  Serial.println("🔐 System Armed. Tap card or break laser to test!");
}

// ═══ MAIN LOOP ════════════════════════════════════════════════
void loop() {

  // ── 1) Check if alarm timer has ended ──────────────────────
  if (alarmActive && (millis() - alarmStart > ALARM_DURATION)) {
    stopAlarm();
  }

  // ── 2) Check if access-granted display should end ──────────
  if (showingAccess && (millis() - accessStart > ACCESS_DURATION)) {
    digitalWrite(GREEN_LED, LOW);
    showingAccess = false;
    systemArmed = true;  // re-arm after access
    Serial.println("🔐 Re-armed!");
  }

  // ── 3) Laser trip-wire check ───────────────────────────────
  if (systemArmed && !alarmActive && !showingAccess) {
    int ldrValue = analogRead(LDR_PIN);

    if (ldrValue < LASER_THRESHOLD) {
      Serial.print("🚨 INTRUDER! LDR value: ");
      Serial.println(ldrValue);
      triggerAlarm("LASER BROKEN");
    }
  }

  // ── 4) RFID card check ─────────────────────────────────────
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
    return;  // no card detected, skip
  }

  checkCard();
  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}

// ═══ FUNCTIONS ════════════════════════════════════════════════

// Check if tapped card matches the authorised UID
void checkCard() {
  Serial.print("Card tapped! UID: ");
  for (byte i = 0; i < rfid.uid.size; i++) {
    Serial.print(rfid.uid.uidByte[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  // Compare UID bytes
  bool match = (rfid.uid.size == UID_SIZE);
  if (match) {
    for (int i = 0; i < UID_SIZE; i++) {
      if (rfid.uid.uidByte[i] != authorisedUID[i]) {
        match = false; break;
      }
    }
  }

  if (match) {
    grantAccess();
  } else {
    denyAccess();
  }
}

// ✅ Access GRANTED
void grantAccess() {
  Serial.println("✅ ACCESS GRANTED! Welcome!");
  systemArmed = false;   // disarm laser briefly
  alarmActive = false;
  showingAccess = true;
  accessStart = millis();

  digitalWrite(RED_LED,   LOW);
  digitalWrite(GREEN_LED, HIGH);

  // Happy beeps! ♪
  tone(BUZZER_PIN, 880, 100); delay(150);
  tone(BUZZER_PIN, 1047, 100); delay(150);
  tone(BUZZER_PIN, 1319, 200); delay(200);
  noTone(BUZZER_PIN);
}

// ❌ Access DENIED
void denyAccess() {
  Serial.println("❌ ACCESS DENIED!");
  digitalWrite(RED_LED, HIGH);

  // Low sad beep
  tone(BUZZER_PIN, 200, 500); delay(600);
  noTone(BUZZER_PIN);

  delay(500);
  digitalWrite(RED_LED, LOW);
}

// 🚨 Trigger alarm (laser broken or bad card)
void triggerAlarm(const char* reason) {
  Serial.print("🚨 ALARM: ");
  Serial.println(reason);
  alarmActive = true;
  alarmStart  = millis();
  digitalWrite(RED_LED, HIGH);
  tone(BUZZER_PIN, 1500);  // continuous alarm tone
}

// 🔇 Stop alarm
void stopAlarm() {
  alarmActive = false;
  noTone(BUZZER_PIN);
  digitalWrite(RED_LED, LOW);
  Serial.println("Alarm cleared.");
}

// 🎵 Startup beep sequence
void startupBeep() {
  int notes[] = {523, 659, 784, 1047};
  for (int i = 0; i < 4; i++) {
    tone(BUZZER_PIN, notes[i], 120);
    delay(160);
  }
  noTone(BUZZER_PIN);
}
Science Corner

🔬 How Does It All Work?

📡 RFID — Invisible Radio Magic

Your RFID card has a tiny antenna coil inside (no battery!). When you bring it near the reader, the reader sends out a radio wave. This wave gives the card just enough energy to wake up and shout its secret UID number back. The ESP32 hears it and checks if it matches the allowed UID in the code.

🔴 The Laser Trip-Wire

The laser diode shoots a thin beam of light to the LDR sensor across the doorway. The LDR (Light Dependent Resistor) has low resistance when bright light hits it — giving a HIGH analog reading. When someone breaks the beam, the reading drops below our threshold (500), and — ALARM! 🚨

☀️ Solar Power Flow

Light hits the solar cells → electrons get excited → electricity flows! The TP4056 chip safely charges the 18650 lithium battery (same type as in some laptops). The MT3608 boosts the battery's 3.7V up to a steady 5V that the ESP32 needs. Free energy from the Sun! 🌞

Troubleshooting

🔧 Something Not Working?

❓ RFID card isn't being read
Check that you wired 3.3V (NOT 5V!) to the RFID module. Double-check SCK→GPIO18, MOSI→GPIO23, MISO→GPIO19, SDA→GPIO5. Re-seat all wires.
❓ Laser alarm fires even with nothing in the way
Your LDR might be in a dim area. Adjust LASER_THRESHOLD lower (try 300) in the code. Make sure the laser is pointing directly at the LDR centre.
❓ Access is always denied even with the right card
Re-run the UID scanner sketch and write down the exact UID bytes again. Make sure they match exactly in the authorisedUID[] array, including leading zeros.
❓ No sound from buzzer
Make sure it's a passive buzzer (not active). Passive buzzers need the tone() function to generate sound. Also check the + leg is connected to GPIO 14.
❓ ESP32 won't upload code
Hold the BOOT button on the ESP32 while clicking Upload, then release it once uploading starts. Check you selected "ESP32 Dev Module" as the board.
❓ Solar panel isn't charging the battery
Check the TP4056 LED lights. Red = charging, Blue = full. Make sure you're outdoors or near a bright window. The panel needs direct sunlight to produce enough voltage.
Stay Safe!

🦺 Safety Rules for Young Makers

👀
Never look into the laser! Even small lasers can harm your eyes. Always point it away from faces.
🔋
Li-ion battery care Never puncture, short-circuit, or overheat a lithium battery. Always use the TP4056 charger — never charge directly!
🧑‍🍳
Ask a grown-up Get help with soldering, adjusting the boost converter, or anything electrical you're not sure about.
🔌
3.3V vs 5V! The RFID module ONLY runs on 3.3V. Wrong voltage = burnt module. Double-check before powering on!
Level Up!

🚀 Cool Upgrades to Try

📱
WiFi Alerts
Send alarm to phone via Telegram bot!
📹
Camera Module
Add ESP32-CAM to snap intruder photos
🗣️
Voice Alert
Add a DFPlayer Mini MP3 module
🔢
Keypad Code
Add a 4x4 matrix keypad for PIN entry
🖥️
OLED Display
Show "WELCOME" or "ACCESS DENIED" on screen
🚪
Servo Door Lock
Turn a servo motor to actually lock a door!
Achievement Unlocked!

🏆 What You Learned Today

📡
SPI Communication

How chips talk to each other using clock signals

Voltage Dividers

How resistors split voltage for sensor readings

☀️
Solar Charging

How to safely charge batteries with solar power

🎛️
State Machines

How code tracks "armed", "alarm", "access" states

🌟
Share Your Build! Made this project? Take a photo and share it online with the hashtag #KidsRobotics and #ESP32Security! We'd love to see your creation!

Built with ❤️ for young makers everywhere 🤖

Keywords: ESP32 security system for kids · RFID robotics project · laser trip wire alarm · solar powered Arduino · beginner electronics project · DIY home security

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
Young inventors love it!
🖨️
3D Print
All parts
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course