any professional programer please help whether my program have any error when you are free

This is my program and this is for my final year project.This program is to energising 2 relay after a certain time but then they will close at different timing, like relay 1 will close at 2 min after it is on whereas relay 2 will close at 1min after it is on and this whole process is continuously non stop.
int r1 = 12;
int r2 = 13;

void setup()
{
pinMode(r1,OUTPUT);
digitalWrite(r1,LOW);
pinMode(r2,OUTPUT);
digitalWrite(r2,LOW);
}

void loop()
{
boolean onRA=0;
boolean onRB=0;
boolean a=0;
boolean b=0;

for (onRA=0 ; onRA<30001 ; onRA=onRA+1000)
{
if (onRA == 30000)
{
digitalWrite(r1,HIGH);

for (a=0 ; a<15001 ; a=a+1000)
{
if (a=15000)
{
digitalWrite(r1,LOW);
}
a=0;
}
}
onRA=0;
}

for (onRB=0 ; onRB<30001 ; onRB=onRB+1000)
{
if (onRB == 30000)
{
digitalWrite(r2,HIGH);

for (b=0 ; b<10001 ; b=b+1000)
{
if (b=10000)
{
digitalWrite(r2,LOW);
}
b=0;
}
}
onRB=0;
}
}

How big do you think a Boolean variable is? Certainly not big enough to hold a value of 30000. Perhaps you want to change it to unsigned int or even long.

Also a couple of your IF statements only have one equal sign in them.

If I understood well, should be something like this

int relay1 = 12;
int relay2 = 13;

boolean state = false;
unsigned long prevTime = 0;

void setup()
{
pinMode(relay1,OUTPUT);
digitalWrite(relay1,LOW);
pinMode(relay2,OUTPUT);
digitalWrite(relay2,LOW);
}

void loop(){
  
  //relay 1
  if(millis() - prevTime > 60000 && state == false){ // wait 1 minute to turn on
    digitalWrite(relay1,HIGH);
    state = true;
    prevTime = millis();
  }else if(millis() - prevTime > 120000 && state == true){ // turn off after 2 minutes
    digitalWrite(relay1,LOW);
    state = false;
    prevTime = millis();
  }

}

@gepd
Your getting there, but you can simplify your code even further if you check the time first then the state instead of time AND the state (no need to rewrite certain lines). Also be aware of these big values 60000 and 120000.

To avoid future issues, add UL to the end of them. 60000UL and 120000UL.

Good night all, I have work in the morning.

I would expect any final year student to be aware of the concepts of diagnosis and debugging.

Have you tried your program? If no, why not? A program is not like a work of art that is appreciated for its form. Only its function matters.

What happened?

You have not described what it is supposed to do and what it actually does. This would make it much easier to give advice. The process of describing the problem clearly may help you to see your own mistakes.

...R

Since your pin numbers are constants you should declare them as "const int" and not just "int". That way the compiler can let you know if you accidentally try to change them.

You seem to be using the same 'state' variable for both relay1 and relay2 even though they are turning on and off at different times. That won't work. You can read the state of the output pin (digitalRead(relay1)) so it can act as its own state variable.

Robin2:
I would expect any final year student to be aware of the concepts of diagnosis and debugging.

Have you tried your program? If no, why not? A program is not like a work of art that is appreciated for its form. Only its function matters.

What happened?

You have not described what it is supposed to do and what it actually does. This would make it much easier to give advice. The process of describing the problem clearly may help you to see your own mistakes.

...R

hi, I am a singapore ITE student and the course i take dont have the arduino module so i dont have the knowledge of the concept of diagnosis and debugging
Also my project is about automated green house that have a sprinkler and leds, so relay 1 is for led then relay 2 is for the sprinkler, i want it to like for every 2/3 hour they will on together but off at different timing then the process repeat itself. understand what i mean?

@HazardsMind

do you mean?

if(relay1time==60000UL)
{
digitalWrite(relay1,HIGH);
}

@johnwasser

noted for "Since your pin numbers are constants you should declare them as "const int" and not just "int". That way the compiler can let you know if you accidentally try to change them."

but for second half, i dont quite get wat u mean there

dkzl:
hi, I am a singapore ITE student ....
i dont have the knowledge of the concept of diagnosis and debugging

Are you seriously trying to tell me that you have got through the earlier years of your course without ever having to diagnose or debug problems in a program?

...R

Robin2:
Are you seriously trying to tell me that you have got through the earlier years of your course without ever having to diagnose or debug problems in a program?

Maybe it is like one of those "History and Philosophy of Science" school courses?