Control LED Strip With Relay And Startup Script

  • Hello there, my name is Kevin. Long time reader of the forums first time poster. Ive been building some cabinets and bartops for friends and family and wanted to take my builds to the next level by adding some lights. I wanted these lights to turn on and off upon boot and shutdown of the pi to keep things simple and organized without the need of doing anything else other than just powering on the pi.

    Ive gotten this to work on my own, but what id like to change is when the lights turn on. right now the lights turn on right when the ES screen pops up after the recalbox splash. What id like is for the LED to come on right when the pi gets power. before the actual recalbox splash screen. Ive included a video of what I mean.

    what I have so far is a Led strip connected to a 5v relay connected to the pi via gpio and a script that runs at startup from /recalbox/share/system/ called

    heres the script im using, feel free to add any changes I should be making.

    # GPIO lib import
    import RPi.GPIO as GPIO
    import time
    channel = 18
    # GPIO setup
    GPIO.setup(channel, GPIO.OUT)

    I also have this script posted in /etc/init.d with no luck. but maybe im also not using the correct script.

  • Banned


    As I posted otherwhere, you need no script for this. As USB are powered up by PI when system starts (all systems) and powered down at shutdown, with the PI always under power. So you just need to connect the relay at an USB power line, by cable or breakout adapter, as you want.

Want to support us ?