Another PWM mosfet light dimmer question/help?

Hi there,

i have recently been looking in to a project to be able to dimm a 6v 15watt light bulb pref using PWM as it seems more efficient than using other circuits. Anyway the light bulb shines really bright at about 5v 2-2.1Amps.

I have been looking at some circuits using mosfets however i dont know how to go about the PWM code. I have played around with analogwrite (varying a pot for the dimmer) and other simple codes but it feels as though its not switching fast enough to be a solid light that dimms rather than a blinking light which is whats happening so far.

component parts i have been using are the opto isolator 4n35 and IRF540 mosfet.

anyone shed some light and help me out. i assume its fairly easy to do i am fairly new to using PWM with the arduino.

cheers

but it feels as though its not switching fast enough to be a solid light that dimms rather than a blinking light which is whats happening so far

Arduino analogWrite switches at nearly 500Hz.
Can you post your code?

I did use the analogwrite from the examples that just reads/senses the pot and tested it With the opto and MOSFET first using an led as the output for now.

That just got it blinking at different speeds depending on the pot adjust. But it's not what I am after. I looked at the fade example which fades the led No probs like dims the brightness but it's automactic/specified in the code, I need it to act like the fade example but adjust with a pot. But then Instead of using an led on the output load, use the 6v 15watt @2A light bulb

If that makes sense.

I need it to act like the fade example but adjust with a pot.

Adjust what with a pot? Brightness? That's a single line of code with two function calls and a division. Rate of dimming? That's about five lines of code.

Yeah dimm the brightness with the pot on the analog input.

I was thinking if I can get an led to the brightness through the MOSFET then I could change it out for a light bulb providing I have a different power Supply for the current draw for the light bulb.

Would that assumption be correct?

No, that's not correct. In a light bulb a thin wire is heated up until it glows. Although for human eyes the start of the glowing seems fast, it isn't. Depending on the type of bulb you take you might get some dimming effect but never the same way you get it from an LED. An LED is almost immediately on when current is running. If you run it for shorter or longer periods the human eye has the illusion of a brighter or less bright light.

kh602: I was thinking if I can get an led to the brightness through the MOSFET then I could change it out for a light bulb providing I have a different power Supply for the current draw for the light bulb.

Would that assumption be correct?

Yes, that is correct. Incandescent bulbs work fine with PWM, and that's how DC bulbs are normally dimmed. It's often more important to use switching (PWM) with bulbs since they usually take more power than LEDs, and that makes linear dimming more "difficult" and inefficient. You might get a different brightness-curve (50% might not look the same as 50% on an LED).

If you have an AC powered lamp, dimming is very similar to PWM except the switching is synchronized with with the AC frequency (50 or 60 Hz) so you turn-on the lamp for part of each the AC half-cycle. And PWM doesn't work with TRIACs (used instead of MOSFETS for high-power AC switching), since they don't turn-off 'till the power is removed, or 'till the AC goes-through a zero-crossing.

P.S.

component parts i have been using are the opto isolator 4n35...

You probably don't need isolation. If there is high voltage (120 or 240VAC) you need isolation for safety. But if the bulb operates from slightly-higher voltage (6-24V, etc.), you don't need isolation. You just need to boost the voltage & current with a MOSFET (and a higher-voltage supply).

Dumb question: What kind of light bulb?

Can we see a picture or schematic? And your code, please.

I was told using dc nothing much would happen till after half the turn of the pot. Which is ok for now.

I want to use dc supply for the bulb as the AC variable supply is a tank 230v output 10v variable @5A AC. So I tested the bulb with a dc power supply and thought I could use that and save space a I don't Have much room at all to work with for the circuit board or a transformer.

I was using the analog write code to start off with and it only blinked the led slow or fast Rather than fade/dim the brightness.

I was basing it off this schematic (last one on the page) http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1270394559

I plan on using a 5 or 6v @3A dc power supply and having the arduino control the PWM using a pot and a MOSFET to supply to the light bulb.

I will try post pics later as I am at work at the moment.

Cheers guys

kh602: I was using the analog write code to start off with and it only blinked the led slow or fast Rather than fade/dim the brightness.

Hi,

You've mentioned this a couple of times. I don't see how it's at all possible if your sketch was correctly constructed. As has already been posted, analogWrite has a frequency of 490Hz (ref: http://arduino.cc/en/Reference/analogWrite) which is well above the frequency your eye can discern as flickering (You're reading this on a screen that likely only refreshes at 60Hz after all). Please post your sketch and hopefully we'll be able to make it work for you.

Cheers ! Geoff

i still cant get this to work. i have removed the optocoupler and just have a wire from pin 9 to the mosfet irf540 which
i have connect up and led for now.

i couldnt get the pot to dimm the led through the mosfet. is it possible to get it to work using the fade example but modify it so that
a pot controls the brightness rather than the fadevalue automatically incrementing?

then would i be able to apply this to the mosfet and use the light bulb. not really getting anywhere with this.

fade code

int ledPin = 9; // LED connected to digital pin 9

void setup() {
// nothing happens in setup
}

void loop() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}

pinMode(ledPin,OUTPUT);try that in setup()

Geoff

this i can help you on as im just finishing up the asym of my mosfet pwm sub board

cheers would definitely like some more ideas too. i will have to do more testing later on as its late. feel free to post any ideas that may help.

there is a few links out there that are similar but this one is the kind of route i was heading down http://arduino-info.wikispaces.com/ArduinoPower (right at the bottom section) and there is eagle schematics of that mosfet board http://yourduino.com/p/PowerFET-4Channel-800.png.

its just the coding i am lacking as i am out of practice and new to arduino platform

i have now have a logic mosfet irl540 which should work with the arduino.

i tested it with an led and it seems like its working.

now can someone explain when i tested my 6v 15watt light bulb on a big variable power supply and
set it to 5v DC and it took 2.1amps to run brightly it works fine. then i moved to a power supply rather
than a bench psu rated at 5v 4A it wont light up my bulb even though its the same settings on the bench top
power supply?