Sunday, 16 November 2025

๐ŸŽฏ Build Your Own Timer Plug (Mobile Charger Auto Cut-Off) Using ESP32 (Hotspot Mode)

 ๐ŸŽฏ Build Your Own Timer Plug (Mobile Charger Auto Cut-Off) Using ESP32 (Hotspot Mode)

๐Ÿ“… By Dinesh D | Tech DIY Projects | Nov 2025


๐Ÿš€ Introduction
Want a simple plug that automatically cuts power to your mobile charger after a set time — and that works without any router or internet? In this project I built a Wi-Fi hotspot timer plug using an ESP32 and a 5V relay module. The ESP32 creates its own Wi-Fi network. Open the web page it serves, set the HH:MM:SS timer, and the relay will turn the charger ON and then auto cut-off when time finishes.

This post gives the full program, pin configuration, wiring, step-by-step usage, and what photos/video clips to include in your Blogspot post.


                     


๐Ÿง  Project Concept

  1. ESP32 runs in Access Point (hotspot) mode.

  2. A simple web UI served by the ESP32 lets the user set a timer.

  3. When the timer starts, ESP32 energizes the relay → charger receives power.

  4. When timer expires or user presses Stop, ESP32 de-energizes the relay → power cut-off.

This is perfect for charging control, lamp timers, and other small AC loads (observe safety limits of your relay).


๐Ÿงฐ Components Used

Component Quantity
ESP32 Dev Board (any DevKit)
1
5V Relay Module (with opto isolation recommended)
1
AC Plug & Socket (mains rated)
1 set
USB Cable (to power ESP32)
1
Jumper Wires
several
Small project box / enclosure
optional

Tools: screwdriver, wire stripper, multimeter, hot glue / tape, soldering iron (optional)


๐Ÿ”Œ Pin Configuration & Connections

ESP32 → Relay (DC control side)

  • relay VCC5V (ESP32 5V or external 5V)

  • relay GNDGND (ESP32 GND)

  • relay INGPIO 5 (ESP32 control pin)

Relay → AC (mains side)Important: mains wiring must be done safely

  • Live (hot) wire from mains → COM on relay

  • NO (Normally Open) → Live to charger input

  • Neutral wire → Direct to charger neutral (do not switch neutral)

  • Earth (if present) → Earth to charger earth

Notes:

  • Use relay rated for your mains voltage & current (e.g., 250VAC @ 10A or higher).

  • If your relay module uses 5V coil, power it from ESP32 5V pin or separate 5V supply (common GND).

  • For safety, place AC wiring inside an insulated enclosure and keep low-voltage wiring separate.


๐Ÿ“Ÿ ESP32 Code (Hotspot Mode + Timer + Auto Cut-Off)
Copy this into Arduino IDE, select your ESP32 board and upload.

#include <WiFi.h>
#include <WebServer.h>

// Hotspot credentials (change if you want)
const char* ssid = "Charger_AP";
const char* password = "12345678";

WebServer server(80);

const int relayPin = 5;  // GPIO5 -> Relay IN
unsigned long timerDuration = 0;  // milliseconds
unsigned long startTime = 0;
bool isCharging = false;

