An AI-powered streetlight control system using XGBoost machine learning to optimize brightness levels based on environmental conditions and sensor data.
- AI-Powered Brightness Control: Uses XGBoost to predict optimal brightness levels (25%, 50%, 75%, 100%)
- Multi-Sensor Integration: Processes data from LDR, ultrasonic, rain, fog, and cloud sensors
- Energy Efficiency: Automatically calculates energy savings compared to full brightness
- Real-time Dashboard: Interactive web interface for monitoring and control
- Weather Integration: Simulated weather data integration (can be connected to Open-Meteo API)
- Prediction History: Tracks and visualizes prediction patterns
- Smart Recommendations: Provides contextual suggestions based on conditions
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Sensors │ │ XGBoost │ │ Dashboard │
│ - LDR │───▶│ ML Model │───▶│ Flask Web │
│ - Ultrasonic │ │ - 98.5% Acc │ │ Interface │
│ - Weather API │ │ - 4 Classes │ │ - Charts │
└─────────────────┘ └─────────────────┘ └─────────────────┘
chmod +x start.sh
./start.sh# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the application
python app.py-
Start the Server: The Flask server will start on
http://localhost:5000 -
Access Dashboard: Open your web browser and navigate to
http://localhost:5000 -
Input Sensor Data:
- LDR Reading: Light sensor value (0-1023, higher = brighter)
- Distance: Ultrasonic sensor reading (2-200 cm, <50cm = motion detected)
- Rain: Rainfall intensity (0-20 mm/hour)
- Fog: Fog density percentage (0-100%)
- Cloud Cover: Cloud coverage percentage (0-100%)
-
Get Predictions: Click "Predict Brightness Level" to get AI recommendations
-
Load Weather Data: Use the weather button to simulate real weather conditions
GET /: Main dashboard interfacePOST /api/predict: Get brightness predictionGET /api/history: Retrieve prediction historyGET /api/weather: Get simulated weather dataGET /api/analytics: System performance analytics
- Accuracy: 98.5%
- Training Data: 5,000 realistic samples
- Features: 5 sensor inputs
- Classes: 4 brightness levels (25%, 50%, 75%, 100%)
- LDR (36.7%) - Primary light sensor
- Rain (23.0%) - Weather condition
- Distance (19.0%) - Motion detection
- Cloud (10.9%) - Sky conditions
- Fog (10.4%) - Visibility factor
The system calculates energy savings compared to always using 100% brightness:
- 25% brightness: 75W saved per streetlight
- 50% brightness: 50W saved per streetlight
- 75% brightness: 25W saved per streetlight
- 100% brightness: 0W saved (full power)
streetlight-control/
├── app.py # Flask backend application
├── streetlight_xgboost_model.pkl # Trained ML model
├── expanded_streetlight_dataset.csv # Training dataset
├── requirements.txt # Python dependencies
├── start.sh # Startup script
├── README.md # This file
└── templates/
└── dashboard.html # Web dashboard interface
The XGBoost model was trained with:
- Algorithm: XGBoost Classifier
- Objective: Multi-class classification
- Classes: 4 brightness levels
- Features: 5 environmental sensors
- Training: 4,000 samples
- Testing: 1,000 samples
- Cross-validation: Stratified split
- Smart lighting algorithm based on LDR readings
- Weather-responsive adjustments
- Motion-activated brightness increases
- Realistic sensor correlations
To integrate with actual Arduino sensors:
- Replace simulated sensor inputs with real sensor readings
- Use the prediction API endpoint to get brightness recommendations
- Control LED/streetlight intensity based on predictions
Replace the simulated weather endpoint with real Open-Meteo API calls:
# Example Open-Meteo integration
url = "https://api.open-meteo.com/v1/current"
params = {
"latitude": your_latitude,
"longitude": your_longitude,
"current": ["precipitation", "cloudcover", "visibility"]
}- Extend the dataset with new sensor columns
- Retrain the XGBoost model with additional features
- Update the prediction API to handle new inputs
- Modify the dashboard interface accordingly
Modify the training data generation logic in the model training script to implement different brightness decision rules.
- Port 5000 in use: Change the port in
app.py - Model file not found: Ensure the pickle file is in the same directory
- Missing dependencies: Run
pip install -r requirements.txt
- Use the weather data loader for realistic testing scenarios
- Monitor the analytics panel for system performance insights
- Check prediction history for pattern analysis
- Real-time sensor integration
- Mobile app interface
- Advanced weather API integration
- Database storage for predictions
- Multi-location support
- Automated model retraining
- IoT device management
- Energy consumption tracking
- Fork the repository
- Create a feature branch
- Make improvements
- Submit a pull request
This project is open source and available under the MIT License.