The Smart Energy Control System is a production-ready, full-stack IoT dashboard designed to monitor and control physical home appliances or power sectors remotely. By integrating a responsive React 19 / TypeScript web client, a Node.js Express backend API gateway, and dedicated Arduino C++ microcontroller firmware, the system bridges the gap between software dashboards and hardware switches.
This architecture serves as a foundational prototype for modern smart homes, enabling administrators to authenticate securely, view real-time appliance states, trigger physical circuits, and receive sensory feedback instantly.
The following colored layout traces how an interaction on the web client traverses the backend service, travels over the serial port, and operates the physical relays:
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#E8F5E9', 'edgeLabelBackground':'#FFFFFF', 'tertiaryColor': '#FFF8E1', 'lineColor': '#2E7D32', 'nodeBorder': '#2E7D32' }}}%%
flowchart TD
classDef web fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px,color:#1B5E20;
classDef server fill:#E3F2FD,stroke:#1565C0,stroke-width:2px,color:#0D47A1;
classDef comms fill:#FFF3E0,stroke:#E65100,stroke-width:2px,color:#E65100;
classDef hardware fill:#EDE7F6,stroke:#6A1B9A,stroke-width:2px,color:#4A148C;
classDef feedback fill:#FCE4EC,stroke:#C2185B,stroke-width:2px,color:#880E4F;
A[π React Web Client / UI] -->|1. HTTP POST Request /control| B(π» Node.js Express Server)
B -->|2. Maps State to Command Char| C[π SerialPort Interface]
C -->|3. Writes Char over USB COM Port| D[ποΈ Arduino Uno / Nano]
D -->|4. Triggers Auditory Beep| E[π Active Buzzer]
D -->|5. Toggles HIGH/LOW State| F[π‘ Physical LEDs]
class A web;
class B server;
class C comms;
class D hardware;
class E,F feedback;
To replicate this physical circuit, connect the following components to your Arduino microcontroller. Ensure you include standard 220Ξ© current-limiting resistors in series with each LED to prevent burnout.
| Actuator / Component | Arduino Pin | Circuit Description | State Character |
|---|---|---|---|
| π‘ LED 1 | Pin 13 | Status Indicator / Zone 1 Power Relay | A (ON) / a (OFF) |
| π‘ LED 2 | Pin 12 | Status Indicator / Zone 2 Power Relay | B (ON) / b (OFF) |
| π‘ LED 3 | Pin 11 | Status Indicator / Zone 3 Power Relay | C (ON) / c (OFF) |
| π Buzzer | Pin 8 | Active Buzzer for instant audio receipt feedback | Short Beep on command |
Ensure you have the following installed:
- Node.js (v18.0.0 or higher)
- Arduino IDE
- Git
- Attach your Arduino board to your workstation via USB.
- Open
Arduino-Code/Arduino-Code.inousing the Arduino IDE. - Go to
Tools > Boardand select your board (e.g., Arduino Uno). - Select the matching COM Port from the ports list.
- Click Upload to burn the sketch onto the board.
- Navigate to the backend directory:
cd backend - Install standard Node modules:
npm install
- Configure Connection Port:
- Open
server.jsin a text editor. - Locate the configuration section and set your Arduino's active COM port:
const ARDUINO_PORT_PATH = 'COM5'; // Update this to match your Arduino port!
- Open
- Fire up the backend engine:
The Express API will initialize and bind to
npm start
http://localhost:3000.
- Navigate to the frontend directory:
cd ../frontend - Install client dependencies:
npm install
- Configure API Endpoints:
- Open
src/App.tsx. - Ensure the active API base URL points to your local backend gateway (
http://localhost:3000) instead of ngrok tunnels.
- Open
- Launch the web dashboard:
The React UI will run locally on
npm run dev
http://localhost:5173(or alternative port shown in terminal).
For local demonstration and sandbox testing, the backend implements basic mock authorization:
- Demo Username:
admin - Demo Password:
password123
Warning
This authentication mechanism is for sandbox and testing environments only. In a production environment, implement salted hashing (such as bcrypt), sign secure JSON Web Tokens (JWT), and persist users within a validated DB system.
βββ .gitignore # Standardized ignore rules for node_modules, builds, logs & credentials
βββ package.json # Root Monorepo configuration
βββ package-lock.json
βββ Arduino-Code/ # C++ Firmware directory
β βββ Arduino-Code.ino # Microcontroller serial event loop handler
βββ backend/ # Express.js REST API & Serial Gateway
β βββ server.js # API routing & SerialPort event hub
β βββ package.json
β βββ ngrok-backend-example.yml # Template configuration for secure ngrok tunnels
βββ frontend/ # React 19 Client Dashboard
βββ index.html
βββ vite.config.ts
βββ package.json
βββ src/ # App views & React components