From LED to 240V switching (Running lights)

Hi guys,

I need help in switching from LED Power (5Volts) to 240V. I done the Running Lights (knight rider) unit, with 10 LEDS.

Now I need to connect a 240Volts SMD (5 watts) lamp to each Led. I cannot use relays, since in some instance of the code, the leds flash quite fast, and am afraid that this will damage the relay.

I thought of using a Triac, but cannot find a circuit to show me, how to connect it the arduino. (or after the LED). I know that probably I need a resistor, and a capacitor on the Live terminal, but cannot figure this out.

Can anybody help please?


Please confirm you are actually wanting to power the LEDs from mains power via a low voltage power supply.

If you want to connect 240v to the LED, you will find it difficult to get anyone involved because of the HIGH danger involved.


^^ Keep it low voltage.
Get a 12volt supply, some logic mosfets, and 12volt COB-LEDs from ebay.

You can easily do this with a solid state relay. Example:

Solid State Relay

or on E-Bay. $5 -$30.

Switches 240 VAC quickly, doesn't wear out, SAFE, UL/CSA/CE, comes with safety cover. Activates from a 5 Volt signal or anything 4-32 VDC. 8mA. 240V is isolated from your Arduino.

I guess that an optoisolator, and a triac should do the job.


You cannot use a TRIAC directly because power line voltage MUST be electrically ISOLATED from your Arduino (and yourself).

It's possible to build your own solid state with a [u]special optoisolator[/u] and a TRIAC. I've built 4 of these built-into a 4-gang power outlet box. But, I don't recommend playing around with lethal voltages if you are a beginner. It's better to buy a solid state relay so you only have to connect 2-wires on the high-voltage side.

Try switching one LED first before you buy 10 solid state relays. The 220V power supplies built-into your LED lamps may not switch on & off instantly, they may not "like" being switched rapidly and they may react erratically.

Normally, the low-voltage side is switched/controlled. There are special constant current* LED power supplies that can be switched/dimmed with a 10V signal. The 10V input is electrically isolated and safe. But, since the standard is 1V and the Arduino output is 5V, you do need to add a transistor or some kind of driver. But, 10 of these would be very expensive.

You might consider regular-old incandescent lamps. They don't snap on & off like LEDs, but they are fast enough for a Knight Rider effect, and it will be a lot less expensive.

I use incandescent lamps with my 4-channel controller, and one of my effects is a 4-channel Knight Rider-like effect. Although by set-up it's only 4-channels, I can plug-in as many as 16 floodlights arranged in a line, square, or circle. There are a few other randomly selected effects and, the Knight Rider effect randomly has 1 to 4 lamps on at a time or it can be inverted so that the off-lamps "move" instead of the on-lamps. These are all audio controlled and the Knight Rider effect gets faster with louder music.

  • They are called constant current, but technically they are controlled current since they are dimmed by controlling the current.

OP please give full details of what you are doing. We are just guessing from current information.


thanks guys for your posts. Just to set your mind at piece, I am not a beginner, were it involves High Voltages, I have been working in electrical for over 14 years. I am not that practical with electronics, even If I had studied and T.V at school. So thanks for all those concerned about my safety, but dont worry, I dont take risks.

Back to this project...

I have found this

but after building it up, the bulb remains always ON.. I tried another triac (out of the circuit), meaning I have soldered it directly (A1 to live, A2 to Bulb, Neutral to Neutral).. and still it turns alone.

I am using an FT0407DH triac, since I have not found the same as indicated on sketch, but at the shop they said its an equivalent.

Shouldnt the bulb remain OFF, if the triac is not trigerred? Or I am missing something out?


If you disconnect the gate, leave it open circuit, is the lamp OFF?

Tom.... :slight_smile:

There's a discrepancy between the schematic and the accompanying fritzing abomination, vis-a-vis the lamp, MT1/MT2 and the juice.
(The sanguinity of the "house wiring" and breadboards is dubious.)
Those VO2223 ICs are just the ticket, buddy.

Thanks guys,

Its solved. The lamp was remaining on due to a leak on the Gate.

I used an optoisolator and a triac, and managed to built a 10 way cct.

@runaway pancake.. I have to try those v0223. They make life much easier.. But being a sunday today, and I had to hand in this board by tomorrow, I had to do with what I had!!.. Hope I can find locally.

Thanks guys..

As regards to the code.. I found 1 and modified it a bit, so the sequence wont be always the same, and it works fine.

Is there a way, to make the code run for lets say.. 10 minutes. and than it starts again after the elapsed time? and so on and so forth.

Is there a way, to make the code run for lets say.. 10 minutes. and than it starts again after the elapsed time? and so on and so forth.

This isn't "hard". If you wrote the Knight Rider code yourself it should be no problem. But if you simply copied the code and you don't understand the details it may not be easy for you to modify it.

First, you need to understand the [u]Blink Without Delay Example[/u]. First you reads the "current time" (the number of milliseconds since the Arduino was booted). Then you run your loop until the current time is greater by a certain amount (10 minutes is 600,000 milliseconds).

Second, you also need to understand loops. I'd suggest a [u]while() loop[/u].

Thanks for your reply.

As a matter of fact, Yes, I did copy the code, which was just an example code, and than I continued modifying it. As you pointed out, I am not able to write the code myself, from scratch, but I can understand each line. (not always.. :slight_smile: ) Thats why I am here!.. hehe

O.K. I got your point, in using a "while loop".. I used it a couple of months ago, when I had to do a 3 floor elevator board, and so far so good..

I just have to figure out, how to imply it in this code..

If not.. a simple timer will play the game. :slight_smile: But its a pity, doing hardware, when it only needs a couple of lines.

You should be able to do what you want with [gasp, horrors] delay()