I am simulating a circuit with arduino, which determine if there is current at input, then turn the led on at the output. The problem is the light is always on even when the button is open at the input.
This is my code:
void setup() {
pinMode(7, OUTPUT);
pinMode(8, INPUT);
digitalWrite(7, LOW);
}
void loop() {
int on = digitalRead(8);
digitalWrite(7, on);
}
Why does this happen and how do I solve it?
Any help would be appreciated.