This is about a bar of mains lamps controlled from your Raspberry Pi's GPIO pins. It gave me a chance to get my computer interacting with the real world & humans in an impressive way. (I WAS a teacher of IT...) The bar of lights was originally made for control via DiscoLitez, the Winamp add-on, and then was used for several years with Liberty BASIC. Now dusted off for use on my Pi! I do come from the home of Bridgwater & Taunton carnivals!
NB You need old-fashioned filament lights if you want to flash them. CFL lights do NOT like this kind of use, and I'm wary of trying mains LED lights. For a more eco-friendly set-up, use high-efficiency LEDs & low voltage high current supplies, and use appropriate current-rated wiring.
Note if using positive logic, the 3.3V 'true'/ 'high' outputs will NOT drive an LED in series with the optoisolator. Use just the limiting resistor. Alternatively, use logic 'low' as a command to turn on the triac, wiring it from the +5V line to the chosen GPIO pin.
Use proper insulation/earthing practice. Track spacing on strip board is NOT designed to insulate mains voltage- hence my 'mid-air jungle' layout. Use earthed boxes or double-insulation, and use rubber grommets and sound cable termination. The PI is separated from the mains section by insulation good for 10000V in the opto-isolators, and the series resistor limits the current draw. Turning a pin ON delivers the 'high' 3.3V, and if you are using LED displays this makes logical sense.
I have the whole 8-channel set-up available, but for testing use just a single opto-isolated triac & 100W bulb. kilowatts of bulbs create kilowatts of heat- not sensible in small computer 'dens'.
-
The following python code was adapted from MagPi Issue 2 examples which were unfortunately published with wrong indenting.
#!/usr/bin/python import time import RPi.GPIO as GPIO GPIO.setup( 11, GPIO.IN) GPIO.setup( 12, GPIO.OUT) while True: if GPIO.input( 11): GPIO.output( 12, True) else: GPIO.output( 12, False) time.sleep( 0.2)