Loading...
Pages: [1]   Go Down
Author Topic: Push Button Not Working  (Read 435 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  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:
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.
« Last Edit: February 18, 2013, 07:21:45 pm by Coding Badly » Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 43
Posts: 2518
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Need to see your circuit. How is the button wired?

Edit: Easy enough to test a switch, use the circuit below.
« Last Edit: February 18, 2013, 06:00:43 pm by Jack Christensen » Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

The Netherlands
Offline Offline
Sr. Member
****
Karma: 9
Posts: 331
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 41
Posts: 5176
CMiYC
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.cmiyc.com/tutorials/arduino-pull-ups/
Logged

www.cmiyc.com - A guide to being an Enginerd

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 "-").
« Last Edit: February 26, 2013, 10:08:02 pm by Darwoon » Logged

Pages: [1]   Go Up
Print
 
Jump to: