0

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

}
2
  • 1
    Please explain what is and isn't working. Commented Mar 9, 2019 at 20:54
  • How do you know the first is working? You're setting a pin low. Commented Mar 10, 2019 at 1:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.