A complete IoT solution for controlling smart home devices (lights, fans, and sockets) using an ESP32 microcontroller and a modern React dashboard with Firebase Realtime Database.
Switch-Board/
โโโ dashboard/ # React web dashboard (TypeScript + Tailwind CSS)
โโโ esp32/ # ESP32 firmware (Arduino C++)
โโโ README.md # This file
- ๐จ Modern, responsive React UI with Tailwind CSS
- ๐ Real-time device state synchronization via Firebase
- ๐ฑ Mobile-friendly design
- ๐ Dark mode support
- โก Instant control feedback
- ๐ฏ Simple click-to-toggle interface
- ๐ก WiFi connectivity
- ๐ฅ Firebase Realtime Database integration
- ๐ฎ Control 3 devices: LED (Light), Fan, Socket
- ๐ Real-time state updates via Firebase streams
- ๐ GPIO pin control
- Node.js (v16 or higher)
- npm or yarn
- Arduino IDE or PlatformIO for ESP32
- Firebase Project (see setup below)
-
Navigate to dashboard folder
cd dashboard -
Install dependencies
npm install
-
Configure Firebase
- Open
src/firebase.ts - Replace the placeholder values with your Firebase project credentials:
const firebaseConfig = { apiKey: "YOUR_API_KEY", databaseURL: "YOUR_DATABASE_URL", projectId: "YOUR_PROJECT_ID", storageBucket: "YOUR_STORAGE_BUCKET", messagingSenderId: "YOUR_MESSAGING_SENDER_ID", appId: "YOUR_APP_ID" };
- Open
-
Start development server
npm run dev
The dashboard will be available at
http://localhost:5173 -
Build for production
npm run build
-
Navigate to esp32 folder
cd esp32 -
Configure WiFi and Firebase credentials
- Open
src/main.cpp - Update the following constants:
#define WIFI_SSID "YOUR_WIFI_SSID" #define WIFI_PASSWORD "YOUR_WIFI_PASSWORD" #define FB_API_KEY "YOUR_FIREBASE_API_KEY" #define FB_DB_URL "YOUR_DATABASE_URL" #define USER_EMAIL "YOUR_ESP32_EMAIL" #define USER_PASSWORD "YOUR_ESP32_PASSWORD"
- Open
-
Configure GPIO Pins (if using different pins)
#define LED_PIN 4 // Light control pin #define FAN_PIN 5 // Fan control pin #define SOCKET_PIN 18 // Socket control pin
-
Upload to ESP32
- Using PlatformIO:
pio run -t upload
- Or use Arduino IDE with appropriate board settings
- Using PlatformIO:
The Firebase database should have the following structure:
{
"led": {
"state": "0" or "1"
},
"fan": {
"state": "0" or "1"
},
"socket": {
"state": "0" or "1"
}
}
Set up the following security rules for your database:
{
"rules": {
"led": {
".write": true,
".read": true
},
"fan": {
".write": true,
".read": true
},
"socket": {
".write": true,
".read": true
}
}
}- React 19.1.1 - UI framework
- TypeScript 5.9.3 - Type safety
- Tailwind CSS 3.3.5 - Styling
- Firebase 12.5.0 - Realtime database
- react-icons 5.5.0 - Icon library
- Vite 7.1.7 - Build tool
- Firebase Arduino Client Library - Firebase integration
- Adafruit GFX Library - Graphics library
- Adafruit SSD1306 - OLED display support
- Open the dashboard in your browser
- Click on any device card (Light, Fan, Socket) to toggle it on/off
- The state will update in real-time across all connected clients
- The ESP32 will receive the update via Firebase stream and control the GPIO pins
- The dashboard subscribes to Firebase Realtime Database
- When any device state changes, all connected clients update instantly
- The ESP32 monitors the database and updates physical pins accordingly
- Never commit sensitive credentials to the repository
- Use
.envfiles for environment variables - Store Firebase credentials securely
- Change default WiFi and authentication credentials
- Use strong passwords for Firebase authentication
- Implement proper security rules in Firebase
Build errors
- Delete
node_modulesand reinstall:npm install - Clear Vite cache:
rm -rf dist
Firebase connection issues
- Verify Firebase credentials in
src/firebase.ts - Check Firebase Realtime Database URL
- Ensure database security rules allow read/write
WiFi connection fails
- Verify SSID and password are correct
- Check ESP32 has stable power supply
- Restart ESP32 and check serial monitor
Firebase connection fails
- Verify API key and database URL
- Check internet connection
- Review Firebase authentication credentials
- Ensure Firebase project has Realtime Database enabled
GPIO pins not responding
- Verify pin numbers in configuration
- Check electrical connections
- Test GPIO pins with simple sketch first
Feel free to fork, improve, and submit pull requests!
This project is open source and available under the MIT License.
For issues and questions, please open an issue on GitHub.
Happy Home Automation! ๐