Trouble w/ Push Buttons

Hello,

I am doing Project 5 from Arduino Workshop by John Boxall. It may be found here - https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CB8QFjAA&url=http%3A%2F%2Fnostarch.s3.amazonaws.com%2Farduino_project5.pdf&ei=6cpbVf7HGovXsAWH6YHQBg&usg=AFQjCNERF2uvzzIyeQ9ANHubh0d0X4-3nw&bvm=bv.93756505,d.b2w&cad=rja

I modified the code, but not the loop structure; it may be found here - http://pastebin.com/xBT8TQDw

The programme is proceeding, as evidenced by executing the content of the loop, as if the buttons are continuously pressed (i.e. westButton and eastButton = HIGH). It will wait no longer than 10s, then the lights will cycle through and proceed to the second loop.

Any help would be appreciated.

Please supply YOUR code.

Please put your code in its own window as seen in other posts. This can be done by placing     [code] and [/code]  around the code. This makes it easier for others to read.

Weedpharma

Thanks for the reply. As mentioned before, my code may be found in the pastebin here:

// Project 5 - Controlling Traffic
 
 
// define the pins that the buttons and lights are connected to:
#define westButton   35
#define eastButton   39
#define westRed      43
#define westYellow   47
#define westGreen    51
#define eastRed      45
#define eastYellow   49
#define eastGreen    53
#define yellowBlinkTime 500                     // 0.1 seconds for yellow light blink
boolean trafficWest = true;                     // west = true, east = false
int flowTime = 10000;                           // amount of time to let traffic flow
int changeDelay = 2000;                         // amount of time between color changes
 
 
void setup()
{
    pinMode(westButton, INPUT);
    pinMode(eastButton, INPUT);
    pinMode(westRed, OUTPUT);
    pinMode(westYellow, OUTPUT);
    pinMode(westGreen, OUTPUT);
    pinMode(eastRed, OUTPUT);
    pinMode(eastYellow, OUTPUT);
    pinMode(eastGreen, OUTPUT);
 
// set initial state for lights - west side is green first
 
    digitalWrite(westRed, LOW);
    digitalWrite(westYellow, LOW);
    digitalWrite(westGreen, HIGH);
    digitalWrite(eastRed, HIGH);
    digitalWrite(eastYellow, LOW);
    digitalWrite(eastGreen, LOW);
}
 
void loop()
{
  if ( digitalRead(eastButton) == HIGH )     //changing from west to east        
  {
    if ( trafficWest == true )
    {
    trafficWest = false;
    delay(flowTime);
    digitalWrite(westGreen, LOW);
    digitalWrite(westYellow, HIGH);
    delay(changeDelay);
    for ( int a = 0 ; a < 5 ; a++ )
    {
      digitalWrite(westYellow, LOW);
      delay(yellowBlinkTime);
      digitalWrite(westYellow, HIGH);
      delay(yellowBlinkTime);
    }
    digitalWrite(westYellow, LOW);
    digitalWrite(westRed, HIGH);
    digitalWrite(eastRed, LOW);
    digitalWrite(eastGreen, HIGH);    //traffic now east
    }
  }
  if ( digitalRead(westButton) == HIGH )   //changing from east to west
  {
    if ( trafficWest != true )
    {
    trafficWest = true;                
    delay(flowTime);                  
    digitalWrite(eastGreen, LOW);      
    digitalWrite(eastYellow, HIGH);
    delay(changeDelay);
    for ( int a = 0; a < 5; a++ )        
    {
      digitalWrite(eastYellow, LOW);
      delay(yellowBlinkTime);
      digitalWrite(eastYellow, HIGH);
      delay(yellowBlinkTime);
    }
    digitalWrite(eastYellow, LOW);
    digitalWrite(eastRed, HIGH);
    digitalWrite(westRed, LOW);
    digitalWrite(westGreen, HIGH);    //traffic now west
    }
  }
}

Have you tied the inputs to 5v or gnd?

Weedpharma

I set up the schematic in accordance with the instructions - https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CB8QFjAA&url=http%3A%2F%2Fnostarch.s3.amazonaws.com%2Farduino_project5.pdf&ei=6cpbVf7HGovXsAWH6YHQBg&usg=AFQjCNERF2uvzzIyeQ9ANHubh0d0X4-3nw&bvm=bv.93756505,d.b2w&cad=rja

Your buttons will always be high unless pressed.

The original code has a test to see if they a not high, IE, pressed.

Look at the original and fix up yours.

Weedpharma

weedpharma: Your buttons will always be high unless pressed.

You sure?- the linked doc shows pull downs methinks.

I stand corrected.

Weedpharma

What happens when you run the unmodified code from the Workshop?

I constructed a second experiment designed to determine the state of the buttons:

#define westButton   35
#define eastButton   39

#define east         40
#define west         36

void setup() 
{
    pinMode(westButton, INPUT);
    pinMode(eastButton, INPUT);
    pinMode(west, OUTPUT);
    pinMode(east, OUTPUT);


// set initial state for lights - west side is green first

    digitalWrite(east, LOW);
    digitalWrite(west, LOW);

}

void loop()
{
  if ( digitalRead(eastButton) == HIGH )        
  {
    digitalWrite(east, HIGH);
  }
  if ( digitalRead(westButton) == HIGH )  
  {
    digitalWrite(west, HIGH);
  }
    if ( digitalRead(eastButton) == LOW )        
  {
    digitalWrite(east, LOW);
  }
  if ( digitalRead(westButton) == LOW )  
  {
    digitalWrite(west, LOW);
  }
}

The schematic is attached.

When I ran the experiment, both LEDs were on. Pressing the buttons made no change.

How do I set this up so that when the button is pressed, westButton and eastButton change from either high to low, or low to high?

The matter is resolved; the push buttons were improperly placed. Such is the joy of near four-fold symmetry.

Always wire to the diagonals of those square tactile switches. That way the orientation doesn't matter. (Not possible on a breadboard though, unless you cut off two of the legs.)