SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By jasmattkrz
#119779
I recently purchased the power driver shield: http://www.sparkfun.com/products/10305 and love it!

However, I've already outgrown it. I'm trying to make several wirelessly-controlled stations that run LED strings (Christmas lights), but the strings are designed to run off-the-shelf at 120v. The Mosfets on the board are limited to 60v, so I was wondering if it would be as simple as just inserting a higher voltage logic-level Mosfet, like the STP80NF12 http://parts.digikey.com/1/parts/102562 ... 0nf12.html and then running it off of 120v?

I suppose I'd have to remove/modify the 12v LED indicator (or else I'd burn it up), but as far as using the new Mosfet for PWM control of my LED light strings at 120v, what do you think?

Also, there is a rectifier in the light string already, but would I need to rectify the A/C before it gets to the Board/Mosfets, either for the sake of the Mosfet, or to eliminate zero-crossing? I know Triacs are usually used with A/C, but this seems like an easier way to do what I want (I'm still playing with a Triac circuit, but zero-crossing is kicking my butt, and I'm having a hard time finding clear information on how to dim my LEDs with a Triac through an Arduino, and not a potentiometer).

Thanks for your thoughts/advice!

-Jason
By n1ist
#119854
You have neither the isolation nor the spacing on that board to safely run at 120V, and the MOSFETs won't work for AC. You are better off using a board that has optoisolators driving triacs to control 120v loads. Look over in www.doityourselfchristmas.com for some sample solid-state relay designs or use all-in-one SSRs.

Be careful, as mains voltages can be deadly to you or your equipment...
/mike
By jasmattkrz
#119857
I've been trying to get a triac circuit to work, with a little success. The circuit can run low wattages, but I can't dim them because I can't figure out the interrupts. I have a post on the arduino pages asking for help.
http://arduino.cc/forum/index.php/topic,51671.new.htm

As I mentioned, I can easily rectify the 120v AC before it gets to the board, with your other concern being spacing/isolation. I haven't been able to find any data on spacing requirements for higher voltage levels (assuming you mean the distance between the traces on the board), so if you could point me to that information I'd appreciate it.

And by isolation, are you just referring to how easy it would be to touch the board and electrocute yourself (or a random conductive object that may encounter the exposed board and short it out?), because that is easily remedied with tapes/glues/etc manufactured for that purpose.

I'm aware of mains voltage dangers, and I've been working with 120v in residential applications long before I got to the vastly more complicated 5v components.

Thanks for your advice, I'm searching through http://www.doityourselfchristmas.com and I'll see what I can come up with.

-Jason
By n1ist
#119865
For AC phase angle control, you need to know where zero-crossing is, and then delay a certain amount from that to turn on the triac. The triac will turn itself off at the next zero crossing.

