Go Down

Topic: Push Button Not Working (Read 3306 times) previous topic - next topic


Feb 18, 2013, 11:45 pm Last Edit: Feb 19, 2013, 01:21 am by Coding Badly Reason: 1
 I am having difficulty using a Push Button to start a sequence of flashing LEDs.  I know I have wired it correctly, as when I remove the Button, the LEDs flash in the sequence I programmed them to.  I believe the problem may be with the Button itself, however, I am not sure.  If it may help in solving the problem, I have included my sketch.

Code: [Select]
const int ledOne = 13;
const int ledTwo  = 12;
const int ledThree = 8;
const int buttonPin = 4;
const int delayPeriod = 1000;

int buttonState = 0;

void setup()
 pinMode (ledOne, OUTPUT);
 pinMode (ledTwo, OUTPUT);
 pinMode (ledThree, OUTPUT);
 pinMode (buttonPin, INPUT);

void loop()
 buttonState = digitalRead(buttonPin);
 if(buttonState == HIGH)
   digitalWrite (ledOne, HIGH);
   delay (delayPeriod);
   digitalWrite (ledTwo, HIGH);
   delay (delayPeriod);
   digitalWrite (ledThree, HIGH);
   delay (delayPeriod);
   digitalWrite (ledOne, LOW);
   digitalWrite (ledTwo, LOW);
   digitalWrite (ledThree, LOW);

Moderator edit: [code] [/code] tags added.

Jack Christensen

Feb 18, 2013, 11:52 pm Last Edit: Feb 19, 2013, 12:00 am by Jack Christensen Reason: 1
Need to see your circuit. How is the button wired?

Edit: Easy enough to test a switch, use the circuit below.


Be sure you always know the state of that button of yours.
What is the state when the button is not pushed ?
What is it when the button is pushed ?

If you enable the pullup at your input pin and connect the button to GND, then you'll have a HIGH when the button is not pushed, and a LOW when the button is pushed.
If you only have it at some level (either HIGH or LOW) when the button is pushed, what state will it be in when the button isn't pushed ?
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html


You aren't enabling the internal pull up, so are you using an external one?

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com


Feb 27, 2013, 03:53 am Last Edit: Feb 27, 2013, 04:08 am by Darwoon Reason: 1
I think you have not wired the button correctly.
Pin4 -> button "+"
pull-up resistance (like 10kOhm) -> button "+"
button "-" ->GND

If you have four wires onto your push button, make sure the "+" and "-" are in the same side (so not "+" in front of "-").

Go Up