Arduino Digital Pins HIGH LOW output seem to be reversed

rohan.k picture rohan.k · Jan 31, 2014 · Viewed 9.7k times · Source

I've written a code last year which was working well at that time. However on loading the same code this time I am getting reversed output. That is, when the Digital Pin is set to HIGH, it return LOW and vice versa.

digitalWrite(led, HIGH) //PROBLEM: Should turn ON the LED but insted it turns OFF

I've tried the BLINK EXAMPLE and in that case also the output seem to be reversed.

Here is the code:

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
// initialize the digital pin as an output.
pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);               // wait for a second
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
delay(5000);               // wait for a second
}

According to the code, my LED should be turned ON for 1 second and then should be turned OFF for 5 seconds before it again turns ON. However, the OUTPUT I am getting is completely reverse i.e LED is ON for 5 seconds and OFF for 1 second. I need help how to fix this.

My main code is based on interfacing arduino with android. I have been working on to fix this for android-arduino connectivity via bluetooth, which I did accomplish last year but now have encountered this issue. I have tried this on three different arduino uno boards, tried with different sensors but the HIGH-LOW seems to be reversed.

Answer

Dithermaster picture Dithermaster · Feb 1, 2014

Put a volt meter or oscilloscope on the output pin. Is LOW at 0 volts and HIGH at 5 volts? If so, the software and chip are working fine and your LED is wired so the other side is going to voltage, which means 0 V from the chip will turn it on. It's a common way to drive LEDs since some chips can sink more current than they can source.