Go Down

Topic: Strange LED Behavior when button is pressed  (Read 352 times) previous topic - next topic

austinwryan

So I'm doing a project for school that simulates a controller for a fuel and oxidizer delivery system. If all the conditions are met a button has power sent to it and it is operable when I push the button one LED light (the green one in my case) will light up followed by the other two(white and blue) after 2 seconds. All of the lights will stay on at this point for an additional 10 seconds and then the power supply to the button will be shut off and the lights will be shut off. (there is also another button in the diagram connected to a yellow LED this is unimportant for this problem)

The weird thing though is that the system only works correctly in the configuration shown in the attached file. If I switch the green LED wires with the white or blue it won't work. Also, I don't know why this configuration works at all because the wires are all connected through the breadboard and I would think that if the button is pressed current would be sent to all three. Does anyone have any Idea why this is happening?

My code below.

//===============================================================================================================================================================================================================
// Global Varriables
#include <dht.h>

dht DHT;

#define DHT11_PINTempN2O A0

int PowerButton = 8;
int buttonPin =  5;      // the number of the pushbutton pin
int buttonPin2 =  7;     // number of second push button pin

boolean on = false;
int buttonState =  0;
int buttonState2 = 0;

int ValveN2O =   4;    // the number of the Valves pins
int ValveRP1 =   3;
int ValveHe  =   2;


//===============================================================================================================================================================================================================
void setup() {

  pinMode(buttonPin, INPUT);
  pinMode(buttonPin2, INPUT);

  pinMode(PowerButton, OUTPUT);

  pinMode(ValveHe,  OUTPUT);
  pinMode(ValveRP1, OUTPUT);
  pinMode(ValveN2O, OUTPUT);
  pinMode(buttonPin2, OUTPUT);

  Serial.begin(9600);
}

//===============================================================================================================================================================================================================
void loop() {
  /* defines integer values for pressure within the scope of the loop(local varriable) idk why this cant be a global varriable or be in void setup() real code will name pins
    need to use long int bc its larger outside the range of  int (-32767 and 32767) and inside range of long int (-2147483647 and 2147483647)
  */
  long int PressHe  = 3000000;
  long int PressRP1 = 2700000;
  long int PressN2O = 2700000;

  int DensityRP1   = 795;
  int VelocityRP1  = 1.27;
  float AreaRP1    = 352.44;

  int DensityN2O   = 1221;
  int VelocityN2O  = 6.59;
  float AreaN2O    = 352.44;

  // Calculates Mass Flow Rate of RP-1 and N2O based on pressure difference on the line
  float mflowRP1 =  DensityRP1 * VelocityRP1 * AreaRP1;
  float mflowN2O =  DensityN2O * VelocityN2O * AreaN2O;

  // Temp of N2O line
  int chk = DHT.read11(DHT11_PINTempN2O);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);

  // Pressures in lines
  Serial.print("Pressure He Tank ");
  Serial.println(PressHe);

  Serial.print("Pressure RP-1 line ");
  Serial.println(PressRP1);

  Serial.print("Pressure N2O line ");
  Serial.println(PressN2O);


  // Switch is attached to arduino will not allow process to start unless switched to on position(determines how witch  will turn on)

  buttonState = digitalRead(buttonPin)  ;
  buttonState2 = digitalRead(buttonPin2);


  if (buttonState == HIGH || buttonState2 == HIGH) {
    if (on == true) {
      on = false;
    }
    else {
      on = true;
    }
  }// end Switch logic if statement

  delay(500);

  Serial.println("");
  Serial.println("End Display Paramiters");

  // Runs system if pressures are at operational range
  if  ( 3000000 >= PressHe && 2632500 <= PressRP1 <= 2767500 &&  2632500 <= PressN2O <= 2767500 && -89 <= DHT11_PINTempN2O <= -90.5) { //30 IS REASONABLE ROOMTEMP TO TEST

    digitalWrite(PowerButton, HIGH);

    delay(5000);
    // Once the switch is turned on then this will make the LED's Light up
    if (on == true) {
      {

        Serial.println(" ");
        Serial.println("Switch opeable: Press to run you have 5 seconds");
        Serial.println(" ");

        digitalWrite(ValveHe, HIGH);
        delay(2000);

        digitalWrite(ValveRP1, HIGH);
        digitalWrite(ValveN2O, HIGH);

        delay(10000); // run for 10 sec

        // Temp in N2O Line

        int chk = DHT.read11(DHT11_PINTempN2O);
        Serial.print("Temperature = ");
        Serial.println(DHT.temperature);

        // Pressures in lines
        Serial.print("Pressure He Tank ");
        Serial.println(PressHe) ;

        Serial.print("Pressure RP-1 line ");
        Serial.println(PressRP1);

        Serial.print("Pressure N2O line ");
        Serial.println(PressN2O);

        Serial.print("mflowRP-1 = ");
        Serial.println(mflowRP1);
        Serial.print("mflowN2O  = ");
        Serial.println(mflowN2O);

        digitalWrite(ValveHe, LOW);
        digitalWrite(ValveRP1, LOW);
        digitalWrite(ValveN2O, LOW);

      }// end if true and Run of system

    }

  }

  //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  // if varriables are not in operational range

  if (3000000 < PressHe || 2632500 > PressRP1 > 2767500 ||  2632500 > PressN2O > 2767500 || -89 > DHT11_PINTempN2O > -90.5) {

    on == false;  // Stops button from being operable
    digitalWrite(PowerButton, LOW);

    Serial.println("Switch off: Process will not Run");
    Serial.println(" ");

    delay(3000);

    digitalWrite(ValveHe, LOW) ;
    digitalWrite(ValveRP1, LOW) ;
    digitalWrite(ValveN2O, LOW);

    Serial.println("Temp. out of Range");
    Serial.println("");

    // Temp of N2O line
    int chk = DHT.read11(DHT11_PINTempN2O);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);

    // Pressures in lines
    Serial.print("Pressure He Tank ");
    Serial.println(PressHe);

    Serial.print("Pressure RP-1 line ");
    Serial.println(PressRP1);

    Serial.print("Pressure N2O line ");
    Serial.println(PressN2O);



  } // end else statement for system not running

  //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


  Serial.println(" ");
  Serial.println("LOOP WILL RUN AGAIN after 1 MINUTE UNPLUG CONTROLLER");
  Serial.println(" ");
  Serial.println("-----------------------------------------------------------------------------------------------------------");
  delay(20000);
}// end void loop

//===============================================================================================================================================================================================================









slipstick

I haven't bothered with the program because if the circuit is really wired like that strange Fritzing diagram then it will never work. Half the pin numbers are wrong and all the output pins are shorted together.

Steve


Go Up