Troubleshooting advice for basic transistor + pro mini setup

Hi all,

I could use some advice on how to approach troubleshooting my current project. In the end it will be a low-power pro mini sensor node, with among others a pn2222a transistor used to power the sensor on & off as the board goes in & out of sleep.

After several rounds of testing I got to a point where Serial doesn’t work on the pro mini anymore. I can still upload sketches using Arduino as ISP, so I uploaded the simple sketch below to test the boards digital pins (was planning to proceed with testing Serial afterwards).
The sketch sets pins 2-13 as outputs, and alternates writing high & low with a small delay.

The first time I ran the sketch I had the led blinking happily on pin 2, then on pin 3, but once I plugged the led into pin 4 (connected to the base of the transistor) everything went black. Since then I can’t get the led blinking on any pin - even after re-uploading the sketch (which still works fine)…

So… the problem is that I don’t know how to troubleshoot this. The resistance between the transistor’s emitter and pin 4 is 500 kOhms, which is the same as between pin 5 or pin 6 and ground.
Is there a simple way to test the transistor using just a multimeter?

The current schematic is this (the transistor collector is unconnected, I am just testing the pins starting with pin 2):
VMCTest_schem.png

The test sketch looks like this:

#include <Arduino.h>

void setup()
{
    for (uint8_t i = 2; i < A0; i++) {
        pinMode(i, OUTPUT);
        digitalWrite(i, LOW);
    }
}

void loop()
{
    for (uint8_t i = 2; i < A0; i++) {
        digitalWrite(i, HIGH);
    }
    delay(500);
    for (uint8_t i = 2; i < A0; i++) {
        digitalWrite(i, LOW);
    }
    
    delay(2000);
}

Thanks!
Franck

Corollary question: troubles started when I tried to test the transistor with a led connected - cathode to the collector and anode to 220ohms resistor to Vcc.

Is that a valid setup or did I miss something?

Thanks!

Can you still blink the LED on any pin without the transistor?

wvmarle: Can you still blink the LED on any pin without the transistor?

Nope, I unsoldered it and all digital pins sit at around 1V, no blinking whatsoever. The builtin led is dark as well, it should be blinking.

What is surprising is that I can still upload sketches using Arduino as ISP (but not using Serial), so the pins still work for SPI.

