Pages: [1]   Go Down
Author Topic: UNO controlled LEDs: Resistor Question  (Read 1138 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to control 6 LED lights with my Arduino UNO. So far I've come up with the following.



Input:

I've been instructed that I need a resistor between the base of the transistor and the Arduino. But I can't figure out what type of resistor I need? If anyone could help me I would REALLY appreciate it!  smiley-eek

Also, I found that this Transistors was popular in similar LED builds, will this work or is there a better Transistor out there?: http://www.radioshack.com/product/index.jsp?productId=2062586

My code:

Code:
/*
  Turn LEDs on and Off
 */

void setup() {               
  pinMode(9, OUTPUT);      // digital pin as output
  digitalWrite(9, HIGH);   // keep power on
 
  // initialize the digital pin as an output.
  pinMode(9, OUTPUT);     
}

void loop() {

  digitalWrite(9, HIGH);   // set the LEDs on
       delay(1000);
      digitalWrite(9, LOW);    // set the LEDs off
}
Logged

alabama
Offline Offline
Full Member
***
Karma: 1
Posts: 183
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mpick
Followed your link to RS, typically they have no link to a datasheet or Hfe values or anything to figure out what resistor you need.
Yes, I can go to another online supplier and look it up, but after reading the bad reviews on RS about their packaging of the wrong parts, just order them from DigiKey, or one of the others listed here http://www.findchips.com/.
The explanation that works best for me to figure the value can be found herehttp://www.rason.org/Projects/transwit/transwit.htm.
Didn't check your code, lots of others here are way more adept at spotting mistakes.
TomJ
Logged

Einstein once said you don't really understand anything until you can explain it to your Grandmother

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  pinMode(9, OUTPUT);      // digital pin as output
  digitalWrite(9, HIGH);   // keep power on
 
  // initialize the digital pin as an output.
  pinMode(9, OUTPUT);     

Setting the pin to output once is enough.

Code:
void loop() {
  digitalWrite(9, HIGH);   // set the LEDs on
  delay(1000);
  digitalWrite(9, LOW);    // set the LEDs off
}

This won't do what you think. It will take the pin high for 1 second, a low for about a microsecond. Thus it will look high all the time to the naked eye. You need another delay.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mpick
Followed your link to RS, typically they have no link to a datasheet or Hfe values or anything to figure out what resistor you need.
Yes, I can go to another online supplier and look it up, but after reading the bad reviews on RS about their packaging of the wrong parts, just order them from DigiKey, or one of the others listed here http://www.findchips.com/.
The explanation that works best for me to figure the value can be found herehttp://www.rason.org/Projects/transwit/transwit.htm.
Didn't check your code, lots of others here are way more adept at spotting mistakes.
TomJ

Thank you for taking the time to reply! I really appreciate it! I followed your link and read the entire article but I'm still a little lost. I did find the data sheet to the P2N2222AG transistor. (http://www.onsemi.com/pub_link/Collateral/P2N2222A-D.PDF)

And I found this calculator for calculating the transistor's base resistor:  http://kaizerpowerelectronics.dk/calculators/transistor-base-resistor-calculator/

I tried using the calculator but I have no idea what I'm doing.  smiley-roll-sweat If you could help me out and calculate this base resistor I would really appreciate it!  This is the last piece to my project, and I would really like to see it work.  smiley-grin
« Last Edit: May 16, 2012, 11:32:21 pm by mpick67 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  pinMode(9, OUTPUT);      // digital pin as output
  digitalWrite(9, HIGH);   // keep power on
 
  // initialize the digital pin as an output.
  pinMode(9, OUTPUT);     

Setting the pin to output once is enough.

Code:
void loop() {
  digitalWrite(9, HIGH);   // set the LEDs on
  delay(1000);
  digitalWrite(9, LOW);    // set the LEDs off
}

This won't do what you think. It will take the pin high for 1 second, a low for about a microsecond. Thus it will look high all the time to the naked eye. You need another delay.

That makes perfect sense! Thank you for your help!
Logged

Offline Offline
Edison Member
*
Karma: 32
Posts: 1282
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

smiley-grin My momma told me, "Never do math in public", so hopefully somebody will double-check me...

Quote
I tried using the calculator but I have no idea what I'm doing.   If you could help me out and calculate this base resistor I would really appreciate it!
The gain of a transistor isn't something you can count-on.   Usually, they will spec the minimum. So normally, we use resistors (which can have 1% or better tolerance) to "control" the gain, or to control how the circuit performs.

There is more than one way to make the calcuations, and  I'm going to make some assumptions & approximations...    Here's my approach:

With 8 Volts from the battery and assuming ~2V dropped across the LEDs, that leaves 6V across each 270 Ohm resistor.  (There is also a small voltage-drop across the transistor's collector-emitter junction, but I'll ignore it.)   Using Ohms Law, the current through each resistor (and LED) is 6/270 = 22.2mA (0.0222 Amps).   Times 6 LEDs = 133mA total.   

Let's assume a worst-case transistor gain (current gain) of 50.   133/50 = 2.67mA (into the base of the transistor). 

There will be an approximate 1/2-Volt drop across the transistors, base-emitter junction.    That's small enough that we could ignore it.  But let's not ignore it, and assume we have 5V coming out of the Arduino with 4.5V across the base-resistor.   We've got 4.5V across an unknown resistor, and we need 2.67mA (0.0267A).  So, we calculate 4.5/.0267 = 1685 Ohms.

Since we made a worst-case assumption about the transistor gain and we intend to saturate the transistor (turn it all the way on), any resistor value between 1k and 2k should work.  As long as the values are "close", changes in the base-resistor value or transistor gain won't affect LED brightness.
« Last Edit: May 17, 2012, 01:50:45 pm by DVDdoug » Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11672
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For full saturation multiply the base current by more than that - 4 or 5 times perhaps, so try a 330 or 470 ohm.  It you don't fully saturate the transistor its collector-emitter voltage won't go right down to 0.1V or so and it will dissipate a bit more heat.  Here that won't matter as the current is only 0.13A, but when you are switching really large currents this will matter more.

Also in those circumstances you'll need to look at the details of DC gain v. collector current in the datasheet - at high currents the gain can fall noticeably.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

smiley-grin My momma told me, "Never do math in public", so hopefully somebody will double-check me...

Quote
I tried using the calculator but I have no idea what I'm doing.   If you could help me out and calculate this base resistor I would really appreciate it!
The gain of a transistor isn't something you can count-on.   Usually, they will spec the minimum. So normally, we use resistors (which can have 1% or better tolerance) to "control" the gain, or to control how the circuit performs.

There is more than one way to make the calcuations, and  I'm going to make some assumptions & approximations...    Here's my approach:

With 8 Volts from the battery and assuming ~2V dropped across the LEDs, that leaves 6V across each 270 Ohm resistor.  (There is also a small voltage-drop across the transistor's collector-emitter junction, but I'll ignore it.)   Using Ohms Law, the current through each resistor (and LED) is 6/270 = 22.2mA (0.0222 Amps).   Times 6 LEDs = 133mA total.   

Let's assume a worst-case transistor gain (current gain) of 50.   133/50 = 2.67mA (into the base of the transistor). 

There will be an approximate 1/2-Volt drop across the transistors, base-emitter junction.    That's small enough that we could ignore it.  But let's not ignore it, and assume we have 5V coming out of the Arduino with 4.5V across the base-resistor.   We've got 4.5V across an unknown resistor, and we need 2.67mA (0.0267A).  So, we calculate 4.5/.0267 = 1685 Ohms.

Since we made a worst-case assumption about the transistor gain and we intend to saturate the transistor (turn it all the way on), any resistor value between 1k and 2k should work.  As long as the values are "close", changes in the base-resistor value or transistor gain won't affect LED brightness.

Thank you SOOOO much! I really appreciate you taking the time to explain this to me! I'll post pictures and a video once I get my project working.  smiley-lol
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For full saturation multiply the base current by more than that - 4 or 5 times perhaps, so try a 330 or 470 ohm.  It you don't fully saturate the transistor its collector-emitter voltage won't go right down to 0.1V or so and it will dissipate a bit more heat.  Here that won't matter as the current is only 0.13A, but when you are switching really large currents this will matter more.

Also in those circumstances you'll need to look at the details of DC gain v. collector current in the datasheet - at high currents the gain can fall noticeably.

So you don't think a 1k or 2k resistor will work? Will I hurt my Ardunio board if I try the wrong resistor, or will the transistor simply not work? Thanks, Mike
Logged

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have spare 270 Ohm resistors, just use those for the base current. As long as you don't draw too much from the Arduino, you're not going to destroy it by driving it into saturation -- in fact, that's usually a good thing when switching power!

Also, I would use a BS170 transistor (MOSFET) rather than that NPN. That's my personal preference, though. (Btw: the hook-up would actually look exactly the same, as the pin order on that MOSFET is D-G-S)

I would hook two LEDs in series (for 7 V drop) and a smaller resistor (~50 Ohm) to get more light out of the juice in that battery. Three strings of two LEDs in series each is more efficient than six strings of one LED each like you have now.
 
Logged

Pages: [1]   Go Up
Jump to: