Hi. I have a strange problem. I have 2 different arduino one arduino nano and uno. They have different code but both auto execute the code at random times without me pressing any button. In both arduino I have to press a button to start the code but is auto start. Why this is happening? Is this normal? Any advice?
(deleted)
sorry for that. here is my code. i have wire the button like in the image i have attach.
int button=2; // koumpi ekinisis
int previousPin = 3; // proigoumeno koumpi mp3 player
int pausePin = 4; // pouse tou mp3 player
int kefalia=10; // kanonika 5 volt
int kefali=8; // kefali me dc down
int kapnos = 9; // kapnomixani
void setup(){
pinMode(button, INPUT_PULLUP);
pinMode(kefalia, OUTPUT);
pinMode(kefali, OUTPUT);
pinMode(previousPin, OUTPUT);
pinMode(pausePin, OUTPUT);
pinMode(kapnos, OUTPUT);
digitalWrite(previousPin, HIGH); //button mp3 player
digitalWrite(pausePin, LOW); // button mp3 player
delay(100);
digitalWrite(pausePin, HIGH); //button mp3 player
digitalWrite(kefalia, HIGH); //kounima kefalion
digitalWrite(kefali, HIGH); //kounima kefali
digitalWrite(kapnos, HIGH); //kapnomixani
}
void loop(){
if (digitalRead(button) == HIGH) {
//Sound!
digitalWrite(pausePin, HIGH);
delay(100);
digitalWrite(previousPin, LOW);
delay(100);
digitalWrite(previousPin,HIGH);
//kounima kefalion
digitalWrite(kefalia, LOW);
digitalWrite(kefali, LOW);
delay(200);
digitalWrite(kapnos, LOW);
delay(3000);
digitalWrite(kapnos, HIGH);
delay(3000);
digitalWrite(kapnos, LOW);
delay(12000);
digitalWrite(kefalia, HIGH);
digitalWrite(kefali, HIGH);
delay(100);
digitalWrite(kapnos, HIGH);
delay(100);
digitalWrite(previousPin, HIGH);
delay(100);
digitalWrite(pausePin, LOW);
delay(100);
digitalWrite(pausePin, HIGH);
delay(1000);
}
else {
digitalWrite(kefalia, HIGH);
digitalWrite(kefali, HIGH);
digitalWrite(kapnos, HIGH);
}
}

image (see the forum sticky threads to find out how this is done):
Your code puts button on pin 2. Your schematic shows pin 7.
(deleted)
aarg:
Your code puts button on pin 2. Your schematic shows pin 7.
The image is for reference only so you can see how I wired the button. I have connected to pin 2.
spycatcher2k:
With input pullup, you dont need a resistor. Just a connection to pin 2, other side of button to ground.
also if (digitalRead(button) == HIGH) should be if (digitalRead(button) == LOW) as the input is HIGH until the button is pressed.
So I need to remove the resistor and connect it directly to min 2 and gnd? Then change the code to “if (digitalRead(button) == LOW)“ ?
klemo4:
The image is for reference only so you can see how I wired the button. I have connected to pin 2.
I'm sorry, must have missed that in my crystal ball..
klemo4:
So I need to remove the resistor and connect it directly to min 2 and gnd? Then change the code to “if (digitalRead(button) == LOW)“ ?
Correct
TimMJN:
I'm sorry, must have missed that in my crystal ball..
Correct
Ok I will try it that way. Thanks for the help I appreciate it.
Thanks everyone it work now. I have let it idle for more than 12 hours and no more auto start.