// Simple HTML UI
String webPage = R"rawliteral(
<!DOCTYPE html><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Timer Plug - Auto Cut Off</title>
  <style>
    body { font-family: Arial, sans-serif; text-align:center; padding:24px; }
    h2 { color:#1a4d8f; }
    .time { font-size:18px; margin:6px; width:80px; padding:8px; border-radius:6px; border:1px solid #ccc; }
    button { padding:12px 20px; margin:10px; border:none; color:#fff; border-radius:6px; background:#1a4d8f; cursor:pointer; }
    .stop { background:#d9534f; }
  </style>
</head>
<body>
  <h2>⏱️ Mobile Charger Auto Cut-Off</h2>
  <form action="/start">
    <input class="time" type="number" name="hours" placeholder="HH" min="0" max="24">
    <input class="time" type="number" name="minutes" placeholder="MM" min="0" max="59">
    <input class="time" type="number" name="seconds" placeholder="SS" min="0" max="59"><br>
    <button type="submit">Start Charging</button>
  </form>
  <form action="/stop">
    <button class="stop" type="submit">Stop Charging</button>
  </form>
  <p>Connect your phone to WiFi: <b>Charger_AP</b> (pwd: 12345678)<br>Open: <b>192.168.4.1</b></p>
</body>
</html>
)rawliteral";

void setup() {
  Serial.begin(115200);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH); // Ensure relay is OFF initially (HIGH = OFF for many modules)

  // Start hotspot
  WiFi.softAP(ssid, password);
  Serial.println("Access Point started");
  Serial.print("IP: "); Serial.println(WiFi.softAPIP());

  // Routes
  server.on("/", []() {
    server.send(200, "text/html", webPage);
  });

  server.on("/start", []() {
    int h = server.hasArg("hours") ? server.arg("hours").toInt() : 0;
    int m = server.hasArg("minutes") ? server.arg("minutes").toInt() : 0;
    int s = server.hasArg("seconds") ? server.arg("seconds").toInt() : 0;

    timerDuration = ((unsigned long)h * 3600UL + (unsigned long)m * 60UL + (unsigned long)s) * 1000UL;
    startTime = millis();
    digitalWrite(relayPin, LOW); // Turn relay ON (LOW for many modules)
    isCharging = true;

    Serial.printf("Started: %dh %dm %ds -> %lu ms\n", h, m, s, timerDuration);
    server.send(200, "text/html", "<h2>Charging Started</h2><a href='/'>Back</a>");
  });

  server.on("/stop", []() {
    digitalWrite(relayPin, HIGH); // Turn relay OFF
    isCharging = false;
    Serial.println("Stopped manually");
    server.send(200, "text/html", "<h2>Charging Stopped</h2><a href='/'>Back</a>");
  });

  server.begin();
}

void loop() {
  server.handleClient();

  if (isCharging) {
    unsigned long elapsed = millis() - startTime;
    if (elapsed >= timerDuration) {
      digitalWrite(relayPin, HIGH); // Auto cut-off
      isCharging = false;
      Serial.println("Timer complete - Relay OFF");
    }
  }
}

๐Ÿ›ก️ Safety Warnings

  • Work carefully with mains voltage. If you are not confident with AC wiring, get help from a qualified electrician.

  • Use a relay rated for the load (voltage & current).

  • Insulate all exposed mains connections; use a proper enclosure.

  • Keep low-voltage electronics (ESP32) isolated from mains wiring.


๐Ÿงช How to Test (Step-by-step)

  1. Upload code to ESP32 using Arduino IDE.

  2. Power ESP32 with USB (from phone charger or power bank).

  3. On your phone: connect to WiFi Charger_AP (password: 12345678).

  4. Open browser → go to http://192.168.4.1.

  5. Enter a short timer (eg. 00:00:10) and press Start Charging.

  6. Verify: relay clicks and charger supplies phone. After 10s the relay should click OFF.


๐ŸŽ‰ Final Result
✅ Simple hotspot-based timer plug that works without internet
✅ Web UI to set time & manual stop button
✅ Auto cut-off protects charger/battery
✅ Easy to adapt for lamps, fans, and other small appliances


❤️ Want More?
If you want, I can also:

  • provide a Blogspot HTML-ready post (with image placeholders),

  • add a live countdown on the web UI,

  • supply a simple circuit diagram image for download.

Contact / Questions: reply here and I’ll help you finish the blog post or improve features.

๐ŸŽฏ Build Your Own Timer Plug (Mobile Charger Auto Cut-Off) Using ESP32 (Hotspot Mode)

  ๐ŸŽฏ Build Your Own Timer Plug (Mobile Charger Auto Cut-Off) Using ESP32 (Hotspot Mode) ๐Ÿ“… By Dinesh D | Tech DIY Projects | Nov 2025 ๐Ÿš€ ...