Saturday 7 November 2015

What are the different ways to switch power using a microcontroller (Arduino, Raspberry Pi, BeagleBone, etc.) and what are the pros/cons for each?


I'm using an Arduino to control a 12v water pump for a self-watering plant wall. I'd also like to use the same power supply for both, and probably need surge protection of some kind to avoid spikes. I would like to understand the pros and cons in general of various methods of switching power.


I've come across various methods of switch power on and off, but have little idea of the pros/cons for each. Here's the ones I know about:




  • Use a transistor (usually a MOSFET) to switch power.

  • Use an opticoupler to toggle power.

  • Use a relay to control power output. The microcontroller usually doesn't have sufficient power to switch the relay. So you end up having to have an additional circuit which controls power to trigger the relay. This seems silly.


To me, it looks like an opticoupler would be the best option. There's no heat buildup from a transistor (I think), and there's no need to use power to trigger switching the power as in a relay. However, it's not the most common way of switching, and I don't understand why.


If this question is too vague, please do flag it, but also help me make it more concise. I might not know the terminology to ask a good question.



Answer



In your case, using a relay to switch the motor is probably the simplest approach. The switching could be done with a FET, but you have to know more about what you're doing and it's not as forgiving.


You are right in that you can't just drive a relay straight from a microcontroller. However, that is still simple to do:




The digital output turns on the transistor, which then turns on the relay. Size R1 to make sure the transistor is saturated when on. Let's say it takes 50 mA to energize the relay, and that the transistor can be counted on to have a gain of at least 50. That means you need a minimum of 1 mA base current. If the digital output goes to 5 V when high, and the B-E drop is 700 mV, then there will be 4.3 V across R1. (4.3 V)/(1 mA) = 4.3 kΩ, which is the largest allowed base resistor. 3 kΩ therefore sounds like a nice value that provides some margin over the minimum required base drive, but would not load a normal digital output. (4.3 V)/(3 kΩ) = 1.4 mA, which just about any digital output can source.


Power connections


I see from the comments that there is some confusion about how all this is powered. The original question was about how to control a 12 V water pump, so 12 V is obviously available. This is also used to power the relay in the circuit above.


The microcontroller probably requires either 5 or 3.3 V. That could be done with a linear regulator from the 12 V, but a buck converter would be better. At these low voltages and probably only a few 100 mA of current, there are plenty of available and cheap options. You can probably find a buck chip with integrated switch and synchronous rectifier, probably even fixed-voltage versions for the 5 or 3.3 V for the micro. All you add is the inductor and some caps, possibly a bootstrap diode, and maybe two resistors to set the output voltage.


A buck converter will waste less power. That may be useful on its own, but the real advantage is in not having to deal with the heat generated by a linear regulator. For example, if the micro and everything around it takes 200 mA, then a linear regulator will dissipate 1.4 W. That's more than a TO-220 package can safely dissipate just in free air. Even a 85% efficient buck regulator would only dissipate 180 mW, which is no problem for something like a SO-8 package the buck probably comes in.


No separate power supplies are needed. Everything can run off the 12 V that is already available. A microcontroller and a relay are a small load compared to a water pump, so this represents only a small additional burden on the 12 V supply.


The real issue is not the supplies but the grounds. In the scenario above, there is only one ground. The ground shown in the schematic above must be the same as the microcontroller ground. Since the pump is running from the same 12 V supply as the relay, the pump must also be connected to this ground.


However, you do have to pay attention to where the return currents flow, particularly those of the pump. The pump should have its own separate ground wire back to the power supply so that the offset voltage generated by its return current times the ground connection impedance doesn't add offset to the micro's ground.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...