1

I made a circuit where when I press a button, a LED lights up using a pull-down resistor. But when I tried the same with a pull-up resistor instead, the LED remains off (whereas I expected it to be on by default and go off when I push the button). What is the problem?

Here is the circuit:

enter image description here

And here the code:

int BUTTON = 7;
int LED = 8;

void setup()
{
  pinMode(BUTTON, INPUT);
  pinMode(LED, OUTPUT);
}

void loop()
{
  digitalWrite(LED, digitalRead(BUTTON));
}
7
  • 1
    Is that LED the right way around? The cathode side or the more negative side is the one with the cut-off edge, and while it's really hard to see from those kinds of drawings, if looks like anode is drawn towards the ground there, so the wrong way around. Commented Feb 11, 2021 at 18:25
  • Try connecting the button to 5V, you have no signal transition. With a pull up the switch has to ground it. With a pull down the switch needs to drive it high. Commented Feb 11, 2021 at 20:12
  • @ilkkachu yes, I just displayed it incorrectly in the picture. Commented Feb 12, 2021 at 12:03
  • @Gil but the button is connected to 5V via the 10K resistor. As is shown in circuit diagrams online. Commented Feb 12, 2021 at 12:04
  • 1
    The drawing looks good, except for the LED. The code looks also good. So, show us the picture of your real circuit on breadboard. There may be a chance that your breadboard's broken. Commented Feb 13, 2021 at 11:17

0

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.