suwn
May 16, 2023, 11:10am
1
always returns 1, even if i dont press it or and even if i remove the button.
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(6,INPUT);
int ingedrukt = 0;
}
int ingedrukt = 0;
void loop() {
Serial.println(ingedrukt);
ingedrukt = digitalRead(6);
}
Is it because of hardware or software?
Welcome to the forum
Could it be that the input is floating at an unknown voltage ?
It is impossible to see how your circuit is wired from the picture. Please post a circuit diagram. A picture of a hand drawn schematic is good enough
Try using INPUT_PULLUP in pinMode() and wiring the circuit to take the input pin LOW when the button is pressed
suwn
May 16, 2023, 11:21am
5
that did not work, it just always returns 1 now. ill go make the circuit diagram on tinkercad if thats good
My guess would be that you have the switch wired wrongly. Use a jumper wire to take the input LOW instead of the switch
If you use the switch connect to 2 diagonally opposite pins to ensure that the connection is actually across the switch and not 2 shorted terminals
suwn
May 16, 2023, 11:29am
8
the diagram, there are also some led on other side but not relevant i think
Yes, thats what it looks like in the picture.
@suwn
Connect the button using the pins on opposite corners.
1 Like
suwn
May 16, 2023, 11:32am
11
thank you, this solved it. i followed the picture on the arduino site, but i switched sides yeah my bad.
AI generated content and direct replies deleted.
suwn
May 18, 2023, 8:44am
13
now i have another button who also isnt working, but i have 2 that work. do you know what could be wrong?
suwn
May 18, 2023, 8:44am
14
now i have another button who also isnt working, but i have 2 that work. do you know what could be wrong
Perhaps it is wired wrongly. Are you connecting to diagonally opposite pins on the switch ?
suwn
May 18, 2023, 8:50am
16
if im correct yes. this is the same way the other switches are also set up
It is impossible to tell from the photo exactly how the switch is connected. Where does the yellow wire connect to and what is the purpose of the resistor that may, or may not, be connected to the switch ?
Write a short sketch that simply reads the state of the input pin associated with the switch and test it
suwn
May 18, 2023, 9:08am
18
the yellow wire is for the button next to it, that button works.
but this one doesnt.
idk why i need a resistor thats just how i learned it in class. i know i can just do it with input_pullup but it makes no difference for me, then it just always returns 1\
void setup() {
Serial.begin(9600);
pinMode(6, INPUT);
}
void loop() {
Serial.println(digitalRead(6));
}
@suwn ,
Reply #19 was spam, no idea if the code was any good but as I deleted #19 I also deleted your reply to the spam.
1 Like
JCA34F
May 18, 2023, 9:48am
22
Connect the pulldown resistor from GND to the same wire that goes to the input pin.
suwn
May 18, 2023, 9:51am
24
i tried a different wiring and it worked thx for the help