1
\$\begingroup\$

I have ATMEGA328 (running on 5V) connected to a C4793 NPN transistor which controls the TEC1-12706 thermal component.

I'm using the code below to turn the transistor on and off:

#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>

void delayms( uint16_t millis ) 
{
    while ( millis ) 
    {
        _delay_ms( 1 );
        millis--;
    }
}

int main( void ) 
{
    DDRD = 0b00000001; 

    while ( 1 ) 
    {
        PORTD = 0b00000001; 
        delayms( 10000 );

        PORTD = 0b00000000;
        delayms( 10000 );       
    }

    return 0; 
}

schematic

simulate this circuit – Schematic created using CircuitLab

Everything is working great, except that the thermal module only gets 0.6A of current, even though the datasheet of the C4793 transistor states that it can handle 1A of current.

If I connect the base of the transistor directly to the VCC, I get 1.07A to the thermal module, which is exactly what I need.

I can't understand why I only get 0.6A when doing the same thing from the ATMEGA328. I thought maybe it's because ATMEGA328 puts out only 20mA from the PIN, but isn't the transistor triggered by the voltage instead of current? Any suggestions please? Thanks!

\$\endgroup\$
9
  • 2
    \$\begingroup\$ Please provide a schematic to show how you have connected things together. There is a built-in schematic editor you can use to add the schematic to your question. \$\endgroup\$ Feb 7, 2019 at 12:56
  • 1
    \$\begingroup\$ Just label a wire to show that it is the signal from the microcontroller, but be sure to also show us how all of the grounds are connected together. \$\endgroup\$ Feb 7, 2019 at 13:04
  • 3
    \$\begingroup\$ You need a resistor from uC to base of transistor, or the uC pin will be toast. Minimum value of resistor in ohms = (5.0-0.7)/0.02 \$\endgroup\$
    – Indraneel
    Feb 7, 2019 at 13:46
  • 1
    \$\begingroup\$ "If I connect the base of the transistor directly to the VCC ..." - That's a good way to destroy a transistor! (most BTJs are not rated for high base currents) \$\endgroup\$
    – marcelm
    Feb 7, 2019 at 15:08
  • 2
    \$\begingroup\$ Your schematic makes little sense. Are you sure your voltage source is the right way around? \$\endgroup\$
    – Hearth
    Feb 7, 2019 at 15:31

2 Answers 2

5
\$\begingroup\$

You are using a NPN transistor for high side switching. This means the bjt will never turn on fully. Voltage at base needs to be about 0.7 V more than voltage at emitter for NPN to turn on fully.

Here's the circuit with low side switching (transistor connected to ground, instead of +ve rail):

schematic

simulate this circuit – Schematic created using CircuitLab

Additionally, I do not recommend running the uC pin at full current it is capable of. So minimum resistor should be (5.0-0.7)/0.02 = 220 ohms. But 330 ohms is better. Typically, 1K is used. Which means, for an optimal design, you need a transistor with higher gain. You can do this yourself by putting 2 transistors in a darlington configuration.

schematic

simulate this circuit

You can replace the transistors with a single logic level mosfet. A cheap and (somewhat) commonly available one that will work here is AO3400.

NOTE that your load no more has a common ground with the rest of your circuit. If this is a problem, you will have to use high side switching. However, this will require PNP BJT or P-channel mosfets. It will also invert the switch on/off logic. If the load operates at more than 5V, it will also mean an additional NPN switch for the PNP switch.

Alternately, in the first schematic, 2SC4793 can be replaced with the TIP122, which is a complete darlington pair transistor in a TO220 package... quite cheap and common, has great characteristics, and finds many uses in the lab and for projects.

In the second schematic, one can replace the specialized, hard to find and expensive 2SC4793 with the very cheap and common BD139 which has both higher gain and higher current capability. [2SC4793 has a Vceo of 230V, so better to keep it for special uses, since it is expensive.]

\$\endgroup\$
3
  • \$\begingroup\$ Thank you very much for your answer! To confirm I understood correctly the reason I would use 2N3904 is because that way I would be getting the current from the power source directly instead of getting it from the microcontroller and therefor I would get all of the amount of current required to turn on the C4793 fully correct? \$\endgroup\$
    – Kristian
    Feb 7, 2019 at 14:26
  • \$\begingroup\$ @Kristian yes, that is correct. The small current from uC is amplified by 2N3904. Since this is about 20-30 mA, the gain can be quite high (about 200). So much less than 1 mA comes from uC. The 30 mA from 2N3904 is enough to allow almost 1 A to flow through C4793 at a gain of about 30 (which is almost at its limit at 1 A, so not recommended. A better transistor would be BD139). The voltage at base of 2N3904 is now 2x0.7 V when it is on (2 diode drops, one for each transistor). So max base current for 2N3904 can be (5-(0.7*2))/1000 = 3.6 mA (with the 1K resistor). \$\endgroup\$
    – Indraneel
    Feb 7, 2019 at 15:49
  • 1
    \$\begingroup\$ @Indraneel: You tell the OP that they're using high-side switching, but don't explain that you're showing low-side switching. Maybe edit your answer a bit? Maybe insert a second sentence that says something like "Here I show how to do the job using low-side switching, which makes better use of the transistor." \$\endgroup\$
    – TimWescott
    Feb 7, 2019 at 15:57
0
\$\begingroup\$

The answer from Indraneel is sort of correct, but a few more comments are in order:

Connecting the transistor as a high-side switch, as you did in your original schematic, is actually valid, provided you consider the implications. You have been told about the 0.7V drop from base to emitter, so your load will see a voltage that is 0.7V less than the voltage at the output pin of the microcontroller. If that's OK, you can use this kind of circuit.

Another consideration is the current gain of the transistor at this operating point. You can consult its data sheet to find this out. In case of the C4793 (actually 2SC4793), you will find that at very low collector-to-emitter voltages the current gain drops significantly. This means that the transistor needs correspondingly more base current, which has to come from the output pin of the controller. This typically makes its output voltage drop, hence the voltage at the emitter will also drop. See the controller data sheet for valid current values. This may well have been a significant effect in your case. If you want to use a single transistor, you need to select one that has sufficient current gain at the operating point you are interested in.

If you can't get enough current gain from one transistor, you need to come up with a different circuit, for example one that uses two transistors. You have been shown how.

\$\endgroup\$
1
  • \$\begingroup\$ The 2SC4793 is unsuitable for this application on many counts. Price would be top of my list. This has a Vceo of 230V, which is why it is expensive, and performs poorly at low voltages. The TIP122 darlington would be the best choice, and is also quite cheap, and useful all around. That is, if one does not have those smd mosfets (like the AO3400 or IRLML2502). \$\endgroup\$
    – Indraneel
    Feb 8, 2019 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.