An easy way to detect zero-crossing is to use an H11AA1 opto (not H11A1, that's a different beast). It's output is open-collector, so you will need a pullup.

To control the triac, use an optocoupler like the MOC3023. Look at http://www.christmasinshirley.com/wiki/ ... itle=SSRez to see that part of the circuit.

If you are using DC (be careful - some LED strings have two series groups with diodes so each runs on one half of the AC line), you can eliminate the zero crossing detector, but I would still use an opto to drive the MOSFET.

Without isolation (either optical or magnetic), your circuit common is connected to (hopefully) the power line neutral. The ground on your scope, serial cable, or programmer is connected to power line ground. This can cause dangerous current flow that can damage equipment. If you accidentally get circuit common connected to power line hot (ie, a miswired outlet or a 2-wire plug) you will short the AC line through your gear. This is separate from the shock risk.

/mike
By jasmattkrz
#119871
Thanks, Mike!

Now I understand what you meant by isolation, so thanks for the clarification. I understand the benefit of optoisolation, and I agree that it's a good idea. I'll have to scrap the idea of simply upgrading the power shield in order to add optoisolators, but I'm not against it for the sake of safety.

I already have an MOC3041, which is similar to the MOC3023, but it has a zero-crossing circuit in it.
http://www.fairchildsemi.com/ds/MO/MOC3041-M.pdf

I bought the MOC3041 to make the triac circuit attached below, but I keep frying resistors.
AC-board-schematic.jpg
I'm trying to figure that out here: http://arduino.cc/forum/index.php/topic,51671.htm.

Even if I could get the circuit to work as an on/off switch, I have no idea how to actually use the zero crossing detector to facilitate dimming (I believe it would be handled with interrupts, but I don't fully understand the code). I'm happy to buy an H11AA1 (and I've seen them in other people's circuits), but I'd know as little about what to do with that one as I would with the one I have in the MOC3041. I understand what the zero crossing point is, and why I want to find/time it, I just don't know how.

Meanwhile, I figured that since I was having more luck with mosfets and DC, I could just modify the board I already have and bring it up to 120vdc (rectified AC), since LEDs are happier with DC anyway, and I'm happier with PWM. Would the MOC3023 or other optoisolator work with PWM?

Your guidance is greatly appreciated!

-Jason
You do not have the required permissions to view the files attached to this post.
By esklar81
#119873
Jason,

Have you considered that you might well be struggling with solving the wrong problem? :wink:

Frankly, I wouldn't assume that the LED strings you have even can be dimmed by PWM control of the AC power.

Rather than finding a painful (perhaps, literally) way to control the 120 Vac, why not remove the AC-driven front end from the string of lights? I suggest you carefully determine what the power is that's being supplied to the string of LEDs (that is, the output of whatever circuitry is provided with them) and look to build a PWM-modulated power supply to supply that power. That way, you can work safely and comfortably in the realm of (most probably, low voltage) DC.

Have Fun,
Eric
By jasmattkrz
#119880
Eric,

I know that I can't use PWM on AC, that's why I'm suggesting rectifying the AC (to get DC) and then using PWM to control the new mosfets at 120vdv (or using an optoisolator to control the mosfets, once I get an answer on whether or not that can be done with PWM or something else that I and the Arduino are capable of).

Also, you are assuming that there is something to remove from the front end of the lights! I have two kinds of LED strands, and the first just uses 25 LEDs wired in series with a 750ohm resistor to handle the AC (no additional circuitry). If you wave your hand in front of the lights, you get a rapid flickering similar to a "persistence of vision" effect. I am intimately familiar with this strand, since I rewired 7 of these to decorate my girlfriend's basement for a New Year's party:
CIMG4369.JPG
If you're interested, you can check out her blog/vblog about it here:
http://talesofagirlgamer.blogspot.com/

As for the second strand, it has 70 LEDs, and 3 "I'm not sure what's." When I ordered the second strand, the distributor said that it had a rectifier in the middle of the strand (and there is, in fact, no visible flicker), but I'm not sure what the other two things are, and the unknown items look exactly like the assumed rectifier (plastic encased cylinder 5cm long by 1.5cm diameter). They may very well be resistors as well.

Definitely in the first case, probably the second, I can't run the strands with much less than 120v, since they'll just get dimmer as I supply less voltage, until they won't light at all.

For the new strand of 70 LEDs, I was able to run only 3 LEDs in series off of a 12vdc/3amp power supply (and I was able to run multiple strings of 3 in parallel with other strings of 3), with both cylinders removed (I bought 2 strands so I could take 1 apart to test it). If I simply replicated this series/parallel trick, or wired them all in parallel, I could use 12v or less to run them all off the Power Driver Shield with a battery which could supply sufficient amperage. But since the final display is set to have 2000 lights, I don't feel like doing that much wiring (it took me three evenings to rewire/solder 150 LEDs for the New Year's party).

Of course, I could buy battery operated LEDs strands, which are probably wired in parallel, but they are much more expensive. The 70 LED strand was only $20, and if I buy enough for 2000, I get a break down to $16. At 23-29 cents per LED (with wiring and G12 bulbs over the LEDs), they are my best option, as long as I can power and dim them, which why I'm asking the forum-goers for your much appreciated help.

Thanks again!

-Jason
You do not have the required permissions to view the files attached to this post.
By n1ist
#119885
You can't dim using an opto or solid-state relay that has zero-crossing detection built in. They will only turn on at a zero-crossing (good to reduce noise). For dimming, you need to turn them on some time AFTER zero crossing. If you turn them on 1/4 of the AC cycle after ZC, the light will be on for 3/4 of the cycle, and be 3/4 as bright (not really as the LEDs and your eye are both logarithmic in their response rather than linear - look up "dimmer curve" for more info on how to fix that). Turn them on at the halfway point, and they'll be half brightness.

You know how long the AC cycle is (1/60 Hz here in the US, 1/50 Hz elsewhere), so you know how much each step of dimming (ie, 0..255 or 0..100) has to be. So you can use an interrupt to start a timer, and pulse the opto once the timer expires. No need to worry about turning the triac off since it will do that automatically at the next zero crossing.

LED strings come in two forms, one with halfwave rectification, and one fullwave. As you discovered, you can tell them apart by the flicker rate. Both of these can be dimmed with a standard dimmer, but you may need to add a snubber (resistor across the line) to keep things happy.

All of the Christmas light dimming systems that I know of (other than the original Lynx dimmer) use triacs and phase dimming instead of PWM'ed DC. PWM seems reserved for low-voltage (<= 24V) applications. There are a number of inexpensive designs over there with large (8-64) channel counts that have already solved these issues.

/mike
By jasmattkrz
#119893
Mike,
You can't dim using an opto or solid-state relay that has zero-crossing detection built in.
So if I got the MOC3023, which has no zero crossing detector, I could use the PWM signal from the Arduino to control/dim it (and therefore the mosfet)?
So you can use an interrupt to start a timer, and pulse the opto once the timer expires.
I could if I knew how! I haven't searched for a tutorial on using the Arduino timer/interrupt, since I was hoping to simply assemble an existing circuit design and use the corresponding code. If anyone could point me in that direction, I'd appreciate it.
All of the Christmas light dimming systems that I know of (other than the original Lynx dimmer) use triacs and phase dimming instead of PWM'ed DC. PWM seems reserved for low-voltage (<= 24V) applications...There are a number of inexpensive designs over there with large (8-64) channel counts that have already solved these issues.
It seems to me that it's just more practical, since anyone with extensive knowledge of the circuitry involved would just do what I tried first (the triac), and failed at, but they would do it successfully. It's an extra step with additional ramifications to rectify the current and have a dc output. In my case, the ramifications are limited since I plan to only use such a circuit on LEDs which run better on DC. There are several boards on http://www.doityourselfchristmas.com(the Renards and Helix for example) that do PWM dimming.

If I did get a board from the list above, I could actually go with a DMX controlled board, since I've already made a DMX controller for my Arduino (controlled using the dmxsimple library).

Still, it may just seem like I'm being stubborn, but it looks like the simplest solution would be to take 120vac, rectify it to 120vdc, run that into a 170v (or higher) mosfet attached to an optoisolator which is triggered by the PWM pin on an Arduino (which is also linked to an xbee), and then plug my off-the-shelf LED string into that, and I'm done. The code would be exceptionally simple. The only way I can think of that this wouldn't work is if I'm missing some sort of latching current problem or something like that which I don't understand at all, so I'm asking if you or anyone thinks such a variable might exist.

Unless, of course, there is an Arduino-based TRIAC tutorial with a circuit diagram and example code that anyone knows about.

Thanks, and I really appreciate you working through this with me.

-Jason
By jasmattkrz
#120254
Thanks to everyone who offered me their advice and expertise. I've ordered a bunch of parts to test out a variety of circuits (triacs, mosfets, isolators, etc), and I'll report back with my findings when I start putting them together.

Again, thank you to everyone who took the time to help!
By n1ist
#120266
Careful with Microchip's apps notes. Some (like the one you quote) can be lethal if you don't take proper precautions when working on them. Others are illegal (NEC violations from tying neutral to ground...) In addition to the safety issues, they are trying to dissipate over a quarter watt in an 1/8 watt resistor.
waltr wrote:For AC dimming circuits from a u-controller check Microchips app notes.

Here is one:
http://www.microchip.com/stellent/idcpl ... e=en025234
I think they have some others.
By jasmattkrz
#121111
Status update: it works!

What I've done is to take wall power and run it through a 4amp rectifier bridge, then run that power through my 9am 200v mosfet with an outlet in line with the positive wire for me to plug my light string (or anything) into.

To control the gate, I put a 5v voltage regulator (and capacitors) on a 9v transistor battery, with positive running through the detector on an optoisolator and then to the gate, and ground tying into my 110v DC ground. There is also a 100k 1/4watt pull down resistor from the gate to ground.

The emitter of my optoisolator is running the "fade" sketch off of a battery powered Arduino Uno.

I am very pleased with the results, and I have effectively faded LED strings and a 60watt incandescent bulb without any noticeable problems or heat generation. However I still have some questions.

1)I read some things I don't understand about how my 100k pulldown resistor may be effecting the PWM signal due to power dissipation or recovery time or something. Is there a better resistance or wattage for the circuit, and why?

