Arduino Output Problem

I am facing a total weird problem one set of code is running and other ain't. Kindly help

This code isn't working :confused:

int pin = 2;
void setup() {
  // put your setup code here, to run once:
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);
}
void loop() {
     // put your main code here, to run repeatedly:
 
}

This code is working

int pin = 2;
void setup() {
  // put your setup code here, to run once:
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(pin,HIGH);
  delay(5000);
  digitalWrite(pin,LOW);
  delay(5000);

}

How are you verifying that the first code isn't working?

by applying on digitial sensor

Give us more information, much more.

i am using the pin 2 to control the LED
in both codes the led is set digitialWrite(pin,LOW); but in one code the led is not setting off......it is should be off in both codes because it is set a low digitialWrite(pin,LOW);

imran403:
i am using the pin 2 to control the LED
in both codes the led is set digitialWrite(pin,LOW); but in one code the led is not setting off......it is should be off in both codes because it is set a low digitialWrite(pin,LOW);

Doesn't follow at all. The LED is on when current flows through it. That can be due to a pin being HIGH,
or it can be due to a pin being LOW, depending on how its wired up.

You haven't shown how you've wired it up...

here is the diagaram

With the first code, you never set the pin High to turn the LED on.

Add
digitalWrite (pin, HIGH);
instead of LOW
after the pinMode statement if you want LED to turn on.

Another Fritzy for the Hall of Shame!

You have to admire the handsome USB plug, presenting itself to the USB port.

@CrossRoads
its WOrking......Yep
Thanks!