Change the Pwm frequency according to delay on time of the mosfet ?

prologikus:
Can you explain how i can do julian circuit working with my 3.2V?

Why do you need 3,3V when the Mega is going to output 5V anyway?

prologikus:
He said with that circuit you can control p channel mosfets too

Yes, but you're not following that circuit, are you?

Than again, it's massively over complicated.

R3 IS the load aka your bulb
Values of R1 and R2 are not strict.

wvmarle:
The schematic on the left is how you should wire the current limiting resistors.

But with a massive down side to it... If the input is floating both opto's are on which turns on both transistors (in the opto) aka shorting the supply through the opto burning the opto / making it nice and toasty.

wvmarle:
Where is the resistor in the path 3.3V - optocoupler - optocoupler - GND?

You need 3.3V - optocoupler - resistor - (link to IO pin without resistor) - optocoupler - resistor - GND.

But even when you have that, strange things may still happen when your Arduino switches on with pins in INPUT mode, and both optos are (partly) on.

The schematic on the left is how you should wire the current limiting resistors. The schematic on the right is a vastly improved version, only one optocoupler. Load is off when pin is LOW or INPUT.

This really make sense more then julian's circuit
But why he didn't use them?

septillion:
Why do you need 3,3V when the Mega is going to output 5V anyway?
Yes, but you're not following that circuit, are you?

Than again, it's massively over complicated.

R3 IS the load aka your bulb
Values of R1 and R2 are not strict.
But with a massive down side to it... If the input is floating both opto's are on which turns on both transistors (in the opto) aka shorting the supply through the opto burning the opto / making it nice and toasty.

My arduino works on 3.3v is not 5

Sorry but i didn't understand what it has to do with that circuit you mentioned

septillion:
If the input is floating both opto's are on which turns on both transistors (in the opto) aka shorting the supply through the opto burning the opto / making it nice and toasty.

Ah, you're right. Still not good :frowning: It was anyway an optocoupler too many, too complex. My second schematic is a much better way.

Or indeed your transistor switch solution, nice and simple, though I'm always worried I'm doing something wrong and link the 12V though the transistor to the Arduino pin.

wvmarle:
Ah, you're right. Still not good :frowning: It was anyway an optocoupler too many, too complex. My second schematic is a much better way.

Or indeed your transistor switch solution, nice and simple, though I'm always worried I'm doing something wrong and link the 12V though the transistor to the Arduino pin.

That 2.2k resistor means 5ma passive current drain
And my project is running on a car's battery with already some current drain

Soo... No passive

prologikus:
But why he didn't use them?

Because he uses leds to create extra forward voltage you just left out...

prologikus:
My arduino works on 3.3v is not 5

You have worlds only Mega that works on 3,3V? ::slight_smile:

prologikus:
Sorry but i didn't understand what it has to do with that circuit you mentioned

What about it? It's just a simple(r) circuit to do what you want. Alternatively you could use an opto instead of a transistor and get the right circuit of wvmarle.

@wvmarle, indeed to complex with two opto's. At these low speeds there is no advantage. And about connecting the 12V to the Arduino, just be careful and check connection twice. Even with an opto it will not stop you from connecting it wrong and blowing things up. But if it's connected correct using a transistor has no change of getting 12V on the Arduino.

prologikus:
That 2.2k resistor means 5ma passive current drain
And my project is running on a car's battery with already some current drain

Soo... No passive

That's winning the BS award of the day... As long as the Arduino pin is low it's not drawing any current. Which is infinity times better then Julian's circuit which draws current in ON and in OFF state. And when the pin is on it might draw 5mA but that's 0,15% of the current of the massive 40W bulb aka not a problem.

septillion:
That's winning the BS award of the day... As long as the Arduino pin is low it's not drawing any current. Which is infinity times better then Julian's circuit which draws current in ON and in OFF state. And when the pin is on it might draw 5mA but that's 0,15% of the current of the massive 40W bulb aka not a problem.

Hah, didn't realise
The gate doesn't consume current yes..
Sorry..

But i don't know how you don't know that the arduino mega can work on 3.3v..
I'm running it a year and everything works perfectly
In the datasheet of the chip(not the board) it aldo say that it works even on 1.8v

And about the forward voltage... It basicly reduce the voltage from 5 to 4.x and also the the current is used for both led and opto in my case is only used by opto, what's the difference?

It's so had that i don't have oscilo so i can see why my circuit doesn't for exactly why

Edit: What if i use this chip HCPL2531 ?
http://www.mouser.com/ds/2/149/HCPL2531-189259.pdf

prologikus:
But i don't know how you don't know that the arduino mega can work on 3.3v..

A Mega will probably run at 3,3V. But I also know that's just wayyyyy out of spec for the ATmega2560 and by no means is a default Arduino. So if you use something as exotic as that it would be useful to tell us beforehand.

