Smart Proximity-Based Display Control for Raspberry Pi
A Python application that uses the HLK-LD2450 24GHz mmWave radar sensor to automatically control display brightness based on human presence. Perfect for home dashboards, kiosks, and smart displays that should wake when someone approaches and sleep when they leave.
- π― Precise Proximity Detection - Uses 24GHz mmWave radar for accurate human presence detection
- π Smooth Brightness Control - Gradual fade in/out transitions for comfortable viewing
- π Advanced Filtering - Intelligent algorithms to eliminate false readings and static objects
- β‘ Real-time Processing - Async-based architecture for responsive control
- π‘οΈ Interference Resistant - Smart filtering handles metal interference and environmental noise
- π Comprehensive Logging - Detailed logging with configurable levels for debugging
- π§ Easy Configuration - Simple parameter adjustment for different mounting positions
- Raspberry Pi 5 (or compatible)
- HLK-LD2450 24GHz mmWave Radar Sensor
- Waveshare 13.3" DSI LCD (or compatible display with brightness control)
- USB-to-Serial adapter (if needed for sensor connection)
git clone https://github.com/edizaziz-dev/homedashsensor.git
cd homedashsensorpython3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- Connect the LD2450 sensor to your Raspberry Pi via USB or GPIO UART
- Mount the sensor above your display for optimal detection (avoid placing behind metal)
- Configure display brightness permissions:
# Add udev rule for brightness control
sudo tee /etc/udev/rules.d/99-backlight.rules << EOF
SUBSYSTEM=="backlight", ACTION=="add", RUN+="/bin/chgrp video %S%p/brightness", RUN+="/bin/chmod g+w %S%p/brightness"
EOF
# Add user to video group
sudo usermod -a -G video $USER
# Reload udev rules
sudo udevadm control --reload-rules
sudo udevadm triggerEdit the sensor port in main.py if needed:
# Update this line with your sensor's serial port
sensor = LD2450(port='/dev/ttyUSB0') # or /dev/ttyAMA0 for GPIO UARTcd homedashsensor
python main.pyEdit the proximity_config in main.py to customize behavior:
proximity_config = {
'proximity_threshold_mm': 500, # Detection distance (mm)
'min_detection_count': 2, # Consecutive detections needed
'min_speed_threshold': 0.5, # Minimum speed to filter static objects (cm/s)
'max_distance_change': 200, # Maximum distance change between readings (mm)
'detection_timeout': 2.5, # Timeout before sleep (seconds)
}Run the calibration tool to test sensor readings:
python calibrate_sensor.pyTest filtering algorithms:
python test_filtering.pyDemo proximity detection without hardware:
python demo_proximity.pyhomedashsensor/
βββ __init__.py
βββ main.py # Main application
βββ ld2450_protocol.py # LD2450 sensor communication
βββ display_manager.py # Display control and proximity logic
βββ calibrate_sensor.py # Sensor calibration tool
βββ demo_proximity.py # Hardware-free demo
βββ test_*.py # Various test scripts
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project configuration
βββ README.md # This file
- Position: Mount sensor above the display center
- Threshold: 500mm (50cm) for comfortable detection range
- Timeout: 2.5s for responsive sleep behavior
proximity_config = {
'proximity_threshold_mm': 500,
'detection_timeout': 2.5,
# ... other settings
}If you must mount behind the display, use these settings and ensure minimal metal interference:
proximity_config = {
'proximity_threshold_mm': 400,
'detection_timeout': 3.0,
'min_speed_threshold': 1.0, # Higher threshold for metal interference
# ... other settings
}Sensor not detected:
# Check USB devices
lsusb
# Check serial ports
ls /dev/tty*Permission denied for brightness control:
# Verify group membership
groups $USER
# Test brightness control
echo 128 | sudo tee /sys/class/backlight/*/brightnessFalse detections:
- Increase
min_speed_thresholdto filter static objects - Adjust
max_distance_changefor environmental stability - Ensure sensor is not behind metal surfaces
No detection:
- Check sensor mounting position and orientation
- Verify
proximity_threshold_mmis appropriate for your setup - Run
calibrate_sensor.pyto test raw sensor readings
The application uses structured logging with multiple levels:
- INFO: General operation status
- DEBUG: Detailed sensor readings and filtering decisions
- ERROR: Hardware errors and exceptions
Logs include emojis and structured data for easy monitoring and debugging.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
# Install development dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/
# Run type checking (if you add type hints)
python -m mypy homedashsensor/This project is licensed under the MIT License - see the LICENSE file for details.
- Primary Developer: edizaziz-dev - Proximity detection application and advanced filtering
- Protocol Implementation: Ron Martin (csRon) - Original LD2450 protocol reverse engineering and Python implementation
- AI Assistant: GitHub Copilot - Code assistance and optimization
- HLK-LD2450 Sensor: Hi-Link Electronic Co., Ltd. for the excellent 24GHz mmWave radar sensor and official documentation
- LD2450 Protocol Implementation: Based on official Hi-Link documentation and community reverse engineering efforts
- Serial Protocol Credits: Community contributors who documented the binary communication protocol
- Waveshare: For the DSI LCD display and documentation
- pyserial: Serial communication with the LD2450 sensor
- loguru: Beautiful and powerful logging
- matplotlib: Data visualization for calibration tools
- Raspberry Pi Community: For extensive documentation and support
- Ron Martin (csRon): For the foundational LD2450 protocol implementation that made this project possible
- mmWave Radar Community: For sharing knowledge about 24GHz radar sensors and protocol documentation
- LD2450 Protocol Contributors: Community members who reverse-engineered and documented the serial communication protocol
- Home Automation Community: For inspiration on proximity-based automation
- LD2450 Protocol: Based on csRon/HLK-LD2450 by Ron Martin (MIT License)
- Serial Communication: Core protocol functions adapted from Ron's excellent reverse engineering work
- Data Parsing Logic: Binary protocol implementation following Ron's documented format
- Command Structure: Extended from Ron's implementation with object-oriented design
- Hardware Integration: Building on the solid foundation of Ron's protocol documentation
- Thanks to the open source community for providing excellent libraries and documentation
- Thanks to Hi-Link Electronic for creating accessible and well-documented radar sensors
- Thanks to everyone who contributed to making this project possible
- csRon/HLK-LD2450 - Original Python protocol implementation by Ron Martin (Foundation for this project)
- LD2450 Arduino Library - Arduino implementation
- Home Assistant LD2450 Integration - ESPHome component
- mmWave Radar Projects - Other radar sensor projects
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Review existing Issues
- Create a new issue with detailed information about your setup and problem
Made with β€οΈ for the Raspberry Pi and Home Automation community