I am using the pin 4 as an OUTPUT and pin 8 as an INPUT to turn on/off the light, but for some reason it is not working. Light is on all the time, but when I try to input something it gets brighter and doesn't turn off when I don't give anything to pin 8.
LED is connected to pin 4 with a 220 R, and the other side to GND. When pin 8 is connected to 5V pin then the light should come on, and off when I disconnect them.
Here is the code:
void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(8, INPUT);
}
void loop()
{
bool on = digitalRead(8);
if(on)
{
digitalWrite(4, HIGH);
}
else
{
digitalWrite(4, LOW);
}
}
What am I doing wrong?