prologikus:
In the datasheet of the chip(not the board) it aldo say that it works even on 1.8v

Where? Don't you confuse the ATmega2560V with the ATmega2560? That single letter makes a world of difference. :wink:

prologikus:
And about the forward voltage... It basicly reduce the voltage from 5 to 4.x and also the the current is used for both led and opto in my case is only used by opto, what's the difference?

What do you mean by "it". The extra leds in series make that the total forward voltage is 2 x (Vf,opto + Vf,led) ≈ 2 x (1,2V + 2,0V) = 6,4V which is above 5V (and 3,3V) thus the leds don't conduct. Just the opto's gives a forward voltage of 2 x Vf,opto ≈ 2 x 1,2V = 2,4V aka the leds will conduct very well at 3,3V.

prologikus:
It's so had that i don't have oscilo so i can see why my circuit doesn't for exactly why

Don't need a scope to see something static as this. Just a multimeter will do :wink:

All the source follower configurations in this thread will drop voltage across the MOSFET, thus dissipating power in it, and decrease the voltage to the load. That is not a good way to switch a load.

What's happened here is that DIY internet publishing has lowered really fine technology down to a level of designer/authors who have no clue how to really use it.

aarg:
All the source follower configurations in this thread will drop voltage across the MOSFET, thus dissipating power in it, and decrease the voltage to the load. That is not a good way to switch a load.

What's happened here is that DIY internet publishing has lowered really fine technology down to a level of designer/authors who have no clue how to really use it.

When internet is the only source of information i had no other option but to use it.
And i used arduino forum considering it's a good source of information.

Can you explain me a good way of switching my lights on at only a percent of it(a dynamic percent by arduino)

Edit: on high side!

ffs can someone please explain the stupidity of trying to PWM a DC incan

aarg:
All the source follower configurations in this thread will drop voltage across the MOSFET

You're right but the only source following circuit I see is from @wvmarle and because he is using a P-channel I think he just messed up and meant to flip the mosfet over the x-axis... So the word "all" is a bit much :stuck_out_tongue:

@prologikus, jeezz, yeah, go on and just ask again to another to see if somebody will give you an answer you like more ::slight_smile: If you want something that works, just use replay #20 or if you don't have a general purpose NPN and want to use an opto go for the right one in reply #19 but note G and S are switched by mistake.

And if you want to have something stable / in spec, put 5V back to your Mega :wink:

@INTP, I see no stupidity whatsoever in that... Normal AC dimmer does it as well although in sync with line frequency and phase cutting.

prologikus:
When internet is the only source of information i had no other option but to use it.

You misunderstand. I'm not saying don't use the internet. That would be insanely stupid. I'm saying go directly to information sources by learning to find them in the heap of junk that spews out of the DIY self help sites. For a simple example, you can download data sheets for MOSFETs and there are many good sites to learn about how they work. Don't scrape the bottom of the barrel for pearls of wisdom.

INTP:
ffs can someone please explain the stupidity of trying to PWM a DC incan

Perhaps you should explain the stupidity. I don't get it.

septillion:
You're right but the only source following circuit I see is from @wvmarle and because he is using a P-channel I think he just messed up and meant to flip the mosfet over the x-axis... So the word "all" is a bit much :stuck_out_tongue:

@prologikus, jeezz, yeah, go on and just ask again to another to see if somebody will give you an answer you like more ::slight_smile: If you want something that works, just use replay #20 or if you don't have a general purpose NPN and want to use an opto go for the right one in reply #19 but note G and S are switched by mistake.

And if you want to have something stable / in spec, put 5V back to your Mega :wink:

@INTP, I see no stupidity whatsoever in that... Normal AC dimmer does it as well although in sync with line frequency and phase cutting.

Thanks for the answers, everybody.

I think i'll use the npn circuit as you draw
Also, if it won't work or if the npn get hot, i'll buy a much faster dual photocoupler.

I also search( local shop) for a driver specialy foe high side but all i found is high side drivers using n channel mosfets.

The arduino is perfectly stable :d i give 3.2v via the 3.3v pin, as i said i run it for a lot of time with a lot of code and librarys and i never have a problem because if it

Edit: maybe, my octocouples are not able to give me enought instant(in time) current to the gate of the mosfet, do you know what i mean ?

aarg:
You misunderstand. I'm not saying don't use the internet. That would be insanely stupid. I'm saying go directly to information sources by learning to find them in the heap of junk that spews out of the DIY self help sites. For a simple example, you can download data sheets for MOSFETs and there are many good sites to learn about how they work. Don't scrape the bottom of the barrel for pearls of wisdom.

I only have a few months of experience in electronics and microcontrollers.
I look at electronics video this is the main source of information
Reading about them it's complicated not only because i don't know the language but because it doesn't always match with the practical thing...
This doesn't mean i don't read at all... But this high side switch hurts by brain...
I already fried 2 mosfets 2 npns and 2 drivers trying to do it

prologikus:
Also, if it won't work or if the npn get hot, i'll buy a much faster dual photocoupler.

If the NPN gets hot you didn't connect it as I said... Very normal/universal circuit which is done millions of times before. The NPN is only driving the gate of the mosfet. So buying a "dual photocoupler" will not fix anything if you don't connect it right :wink: And we're talking incandescent, so even 100Hz is moooore then fast enough to do the dimming.

prologikus:
I also search( local shop) for a driver specialy foe high side but all i found is high side drivers using n channel mosfets.

Noting wrong with that, as long as the driver does it right (and it probably will if it's designed for it :p) But a driver is nice if you need really fast switching with high currents. Switching a 40W incandescent is neither of that.

prologikus:
The arduino is perfectly stable :d i give 3.2v via the 3.3v pin, as i said i run it for a lot of time with a lot of code and librarys and i never have a problem because if it

You never having trouble with it is NOT the definition of stable. You're running it out of spec of the manufacturer so there is just no guarantee. Might only be unstable at extreme temperatures, voltage spikes, vibrations, bad batches or what not. But just don't come whining here if you experience random problems.

prologikus:
I only have a few months of experience in electronics and microcontrollers.

That explains your comment above... If you really need a 3,3V Mega, go and buy a ATmega2560V. But if you se it in an automotive application I don't really see a need for it.

septillion:
If the NPN gets hot you didn't connect it as I said... Very normal/universal circuit which is done millions of times before. The NPN is only driving the gate of the mosfet. So buying a "dual photocoupler" will not fix anything if you don't connect it right :wink: And we're talking incandescent, so even 100Hz is moooore then fast enough to do the dimming.
Noting wrong with that, as long as the driver does it right (and it probably will if it's designed for it :p) But a driver is nice if you need really fast switching with high currents. Switching a 40W incandescent is neither of that.
You never having trouble with it is NOT the definition of stable. You're running it out of spec of the manufacturer so there is just no guarantee. Might only be unstable at extreme temperatures, voltage spikes, vibrations, bad batches or what not. But just don't come whining here if you experience random problems.
That explains your comment above... If you really need a 3,3V Mega, go and buy a ATmega2560V. But if you se it in an automotive application I don't really see a need for it.

From the last post: Maybe, my octocouples are not able to give me enought instant(in time) current to the gate of the mosfet, do you know what i mean ?

And... If you look here

You can see that the minimum voltage is 1.8v

Tomorrow i'll do your circuit and report here what happend.

prologikus:
From the last post: Maybe, my octocouples are not able to give me enought instant(in time) current to the gate of the mosfet, do you know what i mean ?

I know, but at the default <1kHz that's all no problem.

prologikus:
And... If you look here
http://www.microchip.com/wwwproducts/en/ATmega2560
You can see that the minimum voltage is 1.8v

That talks about the whole range. Always use the datasheet. So if you do look a little further and open that and scroll to page 357 and 358 you can see that ONLY applies to the ATmega2560V :wink: it's for a reason the page you link to also says

The device achieves a throughput of 16 MIPS at 16 MHz and operates between 4.5-5.5 volts.

prologikus:
Tomorrow i'll do your circuit and report here what happend.

If you do it right, you'll end up with a dimmable bulb... If you do it wrong you might end with overheating components, magic smoke, death etc*

*Depending on how wrong you do it :stuck_out_tongue:

septillion:
I know, but at the default <1kHz that's all no problem.*

*Depending on how wrong you do it :stuck_out_tongue:

I was talking about the gate capacitance, the driver i fried had 1.5A peak to fill 1000 *f gate cap
Anyway...

About wiring, so far i fried about 5 arduino nanos and that make my check my circuit many times even with the multimeter to see if i do it good
This arduino mega is ~7 months old and it still have all the pins not fried.

It's pretty strange, i even run it at 3v and it worked... But i tought it's big difference from the 3.3v pin that i connected to it..

I did this because i wanted to reduce the power drain in awake mode. The difference between 5v current and 3.2v is pretty big so i stick to it..

Why does it have to be a high side driver?

Like I said, at <1kHz that's all not a problem. And like I said, with an incandescent there's not even a need to go higher then 100Hz...

For a test environment it's okay, if you really need a Mega because you have the need ridiculous amount of IO, grab a ATmega2560V for the final. Or if you have a more normal IO need, grab a 3,3V Pro Mini (or reflash a normal pro Mini to run at 8MHz internal).

aarg:
Why does it have to be a high side driver?

Quick guess, it's an excising bulb in a car which tend to be already connected to the chassis.