PXL_20221231_001757763.mp4
Items needed:
- Raspberry Pi (I'm using RPi 3)
- Pi camera
- RGB LED strip with 3 pins for RGB and 1 pin for 12v DC power. I'm using this 5m LED strip.
- 3x N-channel MOSFETs. I'm using these.
- Power supply for the LED strip. I'm using this 12V 2A power supply.
- Male to female jack adapter connectors. I'm using this 5.5mm x 2.1mm connector.
- Breadboard
- Jumper wires (male-to-male, male-to-female)
Connect the LED strip to the Raspberry Pi as shown in the diagram below. The LED strip has 4 pins, 3 for RGB and 1 for 12v DC power. The 3 RGB pins are connected to the 3 MOSFETs, which are connected to the Raspberry Pi GPIO pins. The 12v DC power jack is connected to the 12v DC power supply.
Also connect the Pi camera to the Raspberry Pi.
Install the required packages with the following commands:
sudo pip install -r requirements.txt
Enable the camera with the following command:
sudo raspi-config
Select Interfacing Options
, then P1 Camera
, then Yes
and Finish
. Reboot the Raspberry Pi with
sudo reboot
The pigpio daemon is required to control the MOSFETs. Enable it with the following command:
sudo pigpiod
Run the script with the following command:
python lights.py
Create a new file called launch.sh
nano launch.sh
and add the following, replacing the path to the lights.py
script with the correct path on your system.
#!/bin/bash
# Start the pigpio daemon
sudo pigpiod
# Run the lights.py script
python /home/pi/lights.py
Save and exit the file with Ctrl+X
, Y
and Enter
. Now make the file executable with
chmod +x launch.sh
To run the script on startup, we need to add it to the rc.local
file. Open it with
sudo nano /etc/rc.local
Add the following line before the exit 0
line, replacing the path to the launch.sh
script with the correct path on your system. . The &
at the end of the line will run the script in the background.
/home/pi/launch.sh &
Save and exit the file with Ctrl+X
, Y
and Enter
. Now reboot the Raspberry Pi with
sudo reboot
Now launch.sh
will run on startup and start the pigpio daemon and the lights.py
script.