SOLVE
The problem is the wire.
My wire for switch is jumper cable, and each other closer (touch) to each other cable. I try to separate, and works. There is no other pin will be trigger.
I would like to know.
I have Pin 2 and 3 as INPUT_PULLUP. I have switch to each other pin. Why when I press switch at PIN 2. SOMETIMES PIN 3 also getting input. Why?
How to fix this? Is it common problem with arduino?
My program is basic. It should be nothing wrong with program.
UPDATE
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 5;
int switch1 = 6;
int switch2 = 7;
int switch3 = 8;
int switch4 = 9;
int led = 13;
//int counter = 0;
void setup()
{
// put your setup code here, to run once
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
pinMode(switch4, INPUT_PULLUP);
pinMode(led, OUTPUT);
}
void loop()
{
if (digitalRead(switch1) == 0){
digitalWrite(led1, HIGH);
}
if (digitalRead(switch1) == 1){
digitalWrite(led1, LOW);
}
if (digitalRead(switch2) == 0){
digitalWrite(led2, HIGH);
}
if (digitalRead(switch2) == 1){
digitalWrite(led2, LOW);
}
if (digitalRead(switch3) == 0){
digitalWrite(led3, HIGH);
}
if (digitalRead(switch3) == 1){
digitalWrite(led3, LOW);
}
if (digitalRead(switch4) == 0){
digitalWrite(led4, HIGH);
}
if (digitalRead(switch4) == 1){
digitalWrite(led4, LOW);
}
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
}
SCHEMATIC (Example only one input, the rest (other 3 input) is similar schematic.
My input only like that, simple schematic.
For output only goes to led, resistor, and ground.