Digital read going crazy

First of all,i don't know if this category is the right one and i'm new to arduino.I'm using digital read on push button with my 12V 1A power supply when i plug in the power supply the value is 0 and 1 but when i plug it off the value is what it should be.I hope

Your topic was MOVED to its current forum category as it is more suitable than the original

Please post uour sketch and a schematic of your project. A 'photo of a pencil and paper drawing is good enough

Const int button = 7;
Const int output_1 = 8;

Int button_value = 0;

Void setup() {

pinMode(button, INPUT);
pinMode(output_1, OUTPUT);
Serial.begin(9600);

}

Void loop() {

button_value = digitalRead(button);
Serial.println(button_value);

if (button_value == 1){
  digitalWrite(output_1, HIGH);
}
else{
digitalWrite(output_1, LOW);
}
}

I'd wire that differently, essentially you're leaving that input pin floating.
Wire button one end from the input pin, other end to GND and define it as INPUT_PULLUP instead of INPUT. The button will read LOW when pressed and HIGH when not pressed.

Hello
Post a real schematic to see how we can help.

It worked,thank you so much

Cool!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.