Detect human presence and location in real-time using Wi-Fi Channel State Information (CSI) with ESP32 and Machine Learning - no cameras or wearables required!
This project uses Channel State Information (CSI) from an ESP32 device to detect and classify human presence into four predefined zones within a room using machine learning techniques. The system operates entirely through Wi-Fi signal analysis, making it a non-intrusive privacy-friendly solution.
Channel State Information (CSI) represents how Wi-Fi signals propagate from transmitter to receiver, capturing fine-grained information about the wireless channel. When humans move through the environment, they cause changes in signal propagation that can be detected and analyzed to determine location and movement patterns.
- โ No cameras or wearables - completely privacy-friendly
- ๐ Real-time zone detection with 80.5% accuracy
- ๐ Live monitoring with terminal-based visualization
- ๐ค Machine learning powered by XGBoost with PCA and SMOTE
- ๐ Data balancing to handle uneven zone occupancy
- โก Low latency predictions via serial communication
| Component | Technology |
|---|---|
| Hardware | ESP32 in AP mode |
| Language | Python 3.8+ |
| ML Model | XGBoost Classifier |
| Preprocessing | PCA + SMOTE |
| Communication | Serial (PySerial) |
| UI | Terminal-based real-time display |
Seefromwall/
โโโ ZONE1.csv # Training data for Zone 1
โโโ ZONE2.csv # Training data for Zone 2
โโโ ZONE3.csv # Training data for Zone 3
โโโ ZONE4.csv # Training data for Zone 4
โโโ trainmodel.py # Model training script
โโโ live_predict.py # Real-time prediction script
โโโ csi_zone_model.pkl # Trained XGBoost model
โโโ csi_zone_pca.pkl # PCA transformer
โโโ csi_label_encoder.pkl # Label encoder
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
Our trained model achieves impressive results:
- ๐ฏ Accuracy: 80.5%
- ๐ F1-Score: 0.80 (macro average)
| Pred Zone 1 | Pred Zone 2 | Pred Zone 3 | Pred Zone 4 | |
|---|---|---|---|---|
| Zone 1 | 151 | 10 | 24 | 9 |
| Zone 2 | 6 | 180 | 10 | 22 |
| Zone 3 | 20 | 23 | 130 | 9 |
| Zone 4 | 2 | 6 | 7 | 150 |
- ESP32 development board
- Python 3.8 or higher
- USB cable for ESP32 connection
pip install -r requirements.txtOr install manually:
pip install numpy pandas scikit-learn xgboost joblib imbalanced-learn pyserialUse a CSI-enabled firmware (ESP32 CSI tool or modified ESP-IDF example). This project uses:
https://github.com/espressif/esp-csi โ specifically
csi_recv_router
The ESP32 was flashed with this to capture CSI data, which was then transmitted via serial to Python.
If you want to retrain the model for your specific environment:
python collect_csi.py # Collect data for each zonepython trainmodel.pyThis generates:
csi_zone_model.pkl- Trained XGBoost classifiercsi_zone_pca.pkl- PCA transformercsi_label_encoder.pkl- Label encoder
python live_predict.pyThe system provides a real-time terminal interface showing current zone detection:
## ๐ก Real-Time CSI Zone Monitor
โช ZONE 1
๐ข ZONE 2 โ Active
โช ZONE 3
โช ZONE 4
--------
โฑ Updated at: 01:42:01
CSI_DATA,0,ee:8a:c6:a9:19:f4,-67,11,1,7,0,0,1,0,0,0,1,-96,0,6,0,8162657,0,126,0,128,1,"[126,96,7,0,28,...,30,17]"
The CSI array contains 128 complex values representing the channel response across different subcarriers.
Update the COM port in live_predict.py:
SERIAL_PORT = 'COM5' # Windows
# SERIAL_PORT = '/dev/ttyUSB0' # Linux
# SERIAL_PORT = '/dev/cu.usbserial-*' # macOSModify zone definitions in your training data collection phase to match your room layout.
- Data Collection: ESP32 in AP mode captures CSI packets from Wi-Fi signals
- Preprocessing: Raw CSI data is parsed into 128-element arrays
- Feature Engineering: PCA reduces dimensionality while preserving important features
- Data Balancing: SMOTE handles class imbalance across different zones
- Classification: XGBoost classifier predicts the most likely zone
- Real-time Inference: Live CSI packets are processed and displayed instantly
- ๐ง Deep Learning: Implement LSTM/CNN for temporal sequence modeling
- ๐ฅ Multi-person Tracking: Detect and track multiple individuals
- ๐ 3D Visualization: Web-based room visualization with real-time avatars
- ๐ฑ Mobile Dashboard: WebSocket-based mobile/web interface
- ๐ Smart Home Integration: MQTT integration for home automation
- ๐ฏ Improved Accuracy: Advanced feature extraction techniques
This project has applications in:
- Smart Buildings: Occupancy detection and space utilization
- Healthcare: Elderly monitoring and fall detection
- Security: Intrusion detection systems
- IoT: Context-aware smart home automation
- Research: Human-computer interaction studies
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the Project
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
- ESP32 community for CSI extraction tools
- scikit-learn and XGBoost developers
- Research papers on CSI-based human detection
Madhav Shah
This project is for educational and research purposes only. Ensure proper privacy compliance and obtain consent when deploying in real environments.
โญ If you found this project helpful, please give it a star! โญ