Offline
Full Member
Karma: 0
Posts: 118
|
 |
« on: June 02, 2012, 06:10:00 pm » |
--edit: see http://arduino.cc/forum/index.php/topic,108403.msg814896.html#msg814896 for up to date info Hi all, I'm doing some experiments to better understand how to use transistors as amplifiers in future projects. Right now, I have this:  But with this setup, PWM works in a very strange way. analogWrite(ledPin, 0); makes the LEDs super bright and analogWrite(ledPin, 255); turns it off. On a single LED that is not on the resistor, 0 = off, 255 = full brightness. Why is that? I guess the transistor is inversing the PWM's effects? Should I carry on, using PWM with reverse values (ie 255 = off and 0 = full on) or does the transistor have other side effects on PWM? Thanks! --edit: see http://arduino.cc/forum/index.php/topic,108403.msg814896.html#msg814896 for up to date info
|
|
|
|
« Last Edit: June 03, 2012, 04:57:50 pm by hfp777 »
|
Logged
|
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.
Please factor this in your answer and clarify as much as possible. It will help me understand better and will help people like me googling this answer/solution.
|
|
|
|
Offline
Edison Member
Karma: 24
Posts: 1477
Now, More Than Ever
|
 |
« Reply #1 on: June 02, 2012, 06:31:12 pm » |
What transistor are you using? Perhaps there is a misconnection or two. As shown, an NPN, it should be full on with 255 (not inverting.)
|
|
|
|
|
Logged
|
Don't React -- Read!
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 118
|
 |
« Reply #2 on: June 02, 2012, 07:27:16 pm » |
I'm using a PN2222 transistor
|
|
|
|
|
Logged
|
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.
Please factor this in your answer and clarify as much as possible. It will help me understand better and will help people like me googling this answer/solution.
|
|
|
|
Port Angeles, Wa
Offline
Edison Member
Karma: 13
Posts: 1410
Ultimate DIY: Arduino
|
 |
« Reply #3 on: June 02, 2012, 07:35:14 pm » |
Please tell me the you are using at least a 1k resistor on the base... arduino pin. Secondly, yes, an npn will invert logic but you can work with that if wired right. When the pin goes highfrom arduino it will turn on and supply gnd path to the leds. Also, each led should have it's own current limit resistor.
To me, your results sound like a wiring issue.
|
|
|
|
« Last Edit: June 02, 2012, 07:39:00 pm by pwillard »
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 24
Posts: 1477
Now, More Than Ever
|
 |
