Auto IR Illumination of led - Velkurkirankumar/Internship-Projects GitHub Wiki
This project uses a Raspberry Pi5, Picamera2, and Infrared led PWM control to automatically adjust the brightness of an IR illuminator based on ambient light conditions.The system dynamically calculates luminance values from camera frames and adjusts the brightness to maintain optimal conditions for AI/ML inference.
To make a simple system that can sense ambient light, we used the Picamera2 library to take pictures and measure how bright they are, and also researched this Manual picamera2 Doc for knowing the picam briefly.
Researched about this IR LED and went through the data sheet to know about this is present inside the link.
This flowchart shows how the system works to monitor the light levels and adjust the IR LED brightness.
Here’s a simple breakdown of each part:
-
Start Camera: The process starts by turning on the camera, which keeps taking pictures to measure how bright the surroundings are. The camera works in real-time to provide data for brightness calculations.
-
Measure Ambient Light: After the camera starts, the system checks how bright the environment is by analyzing the image. This brightness level is compared to a set value to decide if the IR light needs to be adjusted.
-
Decision Block: LT (Less) / AT (Above): This step checks if the brightness is above or below the set value.
- LT (Less): The light level is below the set value, meaning it is too dark.
- AT (Above): The light level is above the set value, meaning the environment is bright enough. Based on this, the system decides whether to increase or decrease the IR brightness.
-
Increase IR Brightness Gradually (Left Path): If the environment is too dark, the system will slowly increase the IR brightness by one level until there is enough light. Then, it measures the light again to see if more adjustments are needed.
-
Decrease IR Brightness Gradually (Right Path): If the environment is bright enough, the system will slowly decrease the IR brightness by one level. This helps save energy and prevents too much light in already bright places. The system then measures the light again.
-
Loop State: This process runs continuously, always checking the light level and adjusting the IR brightness to maintain a good level of lighting.
Summary:
- Low Light (below threshold): Increase IR brightness until there is enough light.
- Sufficient Light (above threshold): Decrease IR brightness to avoid wasting energy.
- Continuous Adjustment: The system keeps repeating the steps to adjust IR brightness smoothly without sudden changes.
- Raspberry Pi5
- IR illuminator and Cable [FFC] Flexible Flat Cable.
- Raspberry Pi Camera Module 3 NoIR Wide with Camera Cable(Standard-Mini|200mm).
- Raspberry Pi 27W USB-C Power supply
- SD card with Raspberry Pi Bookworm OS installed.
Download Raspberry Pi Imager to download the Raspberry Pi Imager from the official Raspberry Pi website and follow the procedure.
- Connect the IR illuminator with flexible flat cable(FFC) to RPI hat
- Attach the Raspberry Pi 5 Camera Module securely and cross check once with the command rpicam-hello.
- RPI hat -2D alert version v1.3.
- PowerOn the Raspberrypi 5 with the 27W USB-C Power supply
- Here you can see the picture "above", It represents the connections to raspberrypi5 with both InfraredLed Illuminator and camera that is connected through the cable.
- Download the ALS Project branch as .zip from the github.
scp -r <local_path of zip file> <username>@<hostname>.local:<remote_path>
If you want to connect with IP Address then use this command
scp -r <local_path of zip file> <username>@<ip address>:<remote_path>
- To connect to a Raspberry Pi remotely from your system, you can use the following SSH command:
ssh <username>@<hostname>.local
- Unzip the file
unzip <source code file.zip>
- Change directory to the extracted file
cd <source code directory>
- Then follow the below instructions.
- Update the Raspberry Pi:
sudo apt update && sudo apt upgrade -y
- Install required libraries:
sudo apt install python3-picamera2 libcamera-tools python3-pip
pip3 install rpi_hardware_pwm numpy
- If the error triggers like externally environment use this command to overcome this issue and run the above commands again
sudo mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old
- Run the Python script:
python3 auto_ir_control.py
- Automatically turns the IR illuminator on or off based on ambient light thresholds.
- Gradually adjusts the IR brightness using PWM to avoid sudden changes.
- Smooths luminance readings using a sliding window to reduce noise.
- Logs ambient brightness and IR brightness to a file.
- Records video while controlling the IR illuminator.
- rpi_hardware_pwm
- numpy
- picamera2
- Automatic Brightness Control: The system kept the LED brightness at good levels according to how bright the environment was, making dark scenes more visible.
- Resolution: The resolution specified in the camera configuration is: 2304 x 1296 pixels
- Data Logging: The logging helped to fine-tune settings and understand how the system was performing.
- Performance: The system worked smoothly at 30 FPS, showing that the Picamera2 and IR illuminator can handle real-time adjustments well.