This is a collection of Raspberry Pi sensor demo projects, including human body detection, light detection, email alert, collision detection, and integrated sensor detection.
Note: The current code is developed and tested based on Raspberry Pi 3 Model B
raspberry-pi-demo/
├── setup.py
├── README.md
├── README_en.md # English version README
├── requirements.txt # Project dependencies list
├── venv/ # Python virtual environment
├── __init__.py
├── sensor_detection.log # Sensor detection log file
├── src/
│ ├── __init__.py
│ ├── body_detect.py # Human body detection module, using infrared sensor to detect human activity and send email alerts
│ ├── smartlite.py # Light detection module, detecting environmental light changes
│ ├── email_alarm.py # Email alert module, independent email sending function
│ ├── collision_detection.py # Collision detection module, using infrared obstacle avoidance sensor to detect obstacles
│ └── sensor_integration.py # Integrated sensor detection module, simultaneously detecting human body and collision
├── tests/
└── docs/
└── collision_detection_design.md # Collision detection design document
- Uses GPIO 18 to connect to human body infrared sensor
- Sends email alert when human activity is detected
- Emails are sent via SMTP protocol
- Uses GPIO 3 to detect environmental light changes
- Outputs timestamp and notification when light changes are detected
- Independent email sending module
- Can be called by other modules to send alert emails
- Uses infrared obstacle avoidance sensor to detect obstacles ahead
- Detectable distance range: 2-30cm (adjustable)
- Real-time detection with output results
- Simultaneously detects human body sensor (GPIO18) and collision sensor (GPIO4)
- Buzzer sounds continuously when human body is detected (GPIO17), LED lights up when obstacle is detected (GPIO23)
- Real-time polling detection with logging
- Supports dual logging to file and console
- Human body infrared sensor connected to GPIO 18
- Light sensor connected to GPIO 3
- Infrared obstacle avoidance sensor connected to GPIO 4
- Buzzer connected to GPIO 17
- LED connected to GPIO 23
-
Clone the project:
git clone https://github.com/zhangsl/raspberry_demo.git cd raspberry-pi-demo -
Create virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # Linux/MacOS # Or use venv\Scripts\activate on Windows
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables:
export MAIL_HOST=smtp.yeah.net export MAIL_USER=your_username export MAIL_PASS=your_password export SENDER=your_email@yeah.net export RECEIVERS=recipient1@domain.com,recipient2@domain.com
-
Run the programs:
python src/body_detect.py python src/smartlite.py python src/email_alarm.py python src/collision_detection.py python src/sensor_integration.py
- Raspberry Pi hardware environment is required to run (developed and tested based on Raspberry Pi 3 Model B)
- Sensors need to be properly connected to the hardware
- Email alert function requires correct email configuration