« Reply #4 on: June 02, 2012, 07:39:28 pm » |
You didn't show a resistor between the base and the PWM pin, use one, 330Ω to 1K or so. The leads of the PN2222 are E-B-C, looking at the flat/face and with the leads pointing down. E goes to GND, B goes to PWM (via that resistor) and C goes the LEDs.
Make sure it's actually marked PN2222, I know of odd bits being stuffed into "multi-packs".
Another thing, each LED ought to have its own resistor (not doing so won't make it to work inverted.)
|
|
|
|
|
Logged
|
Don't React -- Read!
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 118
|
 |
« Reply #5 on: June 02, 2012, 08:03:33 pm » |
Please tell me the you are using at least a 1k resistor on the base... arduino pin. Secondly, yes, an npn will invert logic but you can work with that if wired right. When the pin goes highfrom arduino it will turn on and supply gnd path to the leds. Also, each led should have it's own current limit resistor.
To me, your results sound like a wiring issue.
I have a 220Ω resistor on the base. I'll add 2 other 220Ω for the two LEDs, thanks for the tip
|
|
|
|
|
Logged
|
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.
Please factor this in your answer and clarify as much as possible. It will help me understand better and will help people like me googling this answer/solution.
|
|
|
|
Port Angeles, Wa
Offline
Edison Member
Karma: 13
Posts: 1410
Ultimate DIY: Arduino
|
 |
« Reply #6 on: June 02, 2012, 08:53:54 pm » |
Driving the base pin with over 20mA when 5mA or less is "enough"... is not considered to be "best practice".
|
|
|
|
|
Logged
|
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 34
Posts: 2404
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #7 on: June 02, 2012, 09:44:16 pm » |
One thought about 10 - 20 mA base current is that you can use a transistor with any Beta value whatever and Know it Will Work, Waste of power, Yes certainly but harmful no I have never found except in cases where the base current exceeded the device specifications that there was any great wrong done, obvious reasons excepted. Sometimes we forget that we were ALL new at something, sometime and advice of that nature about base current can be more defeating than a real lesson should be. I Know How to do it right... Electronically about 98% of the time, after all occasionally, There is something New... I DO NOT always know how to tell someone else to do it right unless I am Very careful Because Every situation is Different... IMO
Doc
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
Delray Beach, FL USA
Offline
Full Member
Karma: 0
Posts: 113
|
 |
« Reply #8 on: June 02, 2012, 11:21:40 pm » |
As far as I know, the brightness of the LEDs is entirely due to the current. I'm putting my pair of IR LEDs in series rather than parallel and adjusting the single resistor to a lower value to provide the 100mA of current the LEDs are rated for. I also used a darlington switching transistor which allowed me to use a 100K resistor from the output pin of the atmega (actually a Teensy 2.0 board in my case). Details of my circuit are here: http://home.comcast.net/~tomhorsley/hardware/arduino/teensy.html(Of course the problem you run into putting LEDs in series is that with enough of them, the combined voltage drop is so big you can't get any current at all, but with just two I don't seem to have a problem).
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 118
|
 |
« Reply #9 on: June 03, 2012, 05:55:38 am » |
Yes I put them in series first but I couldn't get any of them lit. I have 10 of them and the current drop was too much for any to light. My schematics has three because I wanted to simplify the wiring while getting it to work but ultimately I will wire up all 10.
|
|
|
|
|
Logged
|
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.
Please factor this in your answer and clarify as much as possible. It will help me understand better and will help people like me googling this answer/solution.
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 118
|
 |
« Reply #10 on: June 03, 2012, 05:57:05 am » |
One thought about 10 - 20 mA base current is that you can use a transistor with any Beta value whatever and Know it Will Work, Waste of power, Yes certainly but harmful no I have never found except in cases where the base current exceeded the device specifications that there was any great wrong done, obvious reasons excepted. Sometimes we forget that we were ALL new at something, sometime and advice of that nature about base current can be more defeating than a real lesson should be. I Know How to do it right... Electronically about 98% of the time, after all occasionally, There is something New... I DO NOT always know how to tell someone else to do it right unless I am Very careful Because Every situation is Different... IMO
Doc
Thanks, it's much clearer. However, I don't understand how to “send” only 5mA base current when I have no control over the intensity of the current sent out by the atmega chip. Should I use a resistor? But then it would be a waste of power too, right?
|
|
|
|
|
Logged
|
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.
Please factor this in your answer and clarify as much as possible. It will help me understand better and will help people like me googling this answer/solution.
|
|
|
|
North Queensland, Australia
Offline
Edison Member
Karma: 35
Posts: 1279
|
 |
« Reply #11 on: June 03, 2012, 06:46:22 am » |
|
|
|
|
« Last Edit: June 03, 2012, 06:47:53 am by pYro_65 »
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26024
Solder is electric glue
|
 |
« Reply #12 on: June 03, 2012, 08:14:26 am » |
I don't understand how to “send” only 5mA base current when I have no control over the intensity of the current sent out by the atmega chip. Yes you have it is the load you connect to it. Should I use a resistor? Yes But then it would be a waste of power too, right? It depends on what you mean by waste - in general no you are limiting the current. Thoughts about wasting power in this situation are meaningless.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Edison Member
Karma: 51
Posts: 2467
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #13 on: June 03, 2012, 08:52:32 am » |
That is not a good circuit.
Every LED (or serial chain of LEDs) should have its own current limiting resistor. You should not share one resistor between multiple paralleled LEDs.
The way you have it now you will get uneven brightnesses, and some LEDs may not even light up.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 118
|
 |
« Reply #14 on: June 03, 2012, 04:56:37 pm » |
I cannot fathom what is going on. This is what I have now for the transistor  And for the photocell  And the code const int ledPin = 6; const int lightPin = 0; int luminosite;
void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); }
void loop() { luminosite = map(analogRead(lightPin), 0, 1023, 255, 0); // this is inversed because I want the LEDs to become brighter as light increases analogWrite(ledPin, luminosite); Serial.println(analogRead(lightPin)); Serial.println(luminosite); Serial.println(); delay(200); } The lower the light, the lower the analog value on the photocell. And the higher the value mapped to luminosite. So, when there is a lot of light, the luminosite should be closer to 255 and the LEDs be very bright. When there is low light, the luminosite should be closer to 0 and the LEDs be less bright. This is working as the values output on the serial monitor concur. What blows my mind is that the LEDs work in reverse logic!!! If I hook one up directly to the Arduino pin, it is fine; 0 = off, 255 = full on. But when I hook up the transistor, with the exact same code, the opposite happens!! The lower the 0-255 luminosite value, the brighter the LED! Can anyone figure this out??
|
|
|
|
|
Logged
|
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.
Please factor this in your answer and clarify as much as possible. It will help me understand better and will help people like me googling this answer/solution.
|
|
|
|
|