Hello, I want to stop relay after 30 seconds, but I couldnt make it, I dont want to use delay(); function because other functions of my code must work. I tried something below, but not working,
(1) I do not see a setup() function.
(2) I do not see a loop() function.
(3) I do not see a declaration for the variable relaymod.
(4) I cannot see how function relaymode() is called.
(5) Isn't relaymod always set to '1' when the if statement is executed?
(6) If relaymode() is called more than once every 30 seconds (probably, but I cannot be sure) then newtime-oldtime will always be less than 30000.
To post code and/or error messages:
Use CTRL-T in the Arduino IDE to autoformat your complete code.
Paste the complete autoformatted code between code tags (the </> button)
so that we can easily see and deal with your code.
Paste the complete error message between code tags (the </> button)
so that we can easily see and deal with your messages.
If you already posted without code tags, you may add the code tags by
editing your post. Do not change your existing posts in any other way.
You may make additional posts as needed.
Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.
If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.
my sketch is so big and complicated, I cannot share it here. I need a code only will stop when work after 30 seconds. I have a relay, I want only stop my relay after 30 seconds later from open. if you have a solution you can write it here please, if you have not, stop writing any fool things..
LarryD I didnt say something to you and all people in this forum, But somebody in this forum what they want to make I didnt understand. They only write foolish things, rebuke and inversion.
Aleyna:
my sketch is so big and complicated, I cannot share it here.
And there's your first problem. You have written a big, complicated sketch when you don't know how to turn a relay on for 30 seconds without delay().
Your function always opens the relay every time it is called. Pull out the first bit - the bit that opens the relay - into its own function. You call that when the relay needs to become open, and you call the other function every loop() to check if it's time to close it again.