Controlling two solenoids with millis (if/else).

Hi,

I'm just new to the Forum and really hope someone can help me. I have a small aeroponics setup (used to grow plants).

I'm controlling one solenoid with my Arduino Uno. Its working great up to this point with the current code I wrote, but I want to expand and control a second solenoid which can be controlled from the same arduino and code but with a different timing.

int solenoid1 = 13;
const long offTime = 720000; //Time solenoid1 is off
const long sprayTime = 5000; //Spraytime for solenoid
1
int defaultState = LOW; //initial state of solenoid
1

long rememberTime = 0;

void setup() {

pinMode (solenoid1, OUTPUT);
digitalWrite (solenoid1, defaultState); //setting initial solenoid state
}

void loop() {

unsigned long currentTime = millis();

if (defaultState ==LOW)
{
  if (  (millis() - rememberTime) >= offTime){
  defaultState = HIGH;
  rememberTime = millis();
  }
}
else 
{
   if(  (millis() - rememberTime) >= sprayTime){
    defaultState =LOW;
    rememberTime = millis ();
   }
 }

digitalWrite (solenoid1, defaultState);

}

Already great thanks to anyone that can help me.

Cheers,

Maarten

What are your timing requirements for the 2nd solenoid?

To which pin will it be connected?

Copy the nice code You have, just create a second defaultTime, defaultState, remember... output pin etc.
It will work fine!

Hello Maarten,
Welcome
++Karma; // For posting your code correctly on your first post.

Minor point:

int solenoid1 = 13;

13 is the built in LED, maybe use a different pin for the solenoid.