[Solved] Four Condition If statement

I am hoping someone might be able to point me in the right direction. I would like to set global variable cycleCounter to 4 only if four conditions are simultaneously met. The four conditions are:

Switch0 == LOW Switch1 == LOW Switch2 == LOW cycleCounter = 0

My sketch compiles fine. When I run it on my Arduino Uno R3, I am able to watch the status of the three switches and the cycleCounter variable on my terminal by utilizing the serial print command.

When Switches 1,2,3, and cycleCounter are all equal to zero(0), the value of cycleCounter does not increase to four(4) like I want it to. It simply stays at zero(0). I cannot figure out why?

The Arduino is being used to control a model roller coaster for my son. I am a mechanical engineer with very limited programming experience, so please take it easy on me.

Thanks in advance for any helpful suggestions.


Here is what I think are the relevant parts of my sketch:

// map the input pin numbers to integer variables
const int S0 = A0;   
const int S1 = A1;
const int S2 = A2;

//Global Variable Initialization
// set cycleCounter to 0
 int cycleCounter = 0;
// the following code only runs only once during setup:
void setup() {                

  // define these pins as inputs with an internal 20k ohm pull-up resistor
  pinMode(S0, INPUT_PULLUP);
  pinMode(S1, INPUT_PULLUP);
  pinMode(S2, INPUT_PULLUP);
//initialize all inputs to high during setup (ie. switch is off)
  digitalWrite(S0, HIGH);
  digitalWrite(S1, HIGH); 
  digitalWrite(S2, HIGH); 
 //initialize serial communication with terminal 

 // Call closeGates function to close the gates 
 // Call returnCarsToStart function to move cars to the "start" position 

// the following code runs over and over again forever.
void loop() {

  //print the state of all switches and the cycleCounter to the terminal
    Serial.print ("  ");
    Serial.print ("  ");
    Serial.print("  ");
    Serial.println("  ");
    delay (500);
  // call the checkStartButton function to check the status of the momentary start push button

// All functions defined below.

void closeGates(){
//...lots of working code here
void returnCarsToStart (){
 //...lots of working code here

 void checkStartButton(){
  // this function checks if the startButton (ie. switch S0) has been pressed.
  // if the startButton is pressed while the coaster is in operation (ie. cycle counter > 0), nothing happens.
  // if the startButton is pressed when the coaster is idle (ie. cycleCounter = 0) and there is a car
  // at both the station (ie. switch S1 = 0) and there is a car at the brake run (ie. switch S2 = 0), 
  // then the cycleCounter is set to 4.
  // the cycle counter decrements by 1 each time a station motor delay is completed.
  // read the state of digital pins S0,S1,S2 and assign to local integer variables
  int Switch0 = digitalRead(S0);
  int Switch1 = digitalRead(S1); 
  int Switch2 = digitalRead(S2); 
  if ((Switch0 == LOW)  && (Switch1 == LOW) && (Switch2 == LOW) && (cycleCounter = 0)) {
   cycleCounter = 4;

if ((Switch0 == LOW) && (Switch1 == LOW) && (Switch2 == LOW) && (cycleCounter = 0))

Count the = in each part of this test.

UKHeliBob, Thank you for your quick response.

I changed the "=" to a "==" and the problem is now solved.

Mental block on my part. I thought "==" was used to compare with HIGH and LOW and "=" was used to compare with integers.

Here is the corrected code in case someone looks at this post in the future.

if ((Switch0 == LOW)  && (Switch1 == LOW) && (Switch2 == LOW) && (cycleCounter == 0)) {
   cycleCounter = 4;