Hey guys, I am running a mosfet power circuit to turn some loads on/off and I'm using a resistor soldered in the circuit to sink the gate voltage, but I'd like to use my Arduino to control the mosfet and I want the gate to stay energized when I reset the arduino. Sometimes I need to reset it a few times a day, and I can't be having the devices go on/off like that...
What's the easiest way of going about this? I thought that when you set a pin to LOW, that it effectively turns it in to a ground? From my testing I see that it just turns the pin off. Would be nice if I could control the mosfet's some way in the code, like HIGH/LOW...
Any thoughts?
Thanks!
I had thought about using a capacitor on each mosfet, that way it would take longer for the pin to sink through the resistor while the Arduino is resetting?
I want the gates to stay in their current condition. If they are getting 5v from the arduino, and I reset the arduino, I want them to stay on... If they are off, they should stay off. Get what I mean? It's lighting in my terrarium and if the lights are on when I reset the arduino I don't want the mosfets going off... Which is why I was thinking it would be great if I could use the same arduino pins to send 5v to the mosfets and then when it's time, turn the mosfets off by sinking the voltage. There should be no more current going to the mosfets than the arduino can send out of it's pins. Each mosfet has it's own arduino pin, too...
CrossRoads, no I set the pinMode to INPUT... I'll do it as OUTPUT and try it. The Arduino can only send 40mA anyway, so it shouldn't have a problem sinking it's own current, right? If need be, couldn't I put an resistor between the pin and it's mosfet to help reduce the current more?
Yeah, I think put a cap on the MOSFET gate.
After your sketch starts, read the state of the pin, and then set the pin to an output and drive it at the same level.
How long of a power outage do you expect?
However long it takes for the Arduino to reset when you push the reset button... So like, 2 seconds? I wasn't going to read the state of the pin, since the timing is control by an RTC... So when the sketch starts, if it's during the time for the lights to be on then that pin will return to 5V status, but the gates will still be energized & open anyway, if the lights are supposed to be off, then the gates would be closed and the arduino pin won't be sending voltage.
That's just the thought I came up with knowing that the mosfet gate takes no current, so the gate will stay energized until something external sinks the voltage... I don't see why the Arduino would have a problem sinking it's own current though. When I get home from work later I am going to take one of my spare Uno boards and just try it. I'd prefer to not have to get in to adding more resistors/cap @ this point in time.
OP, please change your title to sink a CURRENT. You can't sink a voltage. Good discussion by the way. I'm sure others can benefit from reading this so a correct title gets good search hits.
FlyingSteve:
Hey guys, I am running a mosfet power circuit to turn some loads on/off and I'm using a resistor soldered in the circuit to sink the gate voltage, but I'd like to use my Arduino to control the mosfet and I want the gate to stay energized when I reset the arduino. Sometimes I need to reset it a few times a day, and I can't be having the devices go on/off like that...
What's the easiest way of going about this? I thought that when you set a pin to LOW, that it effectively turns it in to a ground? From my testing I see that it just turns the pin off. Would be nice if I could control the mosfet's some way in the code, like HIGH/LOW...
Just remove the resistor to ground - A MOSFET gate is quite a substantial capacitance and the pins should be configured as INPUTs during the reset cycle I believe.
Its not necessarily the best way to achieve the effect, its a kludge. Why are you having to reset BTW?
Any thoughts?
Thanks!
I had thought about using a capacitor on each mosfet, that way it would take longer for the pin to sink through the resistor while the Arduino is resetting?
MarkT, could you please be a little more clear... Not that I'm stupid lol, but your "I believe" statement is confusing me
I'm having to reset because the Arduino also does temperature control via PID algorithm, and sometimes when I open the door it screws the PID up and it way overshoots and then goes into an oscillation that takes a little bit of time to self-correct... So I will manually reset to help avoid that. I am adding in other components to freeze the integral on the PID & include a freeze-time so it won't do that anymore, but in either case if I should need to reset the arduino for whatever reason (Remember, this is for prototyping after-all) I don't want the lights to be going nuts.
FlyingSteve:
I'm having to reset because the Arduino also does temperature control via PID algorithm, and sometimes when I open the door it screws the PID up and it way overshoots and then goes into an oscillation that takes a little bit of time to self-correct... So I will manually reset to help avoid that.
Rather than deliberately crashing the Arduino and trying to minimise the effects of that, I suggest you start by trying to correct the PID parameters. If it's oscillating, perhaps you don't have the derivative feedback set high enough. If you really can't sort that out then you could simply clip the control signal to around the normal steady-state condition so that it doesn't have as much authority to induce these transient overshoots. And if you can't even do that then fit a 'reset' switch which leaves the Arduino running but just tells you sketch to restart the PID algorithm.
Trying to come up with clever drivers that will hide the Arduino reset feels like a solution to the wrong problem.
FlyingSteve:
I'm having to reset because the Arduino also does temperature control via PID algorithm, and sometimes when I open the door it screws the PID up and it way overshoots and then goes into an oscillation that takes a little bit of time to self-correct... So I will manually reset to help avoid that.
Rather than deliberately crashing the Arduino and trying to minimise the effects of that, I suggest you start by trying to correct the PID parameters. If it's oscillating, perhaps you don't have the derivative feedback set high enough. If you really can't sort that out then you could simply clip the control signal to around the normal steady-state condition so that it doesn't have as much authority to induce these transient overshoots. And if you can't even do that then fit a 'reset' switch which leaves the Arduino running but just tells you sketch to restart the PID algorithm.
Trying to come up with clever drivers that will hide the Arduino reset feels like a solution to the wrong problem.
The oscillation happens when you open the door and all the inside air comes out...The input temperature changes, the PID responds. The PID needs to know that the door is open and not to freak out. Enter the microswitch on the door. Door opens, microswitch tells arduino that the door is open and to freeze the integral until the switch is depressed again... Once the door closes then a 5min freeze on the integral starts.
I can't hook the switch up until my Mega board shows up tomorrow... I'm already out of pins on this Uno board and I still have a lot more to hook up.
FlyingSteve:
I can't hook the switch up until my Mega board shows up tomorrow... I'm already out of pins on this Uno board and I still have a lot more to hook up.
Again, I guess you don't want any of us to ask what else you have hooked up to the UNO or attempt to help you optimize the hookup and reduce pins used either. Just I/O pin sink current is asked so only answers to that is needed?!
FlyingSteve:
The oscillation happens when you open the door and all the inside air comes out...The input temperature changes, the PID responds. The PID needs to know that the door is open and not to freak out. Enter the microswitch on the door. Door opens, microswitch tells arduino that the door is open and to freeze the integral until the switch is depressed again... Once the door closes then a 5min freeze on the integral starts.
Hope I'm not screwing you up on this but I find that as good as microswitches are, a latch-type Hall sensor and cheap magnet as used in security apps is far nicer and last for a larger chunk of forever. You don't need parts to make physical contact and wear out or dirt-up, the internals are solid state and the switching action is clean. However it's not good to mount the magnet directly on a steel door or frame, they do make mounting bits just to handle that.
Hall sensors are to microswitches like transistors are to tubes.
FlyingSteve:
I can't hook the switch up until my Mega board shows up tomorrow... I'm already out of pins on this Uno board and I still have a lot more to hook up.
Again, I guess you don't want any of us to ask what else you have hooked up to the UNO or attempt to help you optimize the hookup and reduce pins used either. Just I/O pin sink current is asked so only answers to that is needed?!
Bingo. Thanks.
GoForSmoke:
FlyingSteve:
The oscillation happens when you open the door and all the inside air comes out...The input temperature changes, the PID responds. The PID needs to know that the door is open and not to freak out. Enter the microswitch on the door. Door opens, microswitch tells arduino that the door is open and to freeze the integral until the switch is depressed again... Once the door closes then a 5min freeze on the integral starts.
Hope I'm not screwing you up on this but I find that as good as microswitches are, a latch-type Hall sensor and cheap magnet as used in security apps is far nicer and last for a larger chunk of forever. You don't need parts to make physical contact and wear out or dirt-up, the internals are solid state and the switching action is clean. However it's not good to mount the magnet directly on a steel door or frame, they do make mounting bits just to handle that.
Hall sensors are to microswitches like transistors are to tubes.
I know what you're talking about... You see them on doors/windows. That's a good idea and I'll definitely keep it in mind for my next prototype. I have micro-switches from work and I have other tiny dead-man switches laying around... But I want things to be as trouble free for my hopefully future customers and a latch-type Hall sensor would be good.