Geeks With Blogs
Joaquin Jares Just another geek's blog

Be warned: this will be very basic. I find it amazing nonetheless.

As a newbie, I went out and bought a 5V led to be used in an output port in the Netduino. This will of course not work, as the output ports of the Netduino are 3.3V. “No problem”, I thought, “I’ll just use some resistors”. The only problem is that resistors don’t work that way. You can take 5V to 3.3V by using resistors (although you could take 5V to a 3.3V led). I ended up giving the led to a friend who does very cool led projects, but I couldn’t let it rest. The point is that the Netduino does have a 5V source. So I did a little research on how to use transistors for switching, and this is the result:

Two blinking leds, using transistors as switches

Most of the data I got from this excellent pdf. For this experiment I used 2 BC547B transistors, and 2 2K resistors. The resistors are very easy to calculate in this case. I think anything from 1K to 5K will work. The only point (as is usual with resistors) is not to burn another component, in this case the transistors. The code for the project (based on my last post), is simply this:

1 board.GreenLed.TurnOff(); 2 board.RedLed.TurnOn(); 3 4 while (true) 5 { 6 board.GreenLed.Invert(); 7 board.RedLed.Invert(); 8 Thread.Sleep(1000); 9 }

The code for the board is this:

1 public BaseBoard() 2 { 3 GreenLed = new Led(Pins.GPIO_PIN_D6); 4 RedLed = new Led(Pins.GPIO_PIN_D7); 5 } 6

The transistors have 3 pins: Collector, Base and Emitter. In the transistors I got, they are in that order, from left to right (when the transistor is facing you with the written flat surface). These are NPN transistors. That means that when the base has current (as little as 1mA), the collector and emitter are connected. In PNP transistors, it works the other way around (when the base doesn’t have current, the base and collector are connected).

The connection is the same for both leds: connect the emitter to ground, the collector to the cathode (the short pin) of the led and the base to the resistor. The other leg of the resistor should be connected to the output pin in the Netduino, and the other pin in the led (the anode) to the source (5V or 3.3V, as needed). And that’s it! With that, you’re using the Netduino with leds of 5V or 3.3V.

One final note: I used the extremely cool piranha leds. I had some difficulty understanding how to connect them, but it’s really easy. In these leds, one of the corners of the square capsule is trimmed. In the leds I bought, this corner is the cathode (equivalent to the short pin of a regular led, should be connected to the emitter in the transistor. Piranha leds are very bright, and they look very good.

So what can you do with this? For starters, you can power 4 leds using 2 pins (using transistor boolean magic). For instance, I used a NPN and a PNP transistors, and I had (on 1 Netduino pin) the same alternating effect, by turning on and off the pin. The only difference is that I connected the same pin to both resistors, and I replaced a BC547B transistor with a BC327B transistor. Check it out:

Single pin alternating effect

You can also use the super bright blue leds, which are 5V.

Posted on Saturday, October 23, 2010 12:13 PM | Back to top


Comments on this post: Netduino and Transistors

# Netduino and Transistors
Requesting Gravatar...
The Netduino's pins are great for directly controlling small electric items like LEDs. There are literally thousands of different types of transistors. - car title loans irvine
Left by Car title loans irvine on Jan 11, 2012 1:16 PM

Your comment:
 (will show your gravatar)


Copyright © Joaquin Jares | Powered by: GeeksWithBlogs.net