España
Offline
Jr. Member
Karma: 0
Posts: 69
|
 |
« on: April 09, 2012, 05:42:10 pm » |
Hello!
I have an Atmega328P standalone. I've uploaded a sketch, and it functions perfect. The problem is when I connect a LED to some pins (eg. PD6, PD7..) the LED narrowly lights. I've measured the drop voltage on the LED+resist. an it has almost 2 V. Why just some pins does this? Could anyone explain how could I avoid this? The transistor is the only solution?
Thank you!
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #1 on: April 09, 2012, 07:35:23 pm » |
Do you have resistors in series with the LEDs?
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #2 on: April 09, 2012, 10:07:57 pm » |
Did you remember to do a pinMode command on the pins you wired the led/resistors to?
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #3 on: April 10, 2012, 12:00:49 am » |
I've uploaded a sketch, and it functions perfect.
May we see it? And your wiring?
|
|
|
|
|
Logged
|
|
|
|
|
España
Offline
Jr. Member
Karma: 0
Posts: 69
|
 |
« Reply #4 on: April 10, 2012, 02:01:17 am » |
Yes, I have a resistor. There is nothing wrong with the wiring or with the sketch. Without a load, I have 5V between the pin and GND. When I conect the LED (with the resistor) the drop voltage on the load is, as I said, about 2V.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #5 on: April 10, 2012, 02:06:25 am » |
There is nothing wrong with the wiring or with the sketch. Ah, if I had a dollar for every time I heard that ... So no sketch? No wiring? The transistor is the only solution? The solution is to answer our questions.
|
|
|
|
|
Logged
|
|
|
|
|
España
Offline
Jr. Member
Karma: 0
Posts: 69
|
 |
« Reply #6 on: April 10, 2012, 02:34:15 am » |
Ah, if I had a dollar for every time I heard that ... (...)
 Ok, here is the sketch: #include <Wire.h> byte c; void setup() { Wire.begin(4); // join i2c bus with address #4 Wire.onReceive(receiveEvent); // register event digitalWrite (6, HIGH); delay(3000); digitalWrite (6, LOW); }
void loop() { if (c==1) { digitalWrite (6, HIGH); } if (c==0) { digitalWrite (6, LOW); } delay(100); }
void receiveEvent(int howMany) { c = Wire.read(); } And this is the wiring; the yellow wire is the pin 6 from the sketch.  Thank you! Moderator edit: [code] ... [/code] tags added. (Nick Gammon)
|
|
|
|
« Last Edit: April 10, 2012, 02:57:04 am by Nick Gammon »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 116
Posts: 10134
|
 |
« Reply #7 on: April 10, 2012, 02:48:14 am » |
void setup() { Wire.begin(4); // join i2c bus with address #4 Wire.onReceive(receiveEvent); // register event pinMode( 6, OUTPUT ); digitalWrite (6, HIGH); delay(3000); digitalWrite (6, LOW); }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #8 on: April 10, 2012, 02:57:57 am » |
There is nothing wrong with the wiring or with the sketch.
Where do you set the pin to output?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #9 on: April 10, 2012, 02:58:48 am » |
Did you remember to do a pinMode command on the pins you wired the led/resistors to?
Lefty knew. 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 116
Posts: 10134
|
 |
« Reply #10 on: April 10, 2012, 03:05:28 am » |
He always does. 
|
|
|
|
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 78
Posts: 5453
Strongly opinionated, but not official!
|
 |
« Reply #11 on: April 10, 2012, 03:14:21 am » |
So... If you DON'T set the pin as an OUTPUT, writing a HIGH with digitalWrite() enables the internal "weak pullup", which is a resistor of value about 20k to +5V. This allows enough current to flow out the pin to tell a voltmeter that there is 5V there, and enough for a modern LED to light very dimly, but not enough to get the current you are expecting. Effectively, you get the equivalent of a 20k+R current-limiting resistor to the voltage source, instead of just R.
Nice job on the picture and code posting, BTW. A lot of the time when people are "sure" that their code/circuit is correct, that info NEVER shows up (which is why the responders are a little ... assertive about asking.) Here, we got a good picture and the code quite quickly (and it did indeed make the problem obvious.)
|
|
|
|
|
Logged
|
|
|
|
|
España
Offline
Jr. Member
Karma: 0
Posts: 69
|
 |
« Reply #12 on: April 10, 2012, 03:25:45 am » |
 I didn't saw! INCREDIBLE!!!!! And you realize that I've searched a lot before open a new topic! THANK YOU SIR!  @Westfw: Yes, I realized what happed when I saw that I forgot to declare the type of pin. About the photo, the code... I've posted here because I didn't found any solution myself. So it's my interest to show as more explicit as I can the problem that I have. Isn't it? PS This topic can be deleted because it didn't serve for something and I have the "problem" (that was a shame) solved.
|
|
|
|
|
Logged
|
|
|
|
|
|