2)By using separate batteries for my voltage regulator and Arduino, I believe I am getting the best isolation. However, this is not the most practical. In the future, I intend to use a transformer to step down a separate branch of AC to 12vac, then rectify it to 12vdc, so that my voltage regulator can take it to 5vdc, which is within the specs of my mosfet gate. This will all be on the detector side of the optoisolator, so it shouldn't affect the isolation between the 110v and the Arduino.

I would also like to run the Arduino off of the 110vac, but I want to know how that will effect my isolation.

If I plug a standard wall wart into the same 110vac source to power my Arduino, have I lost some or all of my isolation by sharing a common ground?

If not, could I instead just branch off some of that 12vdc from the transformer/rectifier setup before it goes to the 5v regulator and power my Arduino on that (given that I believe I have accounted for amp draw), or will that negate the purpose of the optoisolator?

The way I see it, the only way to get the Arduino completely isolated from that circuit is to have it on batteries, which I don't want to do (it'll be in a theatrical play for 6 weeks, and that's a lot of batteries). But is sharing a common ground acceptable?

Thanks everyone for your help!

-Jason

PS- I plan to do some pictures and a schematic when I have this completely solved and functional when I have some time, so other people can see what I've done, so any ideas to make this as safe as possible are welcome. I have a liquid, brush on insulation material that I plan to use on my 110v parts, save the mosfet's heat sink (which will be physically isolated from being touched).