A comprehensive IoT control system built with ESP32 microcontroller, featuring web-based device control, task scheduling, and real-time monitoring capabilities.
- 4-Channel Relay Control: Independent control of pumps and DC motor
- Servo Motor Control: PCA9685-based servo positioning (0-180Β°)
- WiFi Connectivity: Automatic connection with NTP time synchronization
- Real-time Monitoring: System status and device state tracking
- Asynchronous Web Server: REST API for device control
- Task Scheduling: Automated device operations with timing
- Bilingual Support: English and Persian language support
- Memory Management: Automatic garbage collection and optimization
- Error Handling: Graceful error recovery and logging
- Streamlit Dashboard: User-friendly control interface
- Real-time Updates: Live device status monitoring
- Scheduled Operations: Task creation and management
- Mobile Responsive: Works on all device sizes
- ESP32-WROOM-32 or compatible
- Minimum 4MB flash memory
- WiFi capability
- 4-channel relay module (5V)
- PCA9685 PWM driver board
- Servo motor (SG90 or compatible)
- Jumper wires and breadboard
- 5V power supply
Relay Control:
- Relay 1 (Pump 1): GPIO 13
- Relay 2 (Pump 2): GPIO 12
- Relay 3 (Pump 3): GPIO 14
- Relay 4 (DC Motor): GPIO 27
I2C (PCA9685):
- SDA: GPIO 21
- SCL: GPIO 22
Servo:
- Connected to PCA9685 Channel 0
-
Install MicroPython on your ESP32:
esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 esp32-micropython.bin
-
Upload Project Files:
# Upload all files in esp-board/ directory to ESP32 ampy --port /dev/ttyUSB0 put esp-board/boot.py ampy --port /dev/ttyUSB0 put esp-board/config.py ampy --port /dev/ttyUSB0 put esp-board/main_board.py ampy --port /dev/ttyUSB0 mkdir lib ampy --port /dev/ttyUSB0 put esp-board/lib/ lib/ -
Configure WiFi in
config.py:WIFI_CONFIG = { 'ssid': 'Your_WiFi_Name', 'password': 'Your_WiFi_Password', 'timeout': 10, 'timezone_offset': 3.5 # Iran timezone }
-
Install Python Dependencies:
pip install streamlit requests pandas
-
Run the Control Interface:
streamlit run streamlit_app.py
http://[ESP32_IP_ADDRESS]/
GET /relay/{channel}/{action}?duration={seconds}- channel: 0-3 (relay channel number)
- action:
onoroff - duration: Optional auto-off timer (seconds)
Example:
GET /relay/0/on?duration=30GET /servo/{angle}- angle: 0-180 (degrees)
Example:
GET /servo/90GET /statusResponse:
{
"status": "success",
"time": {
"year": 2024,
"month": 6,
"day": 6,
"hour": 14,
"minute": 30,
"second": 45
},
"relays": "operational",
"servo": "operational"
}- Open the Streamlit dashboard
- Enter your ESP32's IP address
- Use the control buttons to operate devices
- Monitor real-time status updates
- Navigate to "Timed Operations" page
- Select device, date, time, and duration
- Click "Add Task" to schedule
- View and manage scheduled tasks
- Check connection status indicator
- View current system time
- Monitor device states
- Review operation logs
DEVICE_CONFIG = {
'pump1': {
'channel': 0,
'max_duration': 300, # 5 minutes
'name_en': 'Water Pump 1',
'name_fa': 'ΩΎΩ
ΩΎ Ψ’Ψ¨ Ϋ±'
},
# ... more devices
}SYSTEM_CONFIG = {
'debug_mode': False,
'memory_threshold': 50000, # bytes
'max_concurrent_connections': 5
}- Maximum Duration Limits: Prevents device overrun
- Automatic Shutdown: Timer-based device protection
- Memory Monitoring: Prevents system crashes
- Error Recovery: Graceful handling of failures
- WiFi Reconnection: Automatic network recovery
-
ESP32 Not Connecting to WiFi
- Check SSID and password in config.py
- Verify WiFi signal strength
- Restart ESP32
-
Devices Not Responding
- Check GPIO connections
- Verify relay module power supply
- Test individual components
-
Web Interface Connection Failed
- Confirm ESP32 IP address
- Check network connectivity
- Verify firewall settings
Enable debug mode in config.py:
SYSTEM_CONFIG = {
'debug_mode': True
}This project is licensed under the MIT License - see the LICENSE file for details.
Erfan Mohamadnia
- GitHub: @erfanmohamadnia
- Email: [email protected]
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- β Hardware control implementation
- β Web server and API
- β Task scheduling system
- β Streamlit dashboard
- β Documentation
- π Mobile app (planned)
- π Advanced analytics (planned)
- MicroPython community for excellent documentation
- Streamlit team for the amazing framework
- ESP32 community for hardware support and examples
Generated by Copilot - Professional IoT Control System for ESP32