# Transistor 2N2222A wont accept base input from arduino

I'm New in electronics. I read "Robot Building for Beginners" book and I'm trying to make a line follower circuit. Instead of LM393 and 2N2907A I'm using arduino nano and 2N2222A. Here's my code:

const int leftPin = 9;
const int rightPin = 2;

int leftSensor;
int rightSensor;

bool switchLine = HIGH;

void setup() {
pinMode(11, INPUT_PULLUP);

pinMode(rightPin,OUTPUT);
pinMode(leftPin,OUTPUT);
digitalWrite(rightPin,LOW);
digitalWrite(leftPin,LOW);
}

void loop() {

if(leftSensor > rightSensor)
{
if(switchLine)
{
digitalWrite(rightPin,LOW);
digitalWrite(leftPin,HIGH);
}
else
{
digitalWrite(rightPin,HIGH);
digitalWrite(leftPin,LOW);
};
}

if(leftSensor < rightSensor)
{
if(switchLine)
{
digitalWrite(rightPin,HIGH);
digitalWrite(leftPin,LOW);
}
else
{
digitalWrite(rightPin,LOW);
digitalWrite(leftPin,HIGH);
};
}
delay(20);
}


And here's my circuit (I did not draw other parts of the circuit because they work fine):

simulate this circuit – Schematic created using CircuitLab

If I connect one LED without transistor to arduino output it works, if I connect base of transistor to positive terminal three LEDs light up, but when I connect base to arduino it does not work. Multimeter shows there is 5V on base of the transistor but no current.

what is the vf of the LED’s. if you want to turn on the transistor , it base should be around 0.7 V above emitter. that means the output of the MCU should be (0.7 + (3x Vf_LED)).

• In other words: to get this to work, put the LEDs and the resistor in the collector wire, not in the emitter wire. – Wouter van Ooijen Jul 29 '18 at 12:02
• LEDs are 5mm yellow and green, if vf means forward voltage I think it's about 2V. – Sasan Jul 29 '18 at 12:06
• so that explains. the easiest thing to do is what @wouter says. Move the transistor to the low side; that is have transistor emitter to gnd and collector to cathode of the third LED. And thus the first LED’s connected to VCC – Navaro Jul 29 '18 at 12:10
• The transistors are supposed to run motors too, I can't put LEDs on collector. I reduces LEDs to two and now they work, Thanks guys – Sasan Jul 29 '18 at 12:14
• Motors? Also at the emitter?? Poor transistors... If you have a problem, always give the full context! – Wouter van Ooijen Jul 29 '18 at 12:26

if I connect base of transistor to positive terminal three LEDs light up

Yes, that'll probably work despite the transistor being wired as an emitter follower.

but when I connect base to arduino it does not work. Multimeter shows there is 5V on base of the transistor but no current.

Because the transistor is wired as an emitter follower - the emitter "follows" the base voltage but about 0.7 volts lower. So with 5 volts on the base there will be about 4.3 volts at the emitter and each LED will share that voltage because they are in series.

That's approximately 1.43 volts across each LED and, unlesss they are infra red devices (requiring a lower forward voltage to illuminate) you won't see any glow.

The most appropriate way to drives LEDs in a situation like this is to put them in the collector like this: -

Now the BJT fully turns on to virtually a short circuit (maybe 100 mV across it) and there is almost the full 9 volts across the current limiting resistor and LEDs. It's usually the most appropriate way to simply drive motors too except i would consider using an N channel MOSFET instead of a BJT.

• Thanks for your answer. I did everything as the book said. But since I didn't have LM393 and 2N2907A I went with arduino and 2N2222A. Two or Three LEDs are not a big deal, there is a motor parallel to each LED line and they move the robot based on reading from photoresistors connected to analog pins. – Sasan Jul 29 '18 at 14:17