Confused about transistors! Optocouple / transistor motor control from arduino.

Discussion in 'General Electronics Chat' started by saasnpiy, Jul 19, 2012.

  1. saasnpiy

    Thread Starter New Member

    Oct 17, 2011
    6
    1
    I am trying to teach myself, and control a PC fan from an Arduino nano. The fan will be 12v and pull anywhere from 100mA to around 2 Amps. Looking around I have come up with this:

    http://i.imgur.com/9ugrK.png

    But I'm getting very confused, looking at data sheets, I don't understand.

    - I calculated the R1 value as ~190 Ohm, as 5v from nano - 1.2v drop across the opto LED / 20ma. Then I'm not sure from the datasheet what the current output will be from the optocoupler will be.

    - I'm not sure what the optocoupler protects against exactly? If the 12v/GND lines on the motor side are the same on the arduino side, will it protect anything?

    - I currently have a TIP41C or 2SD882 for the transistor, and the main thing is I'm getting lost trying to calculate what R2 should be, or if ether transistor is even suitable. I'm not sure what information from the datasheets I need to be looking at? Hfe?

    Thanks
     
  2. WBahn

    Moderator

    Mar 31, 2012
    17,751
    4,797
    Because the circuits on both sides of the optoisolator are electrically connected, the opto doesn't buy you much "protection", but it can still make the circuit easier to design and less variable in its operation. Let's first look at what you could do without it.

    The TIP41C is usable (haven't looked at the specs for the other). Here is the basic chain I would consider:

    You want to supply up to 2A of current to the fan. From the TIP41C datasheet, it would appear that the minimum beta (hFE) in this region of operation is 15. Since you want to be sure to turn this thing on hard, allow of a beta of only 10. This means that you need 200mA of base current.

    The maximum saturation voltage (Vcssat) is 1.5V, though this is at a collector current of 6A and a base current of 600mA. The maximum base-emitter voltage is 2V. Using these numbers (which should have plenty of margin in them), the power dissipated in the transistor is going to be 2A*1.5V + 200mA*2V = 3.4W. The maximum continuous dissipation at room temperature without a heatsink is 2W. So you may be able to get by without a heatsink if you don't expect to be pulling that kind of current very often for very long at a time, but it would probably be a good idea to put at least some kind of heatsink on there.

    To the the 200mA of base current, you could use a general purpose small signal transistor, such as the 2n3904 or 2n2222A, in the same place where you presently have the optocoupler. I would recommend moving R2 so that it goes from the 12V to the collector of the small signal transistor.

    For the collector resistor (R2), let's assume that you have that 2V base-emitter voltage for the final transistor and then about 400mV saturation voltage across the first transistor. So you have 2.4V across both and hence your voltage across R2 will be about 9.6V at 200mA. So something like a 47Ω resistor would work. The resistor would be dissipating about 2W. The first stage transistor would be dissipating about 100mW, which shouldn't be a problem.

    The base voltage of the first stage transistor could be as high as 2V (the Vbe of the output transistor) plus another about 800mV for the first stage. So you will have a drop of about 2.2V across R1 with about 20mA in it, making it about 100Ω.

    But now consider that the Vbe of the output transistor is more likely to be a bit less than 1V; let's call it 800mV, and let's assume that the input transistor might only be 700mV. So now you have 3.5V across R1 giving you 35mA. The circuit should still work fine, provided the Arduino's output can provide that much current. You would also have more collector current, but not by as great a margin, since you would have 10.8V across your 47Ω resistor giving you 230mA, which shouldn't present any particular problems for the circuit.

    Now, with the optoisolator, you don't have to deal with this large variability of the base-emitter voltage of the output transistor. You can size it the way you did and now you will have a pretty reliable 20mA draw from the Arduino. The output of the optoisolator can be does exactly as we did for the first stage transistor above, so a 100Ω resistor in the path (but now it doesn't matter whether its in the collector or the emitter side). But you do have to be sure that the optoisolator can handle at least 250mA of collector current (and that 20mA of LED current is sufficient to saturate the output at collector currents less than 250mA).




    are the
     
  3. saasnpiy

    Thread Starter New Member

    Oct 17, 2011
    6
    1
    Thanks for the big reply! I will have a read through it and see if I can figure it out!
     
  4. saasnpiy

    Thread Starter New Member

    Oct 17, 2011
    6
    1
    Again thanks for the big reply, it helped a lot and I think I am getting a better grip on reading and understanding the transistor datasheets etc. I made a ambilight type thing to drive an RGB LED stip I had lying around, using the 2SD882's, and all went well.

    Questions about the fan control,

    -Is there an easy way to split my single 12v feed into two separate feeds, one for the micro and one for the fan so I can use the optocoupler to actually protect the micro? Do I just need a voltage regulator for the micro side? How about the shared ground?

    -Everyone I see controlling fans from micros seems to use PWM. Is it possible to change the fan speed with an analog output pin via the transistor? What would be the disadvantage of this vs PWM apart from low torque? Thanks again.
     
  5. saasnpiy

    Thread Starter New Member

    Oct 17, 2011
    6
    1
    I hooked a fan to the Arduino via one of the 2SD882 transistors, and it powers the small fan fine. The issue was I was getting garbage out the tachometer signal wire. It seems you cannot control a PC fan with PWM and still get usable RPM speed data, so I think I will have to drive it with a true analog signal.
     
  6. radiohead

    Active Member

    May 28, 2009
    474
    31
    Instead of having the arduino turn on an inductive load like a fan motor, have the arduino trip a relay and run the fan from the relay that can handle a larger load.
     
  7. saasnpiy

    Thread Starter New Member

    Oct 17, 2011
    6
    1
    I assume mechanical relays would wear out, and probably can't even use them with PWM? And isn't a solid state relay an opto-coupler and transistor anyway?

    To overcome the tachometer signal being garbage, I have found a workaround:
    I occasionally manually read the RPM (rather than using interrupts). Because the RPM pulse output on the fan works when it's getting steady power, I hold the output high, and count the length of one full pulse, then go back PWM. This doesn't change the speed of the fan noticeably, and is accurate enough for my needs.

    Also if you can afford to wait a while for the pulse, and you read the RPM frequently enough, it has the advantage that you will never have a stalled fan, eg if the duty is too low to start the fan, when you try to read the speed, it will send full power to the fan, and wait for the fan to turn and produce the pulse.
     
  8. radiohead

    Active Member

    May 28, 2009
    474
    31
    Relays do wear out after a decade or two. And no, a relay it totally different from an opto-coupler and transistor. A typical transistor (2N3904 or equivalent) can handle a load up to 200mA. A relay can handle from 10A (10,000mA) up to 40A (40,000mA) or more. Quite a difference. The relay will switch a circuit (the fan circuit) on or off. A transistor will allow you to somewhat control the speed with regards to how much base bias is applied.

    Try using the analog output to control the fan instead of the digital output. The results will probably be better.

    How much time do you have between PWM pulses? Can you post your code?
     
  9. crutschow

    Expert

    Mar 14, 2008
    13,018
    3,235
    If you use a single supply, then you require a common ground and thus an optocoupler cannot be used for complete ground isolation. The ground current for the motor should have a separate return to the 12V from the micro however, so that the high motor currents don't inject noise into the micro ground.

    If you have a noise problem between the micro and the motor control circuit then an optocoupler can help with that since its output signal common can be referenced to the motor control circuit common, independent of the micro common.
     
  10. saasnpiy

    Thread Starter New Member

    Oct 17, 2011
    6
    1
    crutschow; Thanks, yeah I have left the opto out of the circuit now as there is just the one 12v power source, it seems there is no noise, it's working OK. When you say separate return ground, do you mean a seperate PCB trace / wire? It will still be electrically connected to the micro ground though yeah?

    radiohead; Yes I understand how a mechanical relay works, and I'm pretty sure I was correct when I said ~solid state~ relays are an optocoupler with a (MOSFET) transistor(s).
    I didn't really say it previously, but I need to control the speed of the fan not just turn it on or off.
    Using the arduino's default PWM frequency of 488Hz made the fans noisy, so for now I cranked it right up to 62.5Khz. At this speed, not that it could ever switch that fast, a mechanical relay with a 10 million cycle life, would die in just over 2 and a half miuntes :)

    I was thinking I might need to use a true analog output to get the tachometer output working, but that would be more parts, more complexity etc, and PWM seems to be working good with that workaround.

    Basic code would be like:

    Main()
    {

    ...

    Read_RPM();
    analogWrite(FanPin,Speed);

    ...

    }


    Read_RPM()
    {
    Set_PWM(FanPin,255);
    PulseDuration = pulseIn(FanPin, HIGH);
    RPM = (1000000 / PulseDuration )*60 / 4;
    }


    I can control RPM quite accuratly like this (better accuracy the faster the fan is spinning as is spends less time sitting with the pin HIGH waiting for the pulse)
     
    WireNut likes this.
  11. crutschow

    Expert

    Mar 14, 2008
    13,018
    3,235
    Yes, I mean separate wires or traces, one for the motor driver and one for the micro, both connected to the supply common.
     
Loading...