Button sensor

Alright, so I’ve been having a problem with a project I named “Button sensor”. What I intend for it to do is check to see if pin 9 is receiving current, and for pin 9 to receive current the button it is connected to would have to be closed (pushed down). When pin 9 supposedly does sense current, it would light up a LED connected to pin 7. Problem is, I think something is internally wrong with my Arduino UNO board. Every time I press the pushbutton connected to pin 9 my whole Arduino shuts off. Every time I release, it turns back on. Throughout all of this, the LED connected to pin 7 will not turn on no matter what, but that’s more so because the whole circuit board shuts off every time it’s supposed to turn on. I tried switching the arguments making it so that if pin 9 was not sensing current, the LED would turn on, and sure enough, it did. This was before I encountered the Arduino shutting off problem. Someone, please help :frowning:

int pinNine = 9;
int pinSeven = 7;


void setup () {
  pinMode(pinNine, INPUT);
  pinMode(pinSeven, OUTPUT);
  Serial.begin(9600);
}
  

void loop () {
  if (digitalRead(pinNine) == HIGH) {
     digitalWrite(pinSeven, HIGH);
  } else {
    digitalWrite(pinSeven, LOW);
  } 
  
}

According to your Fritz, whenever you press the button, you short the 5V to ground killing power to the board. Disconnect the red wire to the switch. Move the white wire (digital input) to where the red wire was. Connect the black wire to a terminal of the switch diagonal to the terminal the red wire was connected. Enable the internal pullup resistor with pinMode(pinNine, INPUT_PULLUP). Then the input will read LOW when the switch is pushed and HIGH when not pushed.

Tutorial

Thanks, dude! :stuck_out_tongue:

it so that if pin 9 was not sensing current,

For future reference an Arduino pin does not and can not sense current. It senses voltage.