user31282: The serial prints are for troubleshooting. All outputs are LEDs for testing purposes. The running 1 and 2 states are sometimes skipped over, but not always. I think this is from the light sensor being bad and jumping up and down, but using a higher value does nothing. I also tested the light sensor in the example program and got 1s and 2s so that really shouldn't be the problem. When it does work and the second light sensor is covered (the one that measures sugar level) it continuously cycles through and never returns to ready state. If more detail is needed please let me know
//Digital Inputs
int measureSwitch = 13; //switch that sets 2 tsp and 1 tsp

//Digital Outputs
int motor = 12;
int buzzer = 11;
int readyLed = 10;
int running1Led = 9;
int running2Led = 8;
int doneLed = 7;
int sugarLevelLed = 6;

//Analog Inputs
int cupSensor = 20; //the light sensor should read 0 when the cup is resting on it
int lightSensor = 100; // the sugar should cover up thelight sensor so the light can pass thru, making it zero

//different run times

int running1Time = 100; //1 tsp tentative times
int running2Time = 250; //2 tsp tentative times
int buzzerTimer = 200; // how long the buzzer will go off for

void setup() {
  Serial.begin(9600);
  pinMode(measureSwitch, INPUT);
  pinMode(motor, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(readyLed, OUTPUT);
  pinMode(running1Led, OUTPUT);
  pinMode(running2Led, OUTPUT);
  pinMode(doneLed, OUTPUT);
  pinMode(sugarLevelLed, OUTPUT);
}

//Ready State

void readyState(){
  digitalWrite(readyLed, HIGH);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, LOW);
}

//Running 1 State

void running1State(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, HIGH);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, HIGH);
}

//Running 2 State
void running2State(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, HIGH);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, HIGH);
}

//Done State
void doneState(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, HIGH);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, HIGH);
  digitalWrite(motor, LOW);
}

//Waiting State
void waitingState(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, HIGH);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, LOW);
}

//Sugar Level State
void sugarLevelState(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, HIGH);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, LOW);
}

void loop() {
  while(analogRead(A0) > lightSensor){ //when there is no cup placed on the 
sensor, be in ready state
    readyState();
    Serial.println("READY STATE");
  }


//when the cup is on the sensor and the switch is set to 1 tsp
    for(int time1 = 0; ((time1 < running1Time) && 
                        (analogRead(A0) < cupSensor) &&
                        (digitalRead(measureSwitch) == HIGH)) ; time1++){                           
    //run the running 1 state for 4 seconds   
      running1State();
      delay(1);

      Serial.println("RUNNING STATE 1");
      Serial.println(time1);



  }



    //when the cup is on the sensor and the switch is set to 2 tsp

    for(int time2 = 0; ((time2 < running2Time) && (analogRead(A0) < cupSensor) 

&& (digitalRead(measureSwitch) == LOW)); time2++){                            

//run the running 2 state for 8 seconds

      running2State();
      delay(1);
      Serial.println("RUNNING STATE 2");
      Serial.println(time2);
      Serial.println(analogRead(A0));

  }



  for(int buzzerTime = 0; buzzerTime < buzzerTimer; buzzerTime++){ 

    doneState();
    Serial.println("DONE STATE");
    Serial.println(buzzerTime);
    delay(1);
  }

  while(analogRead(A0) < cupSensor){
    waitingState();
    Serial.println("WAITING STATE");
  }

  while(analogRead(A1) > lightSensor){
    sugarLevelState();
    Serial.println("SUGAR LEVEL STATE");
  }
}


user30477: Try pulling the output of the light sensor to ground via a 10k resistor, that should calm the values.
Note that you are going to need to completely change the value of the variable lightSensor. This is because it will now be outputting different values due to the extra resistor to ground.

simulate this circuit – Schematic created using CircuitLab

31282: <p>The serial prints are for troubleshooting. All outputs are LEDs for testing purposes. The running 1 and 2 states are sometimes skipped over, but not always. I think this is from the light sensor being bad and jumping up and down, but using a higher value does nothing. I also tested the light sensor in the example program and got 1s and 2s so that really shouldn't be the problem. When it does work and the second light sensor is covered (the one that measures sugar level) it continuously cycles through and never returns to ready state. If more detail is needed please let me know</p>

