running 2 for loop simultenously

greetings guys.

I just went over some tutorials to do this;

int Pump1 = 3;
int Light1 = 4;
int Pump2 = 10;
int Light2 = 11;

void setup() {
   Serial.begin(9600);
   pinMode (Pump1, OUTPUT);
   pinMode (Light1, OUTPUT);
   pinMode (Pump2, OUTPUT);
   pinMode(Light2, OUTPUT);
}

void loop() 
{
  digitalWrite(Light1,HIGH);
  for(int a=0; a<32; a++){
    for(int b=0;b<10;b++){
      digitalWrite(Pump1,HIGH);
      delay(18000);
    }
    for(int c=0;c<100;c++){
      digitalWrite(Pump1,LOW);
      delay(18000);
    }
  }
  
  digitalWrite(Light1,LOW);
  for(int d=0;d<16;d++){
    for(int e=0;e<10;e++){
      digitalWrite(Pump1,HIGH);
      delay(18000);
    }
  for(int f=0;f<100;f++)
  {
    digitalWrite(Pump1,LOW);
    delay(18000);
  }
  }
  digitalWrite(Light2,HIGH);
  for(int i=0; i<32; i++){
    for(int j=0;j<10;j++){
      digitalWrite(Pump2,HIGH);
      delay(18000);
    }
    for(int k=0;k<100;k++){
      digitalWrite(Pump2,LOW);
      delay(18000);
    }
  }
  
  digitalWrite(Light2,LOW);
  for(int l=0;l<16;l++){
    for(int m=0;m<10;m++){
      digitalWrite(Pump2,HIGH);
      delay(18000);
    }
  for(int n=0;n<100;n++)
  {
    digitalWrite(Pump2,LOW);
    delay(18000);
  }
  }
}

my question is how to run Light1 loop and Light2 loop at the same time?

the relay for Light2 and Pump2 doesn’t switch on.

You can't run 2 FOR loops simultaneously because a FOR loop must complete before the code moves on.

What you can do is carry out several activities in a single FOR loop. Or you can dispense with the FOR loop altogether and rely on the iterations of loop() and a variable to keep track of the stage that each process has reached. Move one step in each iteration of loop() or move one step after N millisecs()

You should get an idea of how this is organized in several things at a time and in planning and implementing a program.

...R

...however... your for loops don't seem to do much except create delays and repeating the same writes over and over, which effectively does nothing at all. What are you trying to do?

Robin2:
You can't run 2 FOR loops simultaneously because a FOR loop must complete before the code moves on.

What you can do is carry out several activities in a single FOR loop. Or you can dispense with the FOR loop altogether and rely on the iterations of loop() and a variable to keep track of the stage that each process has reached. Move one step in each iteration of loop() or move one step after N millisecs()

You should get an idea of how this is organized in several things at a time and in planning and implementing a program.

...R

hmm I see..

aarg:
...however... your for loops don't seem to do much except create delays and repeating the same writes over and over, which effectively does nothing at all. What are you trying to do?

Im building a little hydroponic system.

Requirement is to turn on Light 1&2 for 16hours, while Pump1&2 has a cycle turning on for 3 minutes then off 30minutes.

That dosn't explain why you constantly turn things on. Just once will do.

newbie2arduino:
my question is how to run Light1 loop and Light2 loop at the same time?

How do you cook meat and potatoes at the same time? If you can answer that you can work out how to fix your code.

See my link above for tips.

See your PM