Hi i am new here and i am trying to do one mini project that is

ON relay 1 and wait for 30 seconds and then turn on relay 2 and wait for next 90 seconds and then turn off both relay 1 and relay 2 for next 120 seconds and turn on rely 1 and wait for 30 seconds and then turn ON relay 3 for next 120 seconds and repeat the above cycle.
here is my program.
int pin8 = 8;
int pin7 = 7;
int pin9 = 9;

void setup() {
// Initialize the pins as outputs
pinMode(pin8, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin9, OUTPUT);
}

void loop() {
// Cycle 1: Pin 8 ON, wait 30 seconds
digitalWrite(pin8, HIGH); // Turn ON pin 8
delay(30000); // Wait for 30 seconds (30000 ms)

// Pin 7 ON
digitalWrite(pin7, HIGH); // Turn ON pin 7
delay(90000); // Wait for 90 seconds (90000 ms)

// Turn OFF both pins 7 and 8
digitalWrite(pin7, LOW); // Turn OFF pin 7
digitalWrite(pin8, LOW); // Turn OFF pin 8
delay(120000); // Wait for 120 seconds (120000 ms)

// Pin 8 ON again, wait 30 seconds
digitalWrite(pin8, HIGH); // Turn ON pin 8
delay(30000); // Wait for 30 seconds (30000 ms)

// Pin 9 ON
digitalWrite(pin9, HIGH); // Turn ON pin 9
delay(90000); // Wait for 90 seconds (90000 ms)

// Turn OFF both pins 9 and 8
digitalWrite(pin9, LOW); // Turn OFF pin 9
digitalWrite(pin8, LOW); // Turn OFF pin 8

// After completing the cycle, the program loops back to the start
}

please guide me.

relay is not operating as expecting it remains turn ON.

Which relay ?
At the end of your loop where.

// Turn OFF both pins 9 and 8
digitalWrite(pin9, LOW); // Turn OFF pin 9
digitalWrite(pin8, LOW); // Turn OFF pin 8

There is no Delay and relay 8 is turned ON at the top of the loop.

Relay 8 will turn OFF and ON so fast you will not notice the OFF.

Welcome to the forum.

When you paste code, use the <CODE/> button in the message composition window and do what it says

type or paste code here

so it looks like code as seen in #3. It helps if you use the IDE autoformat tool if you've not yet made writing code in a standard format a habit.

As for the relays, I think @mikedb is correct.

Add

  Serial.begin(115200);

to you setup() function, then put a print statement where the problem is, viz:

// Turn OFF both pins 9 and 8
digitalWrite(pin9, LOW); // Turn OFF pin 9
digitalWrite(pin8, LOW); // Turn OFF pin 8

Serial.println("relays have been switched off");

delay(1000);    // and see what happens when you don't hang out a bit

// After completing the cycle, the program loops back to the start
}

HTH

a7

1 Like

@alto777

HTH .. Here To Help?

1 Like

"Hope That Helps".

But Here To Help works too.

a7

1 Like

I thought it was Happy to Help...

2 Likes

yes, I don't want time delay to turn on pin 8 output initially but in the further loop relay not operating as expected. relay not turning OFF properly.

Hi

I think you will have to add the delay to notice the Relay turning OFF. It may also help if you tell why you dont want a delay but want to turn the relay off. This will help us give you a solution tailored to your project.

@akash55mhatre

Your code switch relay 8 OFF and microSeconds later ON , so what do you want to achieve by this?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.