int LEDPin=6;
int buttonPin=12;
int buttonRead;
int dt=100;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LEDPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonRead=digitalRead(buttonPin);
Serial.println(buttonRead);
delay(dt);
if(buttonRead==1){
digitalWrite(LEDPin, LOW);
}
if(buttonRead==0){
digitalWrite(LEDPin, HIGH);
}
}
Hello guys,
I have got a problem with my pushbutton circuit.
I have got an Arduino Uno, all connected, in the right port.
I wanted to create a circuit which will turn the LED on as I push the button, but there is a problem. My serial monitor only reads 1, when I push the button it does not show 0 and the LED does not turn on. I'm pretty sure that I got all of it connected it the right way, the right pins etc. I have tried all of the cables that I used in this circuit by connecting them to the resistor to LED and 5V and they were good. I used 10k ohms resistor, which seems to be working because I attached LED to it and it worked. I also tried replacing the pushbuttons, but none of the 4 that I have worked. Please help.
I also attach the picture of my breadboard.
Have a nice day
larryd:
Actually the OPs connections should work as is, external pull-up.
It might be that I can't see the photos properly, but it looks to me like one side of the button is grounded and the other side has a pull DOWN resistor.
I think it's most probably that your switch isn't making good contact into the protoboard. Those square ones are absolutely terrible for breadboard use and can screw up the internal connections if you aren't careful when trying to shove them in.
Congratulations on posting good images and the sketch properly !
So I have connected pin12 to GND and indeed I got 0, which I think indicates that it's LOW.
Then I tried switching the buttons and most of them did not work, but it turned out that 1 out of 5 buttons from my kit works :). What's funny is that yesterday I have tried all of them and none worked. Maybe some of them will work tomorrow, who knows?
So what new pushbuttons should I order? The ones that @Jiggy-Ninja mentioned are currently unavailable.
would these work properly? I presume that the pushbuttons that I have right now do not make a good contact with the breadbork, as someone suggested above. These ones have longer legs, so maybe they will work better?
Also, I have got a similar problem with my potentiometer. It does not always work properly and I have to push it in order to read from it. Can anyone recommend me a good potentiometer, which would work properly?
The first link you posted looks fine. It's basically the same switches I linked to, just a different size head on them.
The other two are terrible. Especially the 3rd one. It's the same as what you already used, just a different sized head. Avoid those. Maybe the 2nd one's OK, but you'd have to see the pin spacing to be sure.