# can NPN transistor be used when sinking current?

so to give a little bit of background, I want to experiment with led matrixes. I have multiple Arduino Nano boards, and have done small projects (9 LED bank with simple animations).

So I know that each pin can only supply a limited amount of current (perhaps 40mA).

So my test circuit of a 2*2 matrix has P1, P2 for positive rows, and N1 and N2 for negative columns. All LEDs in row 1 have anodes wired together to P1, all cathodes in column 1 are wired together. also resistors are hard wired to each LED.

Now I there's plenty of current with a small matrix but if I get 9*9 LEDs I would definitely run out of current both onboard and per pin/row.

I successfully used this schematic to wire in a 2n7000 mosfet (200mA max) to P1. http://www.learningaboutelectronics.com/images/N-channel-MOSFET-switch-circuit.png

My own circuit looks somewhat like this rather hard to understand ascii diagram

    P1--*---*--
....l...l..
P2--*---*--
....l...l..
....N1..N2


The dashes are anode wiring, the l's are cathode wiring and the N/P 1/2 are the header wires. (I plan to expand this to 4*4*4 so I want to be able to turn them all on without worrying about current limitations)

To clarify I set P1 HIGH, and N1 LOW to get the top-left led lit. I want 1 transistor per P (for positive, anode) wire, and one per N (negative, cathode)

So here's my question. Do I have to buy a P-channel mosfet in order to accomplish this? Or is there some way to do it with the 2n7000. (I bought 100pcs on eBay)

If I must buy P-channel transistors, can you provide a simple schematic and the equivalent to the 2n7000?

• Your question is a little vague. Firstly in a simple n*n matrix a maximum of n LEDS can be on at any one time (assuming you want to individually control each LED), although multiplexing can give the effect of more. I assume you are using resistors to limit LED current. You can, for example, use a feed resistor for each row, and pull low (with N channel MOSFET) if the row is not on. This is not the most "efficient" use of power, but this is rarely a problem. You need to better define your aims.
– Milliways
Mar 11, 2015 at 7:27
• Voting to close as this question clearly belongs on EESE, not the Arduino site. Mar 11, 2015 at 13:22
• Matt - surface mount or through hole? Mar 11, 2015 at 20:10
• @RussellMcMahon through-hole. I ended up making a 4x4x4 cube with 64 LEDs. I put a resistor on each and every LED too, so I can light up all 16 LEDs at a time on 1 given layer. [Then I scan each 4 layers very fast to give persistence of vision]. It took about 2.5 days to do the hardware, now I am starting on the software.
– Matt
Mar 14, 2015 at 19:03

You do not need transistors on both rows and columns because, as @Milliways explained, you will not light all the rows and columns simultaneously. Since you already have a bunch of N-channel MOSFETs, and these are good for sinking current, you will put them on the columns (negative side of the LEDs). Now you can light a whole column at a time without worrying about current limitations. You do not need transistors on the rows, because at most one LED will be lit per row at any given time.

Your circuit will look like this:

P1 ───────*─────────*────…
│         │
P2 ───────*─────────*────…
|         |
├┘        ├┘
┌→│       ┌→│
│ ├┐      │ ├┐
│  │      │  │
N1  GND   N2  GND


• initialize all Ns and Ps to LOW
• output on P1, P2... Pn whatever you want to see on the first column (HIGH to turn the LED on, LOW to keep it off)
• set N1 to HIGH, this will turn the MOSFET on and light the LEDs
• wait for a few ms
• set N1 to LOW, this will turn off the whole column
• output on P1, P2... Pn whatever you want to see on the second column
• set N2 to HIGH
• wait for a few ms
• set N2 to LOW
• and so on if you have more columns...
• Surface mount or through hole? Mar 11, 2015 at 10:21
• @RussellMcMahon: whatever he prefers.
– Edgar Bonet
Mar 11, 2015 at 10:32
• Nice and simple, but there are a few potential "gotchas". A 9x9 matrix would require at best a 1/9 duty-cycle. This will likely require additional current (to maintain sufficient brightness) requiring a smaller current limiting resistor (on the rows with this method). Note that 40mA is abosolute maximum and 20mA is max recommended current (per pin). Also note there is another current source limitation that has to do with total currents (150mA per group, 200mA per Arduino). See Arduino Pin Current Limitations.
– Tut
Mar 11, 2015 at 10:45
• @EdgarBonet whoops - that question was meant for Matt's post - wrong location - try again. Mar 11, 2015 at 20:11

Key principles:

An N Channel FET such as a 2N7000 has drain more positive than source and needs its gate driven positively relative to its source to turn on.

A P Channel FET such has drain more negative than source and needs its gate driven negatively relative to its source to turn on.

You can use 2N7000 as the high side switch ONLY if you are prepared to drive its gate 3V or more above its source. This would require extra drivers to translate the Arduino voltages to the correct levels, which negates any gains in this case. Better and easier is to use P Channel high side FETs or PNP transistors. A P Channel FET is somewhat easier to drive in this context.

5V drive is better with 2N7000 that 3V3 but 3V3 MAY suffice.

The cheapest P Channel MOSFET (in stock Digikey 11.1 cents each in 100's) is the horrible BSS84 . This is a common hobbyist part but has poor specs.

BUT for 13.3 cents each in 100s (in Stock Digikey) you can buy the unbelievably good IRLML6402 - only 20V but 3A , 65 milliOhm Rdson (on resistance) - probably works well enough with 2.25V gate drive and at 3V will get up and sing and tapdance simultaneously. A bargain.

Those are both SMD (surface mount) parts.

Through hole parts are less available but here are a range available from Digikey

Start from about 36c in 100.s A TO220 part is available for slightly more.

Note that Vgsth - threshold or turnon voltage should be substantially lower than available drive voltage.

THe remarkably good value compared to most IRLIB9343 datasheet here is possibly best value.

• thank you, some good info in here and I'm sure I'll come back the next time I research which transistors to buy next.
– Matt
Mar 11, 2015 at 16:12
• @Matt The Digikey catalog is a superb selection guide. They don't have everything, but more than many. Mar 11, 2015 at 20:12