Pages: [1]   Go Down
Author Topic: Push Button Not Working  (Read 2204 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: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
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.


* ledSwitch.png (3.4 KB, 131x472 - viewed 7 times.)
« Last Edit: February 18, 2013, 06:00:43 pm by Jack Christensen » Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

The Netherlands
Online Online
Edison Member
*
Karma: 50
Posts: 1649
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

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

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6146
Baldengineer
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

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

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
Jump to: