This project is a smart plug powered by an ESP32 microcontroller, which controls a relay to switch connected devices on or off. The relay can be controlled through a simple and intuitive web interface, using API calls over the network. The device also displays relevant information on an I2C LCD screen and includes a physical button for direct control of the relay, ensuring usability even without network access.
-
Wi-Fi Modes:
- Connects to an existing Wi-Fi network using stored credentials.
- Creates an Access Point (AP) if no network credentials are available.
-
Dynamic LCD Display:
- Displays the AP SSID and password when in AP mode without clients.
- Shows the URL for relay control when a client connects to the AP or when connected to Wi-Fi.
-
Physical Button Control:
- Allows direct control of the relay.
- Button press takes priority over API or web-based control.
-
Web Interface:
- Responsive relay control using modern AJAX (XHR).
- Displays the current relay state without page refreshes.
-
Non-Volatile Storage:
- Saves Wi-Fi credentials using the ESP32's Preferences library.
-
Custom 3D-Printed Case:
- A 3D-printable STL file for the case is included in the
assets
folder.
- A 3D-printable STL file for the case is included in the
- Arduino IDE or Arduino CLI
- ESP32 Board Support Package
- Required Libraries:
WiFi.h
WebServer.h
Preferences.h
esp_wifi.h
LiquidCrystal_I2C.h
- ESP32 Microcontroller
- I2C LCD Display: 16x2 with an I2C interface.
- Relay Module
- Self-Lock Push Button
- Voltage Converter: Converts 110V-240V AC to 5V DC for the ESP32.
- NEMA 5-15R Socket: A standard US receptacle for the relay-controlled device.
- IEC 320 C14 Socket (AS-05, AC 250 V, 10 A): Common power inlet for devices.
Note: See the Hardware section below for links to the components used.
- Clone this repository or copy the source code to your local machine.
- Open the project in Arduino IDE or place it in a suitable directory for the Arduino CLI.
- Install the required libraries:
- Use the Arduino Library Manager or Arduino CLI.
- Ensure the ESP32 board package is installed.
- Connect your ESP32 and upload the code.
-
Initial Configuration:
- When powered on for the first time, the ESP32 will start in AP mode. The LCD will display the SSID and password for the AP.
- Connect to the AP, and a captive portal will automatically open, guiding you to the network configuration page.
- Navigate through the captive portal to configure Wi-Fi credentials.
-
Relay Control:
- Access the web interface at the URL displayed on the LCD to toggle the relay state.
- Press the physical button to control the relay directly. The button press overrides web control.
-
LCD Display:
- Shows the current mode and necessary connection details:
- AP mode without clients: SSID and password.
- AP mode with clients: URL for relay control.
- Wi-Fi connected: URL for relay control.
- Shows the current mode and necessary connection details:
Component | Description | Link |
---|---|---|
ESP32 Microcontroller | The heart of the project. | Link |
I2C LCD Display (16x2) | Displays connection details and status. | Link |
Relay Module | Controls the electrical load. | Link |
Self-Lock Push Button | Physical control of the relay. | Link |
Voltage Converter (110V-240V to 5V) | Powers the ESP32 from AC mains. | Link |
NEMA 5-15R Socket | Standard US receptacle for connected devices. | Link |
IEC 320 C14 Socket (AS-05) | Power inlet for AC connections. | Link |
M3 Inserts | M3 insert for lid locking. | Link |
M3 screws | M3 screws. | Link |
- A 3D-printable case designed for this project is available in the
assets
folder. - The STL file can be printed with standard PLA or ABS material without support.
- Relay State: Displays whether the relay is
ON
orOFF
. - Toggle Button: Instantly toggles the relay state.
- Uses modern AJAX (XHR) for a seamless user experience.
-
Button Behavior:
- Relay state may not update on the web interface while the button is pressed. This behavior is by design to prioritize physical control.
-
Suggestions:
- Add password protection to the web interface for enhanced security.
- Include OTA (Over-the-Air) updates for easier firmware management.
This project is licensed under the MIT License. See the LICENSE file for details.