<pre><code>//Digital Inputs
int measureSwitch = 13; //switch that sets 2 tsp and 1 tsp

//Digital Outputs
int motor = 12;
int buzzer = 11;
int readyLed = 10;
int running1Led = 9;
int running2Led = 8;
int doneLed = 7;
int sugarLevelLed = 6;

//Analog Inputs
int cupSensor = 20; //the light sensor should read 0 when the cup is resting on it
int lightSensor = 100; // the sugar should cover up thelight sensor so the light can pass thru, making it zero

//different run times

int running1Time = 100; //1 tsp tentative times
int running2Time = 250; //2 tsp tentative times
int buzzerTimer = 200; // how long the buzzer will go off for

void setup() {
  Serial.begin(9600);
  pinMode(measureSwitch, INPUT);
  pinMode(motor, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(readyLed, OUTPUT);
  pinMode(running1Led, OUTPUT);
  pinMode(running2Led, OUTPUT);
  pinMode(doneLed, OUTPUT);
  pinMode(sugarLevelLed, OUTPUT);
}

//Ready State

void readyState(){
  digitalWrite(readyLed, HIGH);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, LOW);
}

//Running 1 State

void running1State(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, HIGH);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, HIGH);
}

//Running 2 State
void running2State(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, HIGH);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, HIGH);
}

//Done State
void doneState(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, HIGH);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, HIGH);
  digitalWrite(motor, LOW);
}

//Waiting State
void waitingState(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, HIGH);
  digitalWrite(sugarLevelLed, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, LOW);
}

//Sugar Level State
void sugarLevelState(){
  digitalWrite(readyLed, LOW);
  digitalWrite(running1Led, LOW);
  digitalWrite(running2Led, LOW);
  digitalWrite(doneLed, LOW);
  digitalWrite(sugarLevelLed, HIGH);
  digitalWrite(buzzer, LOW);
  digitalWrite(motor, LOW);
}

void loop() {
  while(analogRead(A0) &gt; lightSensor){ //when there is no cup placed on the 
sensor, be in ready state
    readyState();
    Serial.println("READY STATE");
  }


//when the cup is on the sensor and the switch is set to 1 tsp
    for(int time1 = 0; ((time1 &lt; running1Time) &amp;&amp; 
                        (analogRead(A0) &lt; cupSensor) &amp;&amp;
                        (digitalRead(measureSwitch) == HIGH)) ; time1++){                           
    //run the running 1 state for 4 seconds   
      running1State();
      delay(1);

      Serial.println("RUNNING STATE 1");
      Serial.println(time1);



  }



    //when the cup is on the sensor and the switch is set to 2 tsp

    for(int time2 = 0; ((time2 &lt; running2Time) &amp;&amp; (analogRead(A0) &lt; cupSensor) 

&amp;&amp; (digitalRead(measureSwitch) == LOW)); time2++){                            

//run the running 2 state for 8 seconds

      running2State();
      delay(1);
      Serial.println("RUNNING STATE 2");
      Serial.println(time2);
      Serial.println(analogRead(A0));

  }



  for(int buzzerTime = 0; buzzerTime &lt; buzzerTimer; buzzerTime++){ 

    doneState();
    Serial.println("DONE STATE");
    Serial.println(buzzerTime);
    delay(1);
  }

  while(analogRead(A0) &lt; cupSensor){
    waitingState();
    Serial.println("WAITING STATE");
  }

  while(analogRead(A1) &gt; lightSensor){
    sugarLevelState();
    Serial.println("SUGAR LEVEL STATE");
  }
}
</code></pre>
 30477: <p>Try pulling the output of the light sensor to ground via a 10k resistor, that should calm the values.</p>

<p>Note that you are going to need to completely change the value of the variable <code>lightSensor</code>. This is because it will now be outputting different values due to the extra resistor to ground.</p>



<p><img src="https://i.stack.imgur.com/xip2t.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fxip2t.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>
