0

I'm very new to Arduino, so please forgive me if I don't know the proper terms for things.

Whenever I press the button on the board, the LEDs all shut off.

Button Not Pressed Button Is Pressed

I can't host the image files on imgur, and I don't know how well Flikr will work with it.

Now:

The resistors being used are 220 ohm resistors for the LEDs. The one for the button is a 10k ohm resistor.

This also happens without a resistor in place. I tried simply replacing the button with a wire from the positive to a row, with a wire leading from there to another row, back to ground.

What do I do to fix this?

Edit: Sorry about the images being extremely low quality, they've been updated.

Here's the code, but it's mostly irrelevant:

//DEFINE STUFF BABYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
int ButtonState2 = 0;
int ButtonState1 = 0;
int ButtonState0 = 0;
const int ButtonPin2 = 2;
const int ButtonPin1 = 1;
const int ButtonPin0 = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(6, LOW);
  digitalWrite(5, LOW);
  digitalWrite(4, LOW);
  digitalWrite(3, LOW);
  pinMode(ButtonPin2, INPUT);
  pinMode(ButtonPin1, INPUT);
  pinMode(ButtonPin0, INPUT);
  Serial.print(78);
}

void loop() {
  // put your main code here, to run repeatedly:
  ButtonState2 = digitalRead(ButtonPin2);
  ButtonState1 = digitalRead(ButtonPin1);
  ButtonState0 = digitalRead(ButtonPin0);
  if (ButtonState2 == HIGH){
    digitalWrite(13, HIGH);
    }
    else{
      digitalWrite(13, LOW);
      }
}
0

2 Answers 2

1

As per your statement, wire from the positive to a row, with a wire leading from there to another row, back to ground.

That describes a short circuit between V+ and ground.

Remove either the ground wire or the positive wire.

1
  • 1
    This fixed the issue. I removed the ground wire, and the resistor. Dec 9, 2019 at 17:28
1

You have your switch shorting both pin 1 and V+ to ground when you press the switch. Do not do that.

The resistor you have isn't doing anything at all. It isn't really a meaningful part of your circuit. It is in the middle of one of the rows of your breadboard. All the pins in the same side of one row of the breadboard are connected to each other.

In your breadboard, every row, from 1 to 30, is divided into columns a-e and columns f-j. All the pins a-e in a row are connected to each other, and all the columns f-j are connected to each other. You have one end of your resistor in row 7, column g, and the other end in row 7, column h. So the resistor is short-circuited by the breadboard, and doesn't serve any purpose.

It's as if both ends of your resistor are connected to different points on a wire. If you were to measure the resistance between the leads of that resistor as it's connected, you'd get zero ohms.

You need to rearrange your wiring so you have a wire coming from +5V to one row of your breadboard. Let's call that the +5V row. Have a 10K resistor with one lead into another pin in that row, and then put the other end of the resistor into another row. Let's call that the pull-up row. (It's weakly connected, through a 10K resistor, to +5V. Now plug your switch into that row, also. Finally, run a wire from the opposite side of the switch and into ground.

Make sure to configure the pin as an INPUT.

If you set it up as an OUTPUT, set it to HIGH, and close the switch, you'll short the pin output to ground, probably destroying that pin's output driver. DON'T DO THAT.

Now, when the switch is open, the pull-up resistor weakly connects the pin to +5V, so you get a HIGH signal. When you close the switch, it shorts the pin to ground, pulling the input LOW.

Note that you could skip the connections to +5V and set the pin to INPUT_PULLUP mode instead. INPUT_PULLUP mode connects the pin to +5V internally, through a high ohm resistor.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.