How to turn of relay after X seconds, if current temperature is Y celsius?

Hi Smart Arduiners :slight_smile:

I want to create system with two relays, 1 switch and 1 DS18b20 temp. sensor.
Switch turns on the relay1, if current temperature >= 30, relay1 turns off and relay2 turns on for 5 seconds and then turns off.
The main problem, that i am new with arduino and electronics, i watch many tutorials and suggestions about "blink without delay", but i can't to adjust it to my project to work correctly. Delay() and millis() does not work as I want too..
Maybe someone of You has encountered with this problem and can help me. Thank You.

}
else if (currentTemp >= 30 ) {
Relay1_state = 0;
digitalWrite(7, LOW);
TurnOnValve();

}
}

void TurnOnValve(){
digitalWrite(6, HIGH);
delay(5000);
digitalWrite(6, LOW);
}

Well, if you're using BWOD, then don't use delay() AT ALL.

Think about it. Think about how you might do it if you had a wall clock and a piece of paper to write numbers on.

Something happened. Look at the clock, write down that time and write that the something ocurred. Now you want to do something else 5 minutes after that something. So look at the clock and look at the time you wrote. Has 5 minutes passed? Do this as rapidly as possible.

When you get to 5 minutes, do the something-else AND rub out the note that the something occurred. You are now in the state where you are waiting for the something to happen again.

"Delay() and millis() does not work as I want too.."
Where is your attempt at using BWD?

Linis:
Switch turns on the relay1, if current temperature >= 30, relay1 turns off and relay2 turns on for 5 seconds and then turns off.

You must first be very clear about what you want. That is, need to define everything very clearly.

For example...... switch turns on the relay1 if current temperature >= 30, relay1 turns off .....

In the above, you have not clearly defined conditions for which relay 1 is meant to turn off. You have simply written 'relay1 turns off'. And then you need to define the conditions needed for this event ... 'and relay2 turns on for 5 seconds, then turns off'.

So, in order to effectively/efficiently make your system do what you want it to do, you will need to define everything very clearly.

Also, note that in your original post, you put a comma in "Switch turns on the relay1**,** if current temperature >= 30"

I assume that the comma is not supposed to be there. If you put in a comma when there is not meant to be one, then things start to become uncertain or confusing.

Just in case you don't know what BWD means, it is Blink Without Delay.