I don't mind switching to a new board, but I'd like to understand what happened so as not to end up in the same place :(

Franck

So I tested the transistor by itself on the breadboard, comparing to a good one, and it is definitely dead.

While doing that, I found that with a good transistor, simply approaching my hand from the insulated base wire was enough to dimly light up the led.

holding the pin between two fingers lights it brightly… so I have the feeling I am doing something wrong, but what?

Here is a picture, my finger touches the resistor leg and the led is brightly lit:

1-DSCN2350.JPG

The flat face of the pc2222a is facing away.

Franck

It sounds like you somehow blew up your Arduino, but I don't see how that happened. There are no red flags in what you said you did. I'd say if blink doesn't work, it's dead.

Then about your experiment: such a transistor has a gain of about 100 (or even more), so to drive 5 mA through your LED (more than enough for modern LEDs to "shine brightly") you have to sink 50 µA of current into your body. That is quite reasonable for a normal sized human (your body has a significant capacitance, and the charge is leaked out through moisture in the air), so you're not doing anything wrong there: this is expected behaviour. Now you also learned one way of introducing noise into your circuits, as it works the other way around just the same: you are an antenna for the 50 Hz (or 60 Hz) mains field that's all around you!

I don't know why the IDE still thinks it's successfully uploading the sketch.

Groumpf, optocouplers are looking more and more attractive :slight_smile:

I read 5 different transistor tutorials and I am having a really hard time picturing how this all works… but I am getting there, you had me worried until I realized that my circuit had the base floating, which won’t be the case when connected to the atmega pin driven LOW.

I find that the tutorials explain things in terms of quantities that we don’t know or care about for a common emitter switch (e.g. Ib or current gain or Rb).

So, what I know is:

  • when I switch on I will have Vbe = 3.3V
  • I want Ic < 10mA (to protect the pin)
  • I want to support Ic from 10uA up to 50mA

How do I use the equations to properly size the base resistance?

For Ic = 50mA I find

Ib = Ic / beta (75) = 0.66 mA

which is fine, and I will need

Rb = (Vb - 0.7) / Ib = 5K ohms

and 5K saturates my transistor with my led + 220ohms load, Ic is 3mA

Where I get lost is if I assume a much smaller load (sensor module), say 10uA. Then I will have

Ib = Ic / 75 = 0.13uA and
Vb = 0.7 + Ib * Rb = 0.7V + 650uV… but I expect Vb to be 3.3V??

Or is it that 0.7V is really Vbe at saturation and that I will have

Vbe = 3.3V - 650uV ?

Franck

I just took measurements with a 82K led load, and a 5K input resistor. What I find is that Vbe is still 0.7V; the base current Ib however is 550uA when Ic is 15uA.

So the transistor doesn’t work as a current amplifier at all anymore, quite the contrary. Is it ok? How do I know that for some loads Ib will not go over my 10mA limit?

Franck

Base current is limited by the resistor you put between the base and the Arduino pin, not by the collector-emitter current. ICE itself however is limited by Ib (and whatever is in the collector circuit). You can look at a BJT as if it were two diodes linked at either the anode (NPN) or cathode (PNP).
It is good practice to saturate the transistor - then you have a gain of 10-20, so for 15 mA that’d be a 0.75-1.5 mA current. For a 5V signal that means a 1k resistor will do great. This current limiting resistor is a requirement as without it you will probably blow up your transistor, the Arduino pin, or both.
Letting the base of a BJT transistor float won’t do any harm, there’s no current so it’s simply switched off - it’s purely current driven. This in contrast to MOSFET transistors, where leaving the gate float is a very bad idea, as they’re voltage driven.
Optocouplers are for connecting signals, not for driving LEDs.

wvmarle:
Base current is limited by the resistor you put between the base and the Arduino pin, not by the collector-emitter current. ICE itself however is limited by Ib (and whatever is in the collector circuit). You can look at a BJT as if it were two diodes linked at either the anode (NPN) or cathode (PNP).
It is good practice to saturate the transistor - then you have a gain of 10-20, so for 15 mA that’d be a 0.75-1.5 mA current. For a 5V signal that means a 1k resistor will do great. This current limiting resistor is a requirement as without it you will probably blow up your transistor, the Arduino pin, or both.
Letting the base of a BJT transistor float won’t do any harm, there’s no current so it’s simply switched off - it’s purely current driven. This in contrast to MOSFET transistors, where leaving the gate float is a very bad idea, as they’re voltage driven.
Optocouplers are for connecting signals, not for driving LEDs.

Thanks for the explanations! The term “gain” is what confused me, as well as the Ic = gain * Ib in all the tutorials as if Ic and Ib had a causal relationship… I was reading this as give me 0,5mA and I will give you back 50mA.

In fact it seems it’s more “give me 0.5mA on base and I will send them right to ground (through E), but for that price I can close a circuit of up to 50mA; and you’ll have to supply those 50mA yourself separately”.

In my measurements I always have Ib = 0.5 mA = (3.3V - 0.7V) / 5K, no matter what the load or what Ic happen to be (up to 3-4 mA)… so I find the tutorials confusing in that respect.

Franck

I still have a question, and I can't find the answer online: given a common emitter transistor used a switch, what happens when the load gets too high (i.e. increasingly smaller resistance) - i.e. when the collector current reaches the max gain of the transistor?

My base has a fixed voltage (3.3V) and a fixed base resistor (1.5K), so Ic will remain at 2.6V/1.5K, and since the gain isn't infinite something will have to give... so what happens?? Will the transistor get damaged?

Thanks! Franck

The current will never get bigger than what the transistor can pass through. That's how they're used as amplifier in radios etc - a very low resistance load and the transistor regulates the current.

In your case you have a base current of 1.7 mA, and based on the data sheet the transistor will be able to supply >200 mA (collector saturation until about 100 mA), the data sheet that I found is not too detailed about this.

wvmarle: The current will never get bigger than what the transistor can pass through. That's how they're used as amplifier in radios etc - a very low resistance load and the transistor regulates the current.

In your case you have a base current of 1.7 mA, and based on the data sheet the transistor will be able to supply >200 mA (collector saturation until about 100 mA), the data sheet that I found is not too detailed about this.

Cool, so if I understand correctly the transistor will not get damaged, and a load that tries to pull too much current will see a corresponding voltage drop?

Sounds perfect, thanks! Franck

Only if you stay within the limits of the transistor itself (current and power dissipation - for the pn2222a that's 600 mA and 625 mW respectively). With increasing voltage drop over the transistor the heat goes up accordingly! That's why you want to stay in saturation: the least voltage drop over the transistor, so the lowest power dissipation.

wvmarle: Only if you stay within the limits of the transistor itself (current and power dissipation - for the pn2222a that's 600 mA and 625 mW respectively). With increasing voltage drop over the transistor the heat goes up accordingly! That's why you want to stay in saturation: the least voltage drop over the transistor, so the lowest power dissipation.

Makes sense... thanks a lot for the guidance!

Franck