Electronic switch for LED lights, 4 channels, 9 to 24 volts in, 5 volts out. Uses an AVR ATtiny2313 microcontroller.
Table of contents
Details
I used to have a very small apartment, and in that apartment I made a lot of the LED lights myself. To make it easier to control and power them I also built this electronic light switch. With a voltage regulator, and large heat-sink, it took 9 to 24 volts in; and gave out four channels of 5 volts. I used dual-color red and green LEDs to show the state of each output, and push-buttons to toggle them. After 10 seconds on inactivity the LEDs would turn off. The maximum load pr. channel were 500mA, not a lot but enough to drive some LEDs.
Power to the module was provided with a power jack at the bottom, and the outputs and signals through a 9 pin d-sub plug. I used a multicore cable down to a junction box, and from there to all the different LED lights. This did leave me with a lot of cables going to all the different lights, but I was single and didn’t really care.
The unit had a “lights out” input that turned all the outputs off. This allowed some external controller or service to turn off the lights when I left or went to bed. But the lights could only be turned back on using the push-buttons.
Using relays the electronic switch module could of course be used to control all kinds of stuff. But I built it to control and power the LED lights listed below.
Lights
I used this unit to power and control three lights in my apartment:
- Two channels were used for four dual color LEDs. One channel for the white lights, and one for the colored.
- A green LED in the pot of my tiny Bonsai tree.
- And two LED dot lights mounted in the window frame of my living room window.
Video
I/O
Inputs
- PA.0 Push button 1
- PA.1 Push button 2
- PD.0 Push button 3
- PD.1 Push button 4
- PD.2 Signal to turn all lights off
Outputs
Status LED
- PB.0 LED 1 green
- PB.1 LED 1 red
- PB.2 LED 2 green
- PB.3 LED 2 red
- PB.4 LED 3 green
- PB.5 LED 3 red
- PB.6 LED 4 green
- PB.7 LED 4 red
LED light outputs
- PD.3 LED lighting 1
- PD.4 LED lighting 2
- PD.5 LED lighting 3
- PD.6 LED lighting 4
D-Sub 9-pin
- LED lighting 1
- LED lighting 2
- LED lighting 3
- LED lighting 4
- Lights out -12V
- Lights out +12V
- -5V out
- +5V out
Source code
- Bascom-AVR source is available in a git repository:
- https://github.com/thomasjsn/AVR-Electronic-switch-4-channels
Photos
Schematic drawing
Parts list
- 1 × AVR ATtiny2313-20PU, DIL-20, 20 MHz, 18 I/Os
- 1 × Capacitor, aluminium electrolytic, 10 µF, 25V
- 2 × Capacitor, aluminium electrolytic, 47 µF, 25V
- 1 × Capacitor, ceramic, 1 nF, 100V
- 1 × D-sub soldering cups, 9 pin female
- 1 × DIL socket, 20-pin, 7.62mm
- 1 × DIL socket, 6-pin, 7.62mm
- 1 × Diode, rectifier, 1 A, 400V, 1N4004
- 1 × Enclosure, plastic (1591 FL), 120x65x40mm, flange
- 1 × Enclosure, plastic (1591), 112x62x31mm
- 1 × Fuse 5x20 mm, 500 mA, fast-acting
- 1 × Fuse holder, open, PCB, 5x20mm
- 1 × Fuse holder, open, PCB, Protective cover
- 1 × Heat conducting film for heatsink, Adhesive, TO220
- 1 × Heatsink, 6K/W @ 10W, 37.5mm 49g
- 4 × LED 5mm, Red/Green, 2.0 2.1V, 10mA, 100 63mcd, 30°
- 4 × LED holder 5mm, RTC51, black plastic
- 1 × Optocoupler, single, CNY17F-3, DIL-6
- 1 × Power jack, panel, 2.1mm, plastic housing
- 13 × Resistor, carbon film, 0.25W, 330 Ω, 5%
- 5 × Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
- 5 × Resistor, carbon film, 0.25W, 10 kΩ, 5%
- 1 × Resistor, metal film, 0.6W, 1 kΩ, 1%
- 13 × Straight pin header, female, Single row, 2.54mm
- 13 × Straight pin header, male, Single row, 2.54mm
- 4 × Switch, push-button, 1-pole, 1A, 50VAC, on-(off)
- 2 × Terminal block, PCB, screw, 5mm 2-pin
- 4 × Transistor, NPN, 800 mA, 45V, 0.625W, BC337-25
- 1 × Voltage regulator +5V, 1 A, 7805PI
- 1 m Wire, stranded, 0.22mm2, Black
- 3 m Wire, stranded, 0.22mm2, Grey
- 1 m Wire, stranded, 0.22mm2, Red
- 3 m Wire, stranded, 0.22mm2, Yellow
Last commit 2024-11-11, with message: Add lots of tags to posts.