Notifiche
Cancella tutti

LED lighting with remote control  

  RSS
mjf2708
(@mjf2708)
New Member
LED lighting with remote control

I recently decided to install LED lighting on my Original Prusa i3 Mk2, using these brackets:
http://www.thingiverse.com/thing:1615578
and this LED strip (cut down):
http://www.ebay.co.uk/itm/Rigid-LED-Strip-39SMD-12v-10-30v-DC-7W-Cool-White-52cm-1163-/111315261380?var=&hash=item19eae817c4:m:mN8ZFrUfdORork5F24_OL0A

Then I realised that, with my Raspberry Pi (OctoPrint) mounted on the frame, I could turn on / off / dim the LED strip remotely. I used this simple circuit:

which uses a MOSFET driven by a GPIO pin on the RPi.

I wrote the following short Python script:
#!/usr/bin/env python

# LED controller
# Usage: ./led.py
#
# Uses GPIO Zero library - to install, use:
# sudo apt-get install python-gpiozero

from gpiozero import PWMLED

# GPIO pin number
pin = 17

led = PWMLED(pin)
led.on()
print "LED fully on"

while True:

arg = raw_input("Enter a value between 0 and 100 / q to quit: ")
if arg == 'q': quit()

if arg == '0':
led.off()
print "LED off"
elif arg == '100':
led.on()
print "LED fully on"
else:
led.value = float(arg)/100
print "LED dimmed to ", arg, "%"

This makes use of the GPIO Zero library, which greatly simplifies GPIO control, and uses PWM to set the light level. To use it, just type './led.py' (without the quotes) from the directory it's stored in. The LED strip will turn on, and the script will enable you to enter a value (percentage) between 0 (off) and 100 (fully on), or q to quit. I found the loop was necessary to keep the script alive, as the GPIO is reset once the script terminates.

Here are some pictures:

Postato : 30/11/2016 6:25 pm
Condividi: