Raspberry Pi Lab

Tag: amps

Three Blink LED – Part Two

by on Jan.05, 2014, under Electronics, Projects

3LED-transparentA couple of days ago I created a circuit for a three led blinking circuit.  The circuit description and the Python code can be found in my previous post.

In that example, I drove the LEDs directly off the GPIO pin with a 560 ohm resister.  That worked well because the GPIO pin can provide 3.3 v at up to 16mA.  However, I reader suggested that driving the LEDs directly off the 5v power rail and switching them on and off with a transistor on the GPIO pin.

The readers was absolutely right.  The transistor is basically a digital switch.  It has three pins called the collector, emitter, and base.  The collector and emitter pins complete the circuit.  The base pin is the switch.  By connecting the base pin to the RPi’s GPIO and setting it to High (1), the circuit is complete and the LED lights up.  Setting the GPIO to low (0) opens the circuit and turns the LED off.

This allows the LED to get its power from some other source than the GPIO pin itself.  The RPI has a 5v pin that is capable of 300 mA.  This additional voltage and current would allow us to use more LEDs per GPIO pin or control other devices that require more than the GPIO is capable of providing..

In my new circuit I took the 5v pin of the RPi to a 560 ohm resistor.  The resistor connected to the positive leg of the LED which then connected its negative leg to the collector pin of an N2222 transistor.  The emitter leg of the transistor then connected to ground.  The base pin of the transistor connected to a GPIO pin.  I set op three of these LED circutis.  Red on GPIO 25.  Green on GPIO 23.  Blue on GPIO 18.

three led isolatedIt really didn’t matter which GPIO pins I used.

I chose these particular pins because those are the same pins I used in my previous Three LED Blink circuit.  Therefore the Python code did not have to change at all for this to work.  The GMail Notify example I posted will also work with this re-designed circuit.

As a side note… The 560 ohm resister is larger than the minimum resister needed for this circuit.  According to Ohm’s Law (I = V/R), the minimum resister value would be 150 ohms.  That is R = (5v – 2v) / 20mA = 150 ohms.  5v being the voltage supplied by the power rail and 2v being the requirement of my particular LED.  The difference, 3v, needts to be resisted away so as not to blow up the LED.  By using the 560 ohm resistor instead of the 150 ohm minimum, my LED will shine sligntly less bright, but I’m ok with that.

 

 

 

Leave a Comment :, , , , , , , , , , more...

Current Draw In My Three LED Circuit

by on Jan.04, 2014, under Electronics

ohms-lawI an previous post I described a Three LED circuit and Python code to drive the LEDs.  A reader posted, via Facebook, the following question…

“You decided to drive them directly through a resistor instead of going through a transistor. What is the current draw on the GPIO pins?”

Well, I am certainly not an electrical expert, but I think I can attempt to talk about the math behind this circuit.

As you recall,  I drove the LED but connecting a GPIO pin to a 560 Ohm resister.  The resistor was connected to the positive leg of the LED.  Lastly, the negative leg of the LED was connected to ground.

I used a 10mm Red LED purchased from Ada Fruit.  The datasheet for this LED can be found at on the Ada Fruit website.  In short, the forward voltage of the LED is a typical 2.0 v with a maximum of 2.4 v.  It draws 20mA.

Ohm’s Law reads the current (I) = Voltage (v) / Reistance (R).   I=V/R

Well, we already know that the LED wants to run at 2.0 V and draw 20mA.  We just need to know what size resistor to place on the LED so as not to blow up the LED.  A simple algebraic re-arrangement of Ohm’s law tells us that R=V/I

The GPIO pins on the RPi all output 3.3v.  Since the GPIO is giving us 3.3 V when we only need 2.0 V, we will have to remove (resist) 1.3V.  Now we can calculate the minimum resistor size.

R = (3.3 V = 2.0 V) / 0.02A = 65 ohms.

That means the minimum size resistor for this circuit using this LED is 65 Ohms.  Using a larger resistor just means the LED won’t shine as brightly as it would with the minimum sized resistor.

So why did I decide to use the 560 ohm resistor?  Simple… That is what I had available in my toolbox.

I think I can now answer the reader’s actual question of how much current was actually drawn from the GPIO pin.

Because I used a 560 ohm resistor and I know the voltage provided by the GPIO and the voltage used by the LED, I can calculate the current draw via Ohm’s Law.

I = V/R

The LED needs 2v of the 3.3 v provided on the GPIO and we know the resister is 560 ohms.

I = (3.3 V – 2.0 V) / 560 ohms = 0.0023 A = 0.23mA

The spec sheet says we can draw up to 16mA from a GPIO (as long as we don’t do that much for more than one pin at a time).  So our 0.23mA is well within spec..

 

 

 

 

 

 

Leave a Comment :, , , , , more...

Archives

All entries, chronologically...

Our Partners

Please take a minute to visit our partners

Looking for something?

Search the Site

If you can't find what you are looking for, please leave a comment somewhere, subscribe to our feed and hopefully your question will be answered shortly, so please visit again!