digitalwrite has opposite effect

Hi There

I’m new to arduino and i have searched for an answer to this for a few hours now.

Basically my Uno board was working great and I have ben ploughing through the sparkfun examples, but yesterday things started to go funny. Long story but I but I stripped back the breadboard to the basic “Blink” configuration and now I see the issue. Basically when I digitalwrite HIGH to a pin with just an LED on it, it turns it OFF, and when I send LOW it turns it on, opposite effect to what you would expect. THE LED on the board behaves fine on PIN 13, but if I attach an LED to PIN 13 like in example 1, it behaves in the opposite. This is now true on on my output pins.

Any help would be greatfully received as its driven me crazy!

DaveK

Where do you connect the LED to?

Hi Nick

Cheers for such a quick reply.

The LED is connected across row 14 and 15 on the breadboad, I have the Resistor connected from the +ve end of the LED to the +ve power line on the the board and a wire from the LED -ve to the output pin.

I first noticed the issue when I was trying to blink a load of LED’s and it just wasn’t working so I stripped everyhitng back to the most basic example and can now see plainly the issue. If you take the Blink Code:

digitalwrite(8, HIGH)
Delay (1000);
digitalwrite(8, LOW)
Delay (1000);

This blinks the LED, but if I change the first dely to say 100, you would expect the LED to flash for a split second and wait, however it keeps the LED on with a short off instead. So I stripped this down further only leaving a digitalwrite line in the setup() and low and behold, setting any pin to HIGH switches the LED off and LOW switches it on.

Is this a faulty board or compiler?
DaveK

OK so if I connect the LED directly into the output on th arduino board, +ve in PIN 12, -ve into ground, then it works fine, however if I make the cirect through the Breadboad, it does the opposite.

I am sure I am doing somehting basic and newboe wrong here but i'm flummoxed at the moment!

DaveK

davek17: I have the Resistor connected from the +ve end of the LED to the +ve power line on the the board and a wire from the LED -ve to the output pin.

There's your problem. The +ve side of the LED should be to the output pin and the -ve side to Ground. You've effectively reversed the way the LED works.

Hi Nick

OK, you sir are a gent for putting up with a very basic error here. I have now got it working and many thanks to you!

davek

It is not an error you have made you are just powering the LED through current sinking rather than current sourcing. It is the prefers way for professionals to do it.

I have this same problem with the built in led on my nano. Any ideas?

wonza: I have this same problem with the built in led on my nano. Any ideas?

I think you do not.

According to the schematic I have of the nano the internal LED ( and resistor ) is directly connected between Pin 13 and the ground. Check the schematic for the revision of the nano that you have.