Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Smart Streetlight Control System

An AI-powered streetlight control system using XGBoost machine learning to optimize brightness levels based on environmental conditions and sensor data.

Features

  • 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

System Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Sensors       │    │   XGBoost       │    │   Dashboard     │
│   - LDR         │───▶│   ML Model      │───▶│   Flask Web     │
│   - Ultrasonic  │    │   - 98.5% Acc   │    │   Interface     │
│   - Weather API │    │   - 4 Classes   │    │   - Charts      │
└─────────────────┘    └─────────────────┘    └─────────────────┘

Quick Start

Method 1: Using the startup script (Linux/Mac)

chmod +x start.sh
./start.sh

Method 2: Manual setup

# 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

Usage

  1. Start the Server: The Flask server will start on http://localhost:5000

  2. Access Dashboard: Open your web browser and navigate to http://localhost:5000

  3. 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%)
  4. Get Predictions: Click "Predict Brightness Level" to get AI recommendations

  5. Load Weather Data: Use the weather button to simulate real weather conditions

API Endpoints

  • GET /: Main dashboard interface
  • POST /api/predict: Get brightness prediction
  • GET /api/history: Retrieve prediction history
  • GET /api/weather: Get simulated weather data
  • GET /api/analytics: System performance analytics

Model Performance

  • Accuracy: 98.5%
  • Training Data: 5,000 realistic samples
  • Features: 5 sensor inputs
  • Classes: 4 brightness levels (25%, 50%, 75%, 100%)

Feature Importance:

  1. LDR (36.7%) - Primary light sensor
  2. Rain (23.0%) - Weather condition
  3. Distance (19.0%) - Motion detection
  4. Cloud (10.9%) - Sky conditions
  5. Fog (10.4%) - Visibility factor

Energy Savings

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)

File Structure

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

Model Training Details

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

Training Features:

  • Smart lighting algorithm based on LDR readings
  • Weather-responsive adjustments
  • Motion-activated brightness increases
  • Realistic sensor correlations

Integration Notes

Arduino Integration

To integrate with actual Arduino sensors:

  1. Replace simulated sensor inputs with real sensor readings
  2. Use the prediction API endpoint to get brightness recommendations
  3. Control LED/streetlight intensity based on predictions

Weather API Integration

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"]
}

Customization

Adding New Features

  1. Extend the dataset with new sensor columns
  2. Retrain the XGBoost model with additional features
  3. Update the prediction API to handle new inputs
  4. Modify the dashboard interface accordingly

Adjusting Brightness Logic

Modify the training data generation logic in the model training script to implement different brightness decision rules.

Troubleshooting

Common Issues:

  1. Port 5000 in use: Change the port in app.py
  2. Model file not found: Ensure the pickle file is in the same directory
  3. Missing dependencies: Run pip install -r requirements.txt

Performance Tips:

  • Use the weather data loader for realistic testing scenarios
  • Monitor the analytics panel for system performance insights
  • Check prediction history for pattern analysis

Future Enhancements

  • 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

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make improvements
  4. Submit a pull request

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages