hi guys
i'm using arduino mega
i'm trying to turn on a led (on pin 30) when pin 31 goes HIGH
but the problem is when I put a jumper on pin 31 (jumper isn't connected to anything in the other side) led start blinking
and stop after a while but when i move my hand close to the jumper the led start blinking again
so please help me
that's my code:
int Switch = A7;
int flag;
void setup() {
Serial.begin(9600);
pinMode(Switch, INPUT);
pinMode(30,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(Switch)==HIGH){
flag =1;
digitalWrite(30, HIGH);
if(digitalRead(30)==HIGH){
Serial.print("b");
}}
if(digitalRead(Switch)==LOW){
flag =0;
digitalWrite(30, LOW);
if(digitalRead(30)==LOW){
Serial.print("f");
}}
}