ChiefRunningPhist
Well-Known Member
Relays are great and offer physical isolation due to their mechanical operation, but if you don't need isolation, just need a switch, then MOSFETs are real nice and easy components to work with, they are smaller and cheaper than relays and can switch at very fast speeds, like 1MHz+, or on & off at 1 million times a second.
They can be rated up to 600V and higher, though mostly are 200V or less for power MOSFETs (bigger beefier switches), and 60V or less for LL MOSFETs (LL = logic level). They require much less power to operate (LL = 5V or less but microamps, or millionths of an amp, power FETs typically need 10V - 18V to work but again at only millionths of an amp, so total power is very low). This allows for you to PWM or control loads that require more power than the esp can produce at each of its GPIO pins.
A GPIO might be able to power an LED or 2, but much more and you're not going to have enough power. So you'd wire your load or LEDs in series with a bigger PS, like a battery ect, and then also wire the MOSFET in series. This way when the MOSFET is on, the cct flows current through the load/LED, but when the MOSFET is off the cct is broken and can't complete so the load/LEDs aren't energized and off. By varying how many times you turn the MOSFET on in a second, as well as how long you turn it on per switching cycle (1 on/off event) you can very how much current is flowed on average. Increasing your PWM duty cycle to be ON for longer than its OFF will make more current flow, and by reducing duty cycle so that your MOSFET is OFF for longer than its ON will reduce current flow, or dim. The quicker you switch, or the more on/off events per second, then the less noticeable the switching is. If you turned an led on for half a second, and then off for half a second, you'd see a strobe rather than a smoothly dimmed light, but if you switched many times in a second you'll see less strobe and more of a smoothly dimmed light. PWM is not just for lights but for anything requiring a dimming transition, like motors ect. You can trigger MOSFETs with your arduino without a shield and your MOSFETs can then be the gatekeeper for your other devices getting power or not or dimming them via PWM ect.
Just like relays, MOSFETs come in all sizes and electrical parameters, so you'll want to shop for FETs that can handle the voltage and current of your cct. N channel MOSFETs are placed after your cct, or close to ground or negative, and P channel MOSFETs are placed before your cct or close to positive. There's all sorts of FETs, some that are initially on (depletion) some that require voltage to turn on (enhancement). P channel MOSFETs have greater resistance when they are switched on and allowing current to flow, so they are less used over their cousin the N - channel MOSFET which has very low resistance when it's on and allowing current to flow.
Armed with a bit of code and utilizing MOSFETs or other switches, you can turn on/off several devices that require more power than the esp can produce. You can dim as well with the PWM function. Imo pretty much all the grow room stuff can be controlled by on/off or PWM (fan speed ect).
Here's a quick schem/graphic showing a MOSFET in series with a seperate power source and a single LED. The MC or microcontroller (esp), and the peripheral cct both share the same ground. The MC GPIO pin is attached to the gate of the MOSFET and in this particular example once a small voltage is sent to the gate the MOSFET turns on and allows current to flow from the batteries, then through the LED, then through the MOSFET, and then to the negative side of the batteries, or GND (ground).
EDIT:
Its a good idea to use some resistance, ie a resistor, in series with LEDs in case your cct isn't current regulated. So in this example I'd want to add a resistor somewhere in the loop because its a voltage source. Voltage source means the voltage is the fixed variable while as much current can flow as the cct will allow, a Current source means current is the fixed variable and voltage will adjust automatically to whatever is needed to flow the fixed current of the current source.
They can be rated up to 600V and higher, though mostly are 200V or less for power MOSFETs (bigger beefier switches), and 60V or less for LL MOSFETs (LL = logic level). They require much less power to operate (LL = 5V or less but microamps, or millionths of an amp, power FETs typically need 10V - 18V to work but again at only millionths of an amp, so total power is very low). This allows for you to PWM or control loads that require more power than the esp can produce at each of its GPIO pins.
A GPIO might be able to power an LED or 2, but much more and you're not going to have enough power. So you'd wire your load or LEDs in series with a bigger PS, like a battery ect, and then also wire the MOSFET in series. This way when the MOSFET is on, the cct flows current through the load/LED, but when the MOSFET is off the cct is broken and can't complete so the load/LEDs aren't energized and off. By varying how many times you turn the MOSFET on in a second, as well as how long you turn it on per switching cycle (1 on/off event) you can very how much current is flowed on average. Increasing your PWM duty cycle to be ON for longer than its OFF will make more current flow, and by reducing duty cycle so that your MOSFET is OFF for longer than its ON will reduce current flow, or dim. The quicker you switch, or the more on/off events per second, then the less noticeable the switching is. If you turned an led on for half a second, and then off for half a second, you'd see a strobe rather than a smoothly dimmed light, but if you switched many times in a second you'll see less strobe and more of a smoothly dimmed light. PWM is not just for lights but for anything requiring a dimming transition, like motors ect. You can trigger MOSFETs with your arduino without a shield and your MOSFETs can then be the gatekeeper for your other devices getting power or not or dimming them via PWM ect.
Just like relays, MOSFETs come in all sizes and electrical parameters, so you'll want to shop for FETs that can handle the voltage and current of your cct. N channel MOSFETs are placed after your cct, or close to ground or negative, and P channel MOSFETs are placed before your cct or close to positive. There's all sorts of FETs, some that are initially on (depletion) some that require voltage to turn on (enhancement). P channel MOSFETs have greater resistance when they are switched on and allowing current to flow, so they are less used over their cousin the N - channel MOSFET which has very low resistance when it's on and allowing current to flow.
Armed with a bit of code and utilizing MOSFETs or other switches, you can turn on/off several devices that require more power than the esp can produce. You can dim as well with the PWM function. Imo pretty much all the grow room stuff can be controlled by on/off or PWM (fan speed ect).
Here's a quick schem/graphic showing a MOSFET in series with a seperate power source and a single LED. The MC or microcontroller (esp), and the peripheral cct both share the same ground. The MC GPIO pin is attached to the gate of the MOSFET and in this particular example once a small voltage is sent to the gate the MOSFET turns on and allows current to flow from the batteries, then through the LED, then through the MOSFET, and then to the negative side of the batteries, or GND (ground).
EDIT:
Its a good idea to use some resistance, ie a resistor, in series with LEDs in case your cct isn't current regulated. So in this example I'd want to add a resistor somewhere in the loop because its a voltage source. Voltage source means the voltage is the fixed variable while as much current can flow as the cct will allow, a Current source means current is the fixed variable and voltage will adjust automatically to whatever is needed to flow the fixed current of the current source.
Last edited: