Zaksutro:
I've been trying to get this code going for a few days to no avail any help would be greatly appreciated
So did any of the LEDs turn on? Did any pumps turn on?
Can you tell us more about what was unexpected?
It's often helpful to add serial statements to a program so you can monitor which part of the code is running.
I added some serial statements to the simple version of the code.
const unsigned long MILLISECONDS_PER_SECOND = 1000;
const unsigned long ON_TIME_LONGEST = MILLISECONDS_PER_SECOND * 240;
const unsigned long ON_TIME_MIDDLE = MILLISECONDS_PER_SECOND * 30;
const unsigned long ON_TIME_SHORTEST = MILLISECONDS_PER_SECOND * 5;
const unsigned long PIN_LONGEST = 2;
const unsigned long PIN_MIDDLE = 3;
const unsigned long PIN_SHORTEST = 4;
const int GREEN_ON_TIME = 250;
const int GREEN_OFF_TIME = 250;
const byte SECONDS_TO_BLINK = 25;
// "TIMES_TO_BLINK" is calculated from the above three constants.
const byte TIMES_TO_BLINK = SECONDS_TO_BLINK * MILLISECONDS_PER_SECOND / (GREEN_ON_TIME + GREEN_OFF_TIME);
const boolean ACTIVE_STATE = HIGH; // Pin state to turn on the pump
const boolean INACTIVE_STATE = LOW; //!ACTIVE_STATE; // would this work?
const boolean ACTIVE_BUTTON = LOW; // Assumes the pin will be pulled high.
const byte BUTTON_PIN = A3;
const byte RED_LED_PIN = 5;
const byte GREEN_LED_PIN = 6;
void setup()
{
Serial.begin(9600);
Serial.println("Pump Timer Program");
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
digitalWrite(PIN_SHORTEST, INACTIVE_STATE);
pinMode (PIN_SHORTEST, OUTPUT);
digitalWrite(PIN_MIDDLE, INACTIVE_STATE);
pinMode (PIN_MIDDLE, OUTPUT);
digitalWrite(PIN_LONGEST, INACTIVE_STATE);
pinMode (PIN_LONGEST, OUTPUT);
}
void loop()
{
Serial.println();
Serial.println("All Pumps Off");
Serial.println();
Serial.println("Waiting for button press.");
while (digitalRead(BUTTON_PIN) != ACTIVE_BUTTON) {} // wait for button press
Serial.println("The button has been pressed.");
digitalWrite(RED_LED_PIN, HIGH);
// Turn on all the pumps.
digitalWrite(PIN_SHORTEST, ACTIVE_STATE);
digitalWrite(PIN_MIDDLE, ACTIVE_STATE);
digitalWrite(PIN_LONGEST, ACTIVE_STATE);
Serial.println();
Serial.println("All Pumps On");
// Turn off pumps one at a time.
delay(ON_TIME_SHORTEST);
digitalWrite(PIN_SHORTEST, INACTIVE_STATE);
Serial.println();
Serial.println("The first pump has been turned off.");
delay(ON_TIME_MIDDLE - ON_TIME_SHORTEST);
digitalWrite(PIN_MIDDLE, INACTIVE_STATE);
Serial.println();
Serial.println("The second pump has been turned off.");
delay(ON_TIME_LONGEST - ON_TIME_MIDDLE - ON_TIME_SHORTEST);
digitalWrite(PIN_LONGEST, INACTIVE_STATE);
Serial.println();
Serial.println("The last pump as been turned off.");
// All the pumps are off.
digitalWrite(RED_LED_PIN, LOW);
Serial.println();
Serial.print("The red LED is off and the green LED will now blink ");
Serial.print(TIMES_TO_BLINK);
Serial.println(" times.");
// Blink the green LED.
for (int i = 0; i < TIMES_TO_BLINK; i++)
{
digitalWrite(GREEN_LED_PIN, HIGH);
delay(GREEN_ON_TIME);
digitalWrite(GREEN_LED_PIN, LOW);
delay(GREEN_OFF_TIME);
}
Serial.println();
Serial.println("End of loop.");
}
This is the output you should expect.
Pump Timer Program
All Pumps Off
Waiting for button press.
The button has been pressed.
All Pumps On
The first pump has been turned off.
The second pump has been turned off.
The last pump as been turned off.
The red LED is off and the green LED will now blink 50 times.
End of loop.
All Pumps Off
Waiting for button press.
I used an active low button. One side of the button was connected to the Arduino's "A3" pin and the other side connected to ground.
The I/O pins controlling the pumps will be set high to turn on the pumps and set low to turn them off.
You should have a current limiting resistor between the Arduino's I/O pin.
Arduino I/O pin -> resistor -> LED anode |LED| LED cathode -> ground
I think a resistor value of 220 ohm to 1k ohm should work okay with most LEDs.
Do you have the transistors and pumps wired correctly?
Let us know which LEDs are on, and which pumps are active at various points of the program. Use the serial output to help identify which part of the program is running.