0
votes

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

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:

}

And at the same time this is not 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);

}
1
Please explain what is and isn't working.Jennifer Goncalves
How do you know the first is working? You're setting a pin low.TomServo

1 Answers

1
votes

Try putting an LED on your D2 pin to check whether it lights up or not. Make sure to add a resistor (220 ohm or 330 ohm) before the LED. Also, LED has polarity. The small leg should be towards the ground and the long leg (anode) should be towards the D2 pin.

If you don't have an LED or resistor, try using Serial.print() to display whether the system is going through your code or not. You can view your serial response through your serial monitor.