Drop voltage on some pins

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!

Do you have resistors in series with the LEDs?

Did you remember to do a pinMode command on the pins you wired the led/resistors to?

Lefty

suirammarius: I've uploaded a sketch, and it functions perfect.

May we see it? And your wiring?

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.

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.

XD

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! :slight_smile:

Moderator edit: [code][/code] tags added. (Nick Gammon)

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);
}

suirammarius: There is nothing wrong with the wiring or with the sketch.

Where do you set the pin to output?

retrolefty: Did you remember to do a pinMode command on the pins you wired the led/resistors to?

Lefty knew. :)

He always does. 8)

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.)

:blush:

I didn’t saw! INCREDIBLE!!! And you realize that I’ve searched a lot before open a new topic!
THANK YOU SIR!

:blush:

@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? :slight_smile:

PS This topic can be deleted because it didn’t serve for something and I have the “problem” (that was a shame) solved.