How to control a PNP transistor?

Hi, This is getting me very confused i already searched a lot but the more i read the less i know!

With NPN transistors i connect the base to the arduino (with a resistor), whens its HIGH it turns on, when it's LOW its off.

Now how i wire a PNP transistor to the arduino? I read a lot about this and i'm even more confused =(

Thanks in advance.

http://incredulist.blogspot.com/2012/10/high-side-switching.html

If switching from 5V, connect the same way; only Low is on, and High is off. If switching from higher voltages, like 12V, then a buffer is needed between Arduino and PNP base - a resistor pulls the base high to 12V to turn it off, and a buffer such as NPN transistor is used to pull the base low. Can be one channel of a part like ULN2803, or an open drain shift register such as TPIC6B595.

So in my situation i want to do a LED Matrix using shift registers, if i use PNP on the columns and NPN's on the rows it's ok? It's all running from 5v.

In my opinion, driving the rows from databytes while pulling the columns low is easiest for coding. So have inverse data (1 = off, 0 = on) drive the PNPs to source current thru current limit resistors to the rows, and larger NPNs to sink current from each column one at a time.
Using a shift register like cd74ac164 in place on PNPs is much less wiring to build up.
If total current/column can be limited to <=150mA (8 LEDs at just 20mA each) than TPIC6B595 can be used for the columns.

Example:
Drive the 16 anodes, turn on cathode 0.
2mS later, turn off the cathode.
Drive the 16 anodes, turn on cathode 1.
2mS later, turn off the cathode.
Repeat.
I use one array to hold the anode date,
and a 2nd to hold the cathode data:
byte cathodeData = {0b01, 0b02, 0b04, 0b08, 0b10, 0b20, 0b40, 0b80,}; // data for 8 columns only, 1 = column that is on

Then write a for loop using blink without delay, every 2mS pull up the next anode data and drive the next column.

I already bought some stuff, i have 74HC595,2N3904, 2N3906 and lots of LED's. Can i make it with only this?

If i understand you correctly, the rows would be "positive" and the columns "negative". But with this the PNP transistor in the row would be required to be able do source all the current for the columns, so if i do a 24x8 i would need something like (20mA * 24 = 480mA) ? I would shift the data to the columns and then i would turn the correct row "on".

If i understand you correctly, the rows would be "positive" and the columns "negative".

Yes.

But with this the PNP transistor in the row would be required to be able do source all the current for the columns, so if i do a 24x8 i would need something like (20mA * 24 = 480mA) ?

Otherway around - PNPs source 20mA each, NPNs sink 20mA * # of LEDs in a column. I suppose you could multiplex by Row instead of by Column. I find it easier to think of the other way. Say you had text to display and you wanted to scroll it. Take the letter A below for example: 01110 01110 11011 11011 11111 11111 11011 11011

column 0 is 00111111 = 0x3f column 1 is 11111111 = 0xff column 2 is 11001100 = oxcc column 3 is 11111111 = oxff column 4 is 00111111 = 0x3f

so I would store that in memory as

byte fontArray[] = {
0x3f, 0xff, 0xcc, 0xff, 0x3f, // A
};

and to display a simple loop might be this, blink without delay and with a "manual' for-loop to keep track of where you are.

void loop(){
currentMillis = millis();
elapsedMillis = currentMillis - previousMillis();
if (elapsedMillis >= muxDuration){
previousMillis = previousMillis + muxDuration;
}
columnCount = columnCount +1;
if (columnCount == 5){columnCount = 0;} // reset column tracking
// turn off prior cathodes
digitalWrite (ssPinC, LOW);
SPI.transfer[0);
digitalWrite (ssPinC, HIGH);
// set up anodes
digitalWrite (ssPin, LOW);
SPI.transfer[fontArray[columnCount]);
digitalWrite (ssPin, HIGH);
// turn on cathode
digitalWrite (ssPinC, LOW);
SPI.transfer[cathodeArray[columnCount]);
digitalWrite (ssPinC, HIGH);
}

Add a 2nd blink without delay loop to change the letter being displayed. Maybe have the letters in a larger array and just move columnCount across the columns to control what is multiplexed: 0-4, then 100mS later 1-5, 2-6, 3-7, 4-8 etc. Or a wider swath if the display is wider, say 16 columns: 0-15, 1-16, 2-17, 3-18, etc.

Example uses SPI.transfer to very quickly shift data into shift regsters using '328Ps internal shift register hardware. Others use slower shiftOut command.

So my problem now is with the transistors... NPN: 2N3904: max 200mA PNP: 2N3906: max 200mA

So i will just be able to do around (200/ 26.5) 7 LED's... but since this in on for short time i can probably do the 8 i need?


Forward Voltage (V): 3.2 Forward Current : 30mA Max Peak Forward Current : 75mA Total mA: 26.5 (With 68Ohm resistor)

http://www.fairchildsemi.com/ds/MM/MMBT3904.pdf 200mA, 212mA,data is off the charts. How much base current is needed to achieve that? Who knows. Vce at higher current? Who knows. You can try some standalone, see if it smokes, see if base current is driveable (won't be from 74HC595 I'm pretty sure, wimpy IO part) to support the desired collector current.

You need heftier NPNs, or use 2 per column, 4 LEDs each.

Guess i will end up doing that 2 NPN's since its quite hard to get components here where i live, i bought a lot of stuff from ebay but it took a month to arrive... I should connect the bases together right?

danielb7390: So in my situation i want to do a LED Matrix using shift registers,

This is purely an academic/ experimental head-banging exercise, isn't it, not for a serious application?

If you really want to do a LED matrix of 8 or less in one dimension, you use MAX7219s.

As OP says tho, parts are hard to come by and slow to get. Drive each base with its own resistor from common arduino pin. (5-Vbe)/10mA =resistor Vbe = 0.65, 435 ohm range, down to as low as 250.

Maybe OP can get some PN2222 (2N2222). Hoary things, not cutting-edge modern, but still plentiful and effective. http://forum.arduino.cc/index.php?PHPSESSID=ojkosvqsv5f3s78vlubp4l5ls4&topic=160532.0

CrossRoads: As OP says tho, parts are hard to come by and slow to get. ...

Yes its quite hard, but now the question is getting other transistors will make my soldering part easier i guess i can wait since this is just for fun!

[quote author=Runaway Pancake link=topic=243488.msg1744705#msg1744705 date=1401418506] Maybe OP can get some PN2222 (2N2222). Hoary things, not cutting-edge modern, but still plentiful and effective. http://forum.arduino.cc/index.php?PHPSESSID=ojkosvqsv5f3s78vlubp4l5ls4&topic=160532.0 [/quote] Indeed those are quite old! Theres nothing newer?

For this application wouldn't a mosfet be best suited for the job?

Please help with part numbers. Thanks.

danielb7390: Indeed those are quite old! Theres nothing newer?

Sure, but those ones still work.

Runaway Pancake - Newbie here. How did you determine the value of power dissipation in transistor. We have the current, but what is R of the transistor at saturation? I could not find it in the PN22222 datasheet.

P = I*I*R = V*V/R = IV You know I, you know Vce. Do the math.

R comes into play, Rds, with MOSFETs.

No response to my reply? Won't a mosfet be better for this so if i want to increase the columns sometime i already have something that can handle more in the rows?