So, i i was working on a project and asked a friend to code it for me, but the input pins are detecting false inputs.
I tried using a simple code for a push button and an LED and still got the falste input signal, the LED should light on only when the button is pressed, but keeps blinking sometimes by itself, sometimes when i get my hand close to the hardware.
I tried this on 3 different boards (Nano, Original nano, original leonardo), 3 different protoboards, and different jumper cables, and still got the same problems.
The code i asked my friend to make works perfectly for him (he is far away from me)
here is a link to a youtube video showing the problem
Any ideas on what could be causing this interferences?
Yes, i already tried moving to other places in the house.
Here is the code im using for the LED pushbutton test:
int button = 3;
int led = 13;
int buttonState = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(led, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(button);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(led, HIGH);
} else {
// turn LED off:
digitalWrite(led, LOW);
}
}
IDK
The only declared input is pin 3
The only declared output is pin 13
i have connected:
5v-jumper-button-resistor-pin3
pin13-resistor-led-gnd
No floating inputs
Both codes, my friend and me on the same board, wired the same way, for him works, for me not
technically speaking, an input defined as "INPUT" is considered "HIGH". But this "HIGH" is sensitive to noise and can easily go LOW. So, if you have the button to 5V, there is the default HIGH (floating) when not pressed and the 5VHIGH when pressed. When pressed, you should not have fluctuations.
You should go either:
5V-resistor (not more than 20k)-button-gnd, and go to pin from resistor-to-button connection, or
define input as "INPUT_PULLUP" and go : pin-button-gnd. (as previous answer by DELTA_G)
demkat1:
technically speaking, an input defined as "INPUT" is considered "HIGH". But this "HIGH" is sensitive to noise and can easily go LOW. So, if you have the button to 5V, there is the default HIGH (floating) when not pressed and the 5VHIGH when pressed. When pressed, you should not have fluctuations.
You should go either:
5V-resistor (not more than 20k)-button-gnd, and go to pin from resistor-to-button connection, or
define input as "INPUT_PULLUP" and go : pin-button-gnd. (as previous answer by DELTA_G)
YES!
This actually worked!
using another resistor from button to ground solved the problem, now i must try with the big project
TY!