Hi,
I am relatively new to arduino...
I am trying to figure out the best way to program a trigger time delay relay. So basically, every time when a digital pin receives a LOW input signal, then i need to set an output pin as HIGH for 30 seconds...
But every time the input becomes low, the timer needs to be reset..
So if the input becomes low twice within 20 secs, once at 10secs and once at 20secs, then the timer would keep the output pin HIGH until 50secs have passed (20secs + 30secs).
Can anyone help?
Ask me if you don't quite understand the concept! Its a strange one!
Thanks
What's difficult?
Count the number of button pressings and watch the time when they are pressed, and regard the current timer situation.
Hi, thanks for your reply. The thing i find difficult is being able to write the code really.. Would you be able to either write a bit for me or advise me on how to go about it?
Thanks
Don't look at the key board. Plan the code, the flow of the logic.
This is not a give away code shop. You do the coding.
What functions do i need to use to make it work?
Look for topics telling how to use the millis() function.
So you want a timing function that can be retriggered each time an input ‘LOW’ is received ?
Have you studied the basic programming examples that are included in the IDE ?
Do you understand the difference between monitoring an input while at LOW and ‘when’ an input goes LOW ?
What electronics and programming experience do you have ?
Why are you wanting to do this ?
jack789_arcademan:
So basically, every time when a digital pin receives a LOW input signal, then i need to set an output pin as HIGH for 30 seconds...
But every time the input becomes low, the timer needs to be reset..
So if the input becomes low twice within 20 secs, once at 10secs and once at 20secs, then the timer would keep the output pin HIGH until 50secs have passed (20secs + 30secs).
This is confusing. Do you mean that every time the input triggers the timer should run for thirty seconds? First time 30s, second time add 30s to whatever time is remaining? Can the timer be triggered again and again, adding 30s each time?
dougp:
This is confusing. Do you mean that every time the input triggers the timer should run for thirty seconds? First time 30s, second time add 30s to whatever time is remaining? Can the timer be triggered again and again, adding 30s each time?
Yes, I need it to add 30secs to the remaining time every time it is triggered
Then detect button changed from inactive to active and add 30 to the timer.
timeRemaining = timeRemaining + 30000;
Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.
Hello.
Can take a few moments to Learn and Use The Forum
It will help you get the very best out of the forum in the future.
-
Your OS and version can be valuable information, please include it along with extra security you are using. Antivirus etc.
-
Always list the version of the IDE you are using and the board version if applicable.
-
Use quote or add error messages as an attachment NOT a picture.
-
How to insert an image into your post. ( Thanks @sterretje )
-
Add your sketch where applicable but please use CODE TAGS
-
Add a SCHEMATIC were needed even if it is hand drawn
-
Add working links to any specific hardware as needed (NOT links to similar items)
-
Remember that the people trying to help cannot see your problem so give as much information as you can
COMMON ISSUES
-
Ensure you have FULLY inserted the USB cables.
-
Check you have a COMMON GROUND where required. ( Thanks @Perry)
-
Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.
-
Try other computers where possible.
-
Try other USB leads where possible.
-
You may not have the correct driver installed. CH340/341 or CP2102 or FT232 VCP Drivers - FTDI
-
There may be a problem with the board check or remove your wiring first.
-
Remove any items connected to pins 0 and 1.
COMPUTER RELATED
-
Close any other serial programs before opening the IDE.
-
Ensure you turn off any additional security / antivirus just to test.
-
There may be a problem with the PC try RESTARTING it.
-
You may be selecting the wrong COM port.
-
Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.
-
Clear your browsers CACHE.
-
Close the IDE before using any other serial programs.
-
Preferably install IDE’s as ADMINISTRATOR or your OS equivalent
ARDUINO SPECIFIC BOARDS
-
CH340/341 based clones do not report useful information to the “get board info” button.
-
NANO (Old Types) some require you to use the OLD BOOTLOADER option.
-
NANO (ALL Types) See the specific sections lower in the forum.
-
NANO (NEW Types) Install your board CORE’s.
-
Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default “AVRISP mkII”.
-
Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.
CREATE editor install locations.
-
On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini
-
On Linux ~/ArduinoCreateAgent-1.1/config.ini
-
On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1
Performing the above actions may help resolve your problem without further help.
Language problem ?
Try a language closer to your native language:
Thanks to all those who helped and added to this list.
This is a function called a "retriggerable monostable".
In the loop, you monitor the input. While ever it is LOW, you keep the output HIGH and set an unsigned long variable such as "lastlow" to the current millis() value.
If in the loop you find the input is HIGH, you first check to see if your output is HIGH; if it is presently LOW there is no need to do anything. If however it is HIGH, then you subtract "lastlow" from the current millis() value and see if the result is greater than 30000UL, in which case you set the output LOW.
In other words, you keep the output HIGH until 30 seconds after the input goes HIGH - and stays HIGH for that period.
Please correct the subject line in your first post - you foolishly had Caps Lock on.
Paul__B:
This is a function called a "retriggerable monostable".In the loop, you monitor the input. While ever it is LOW, you keep the output HIGH and set an unsigned long variable such as "lastlow" to the current millis() value.
If in the loop you find the input is HIGH, you first check to see if your output is HIGH; if it is presently LOW there is no need to do anything. If however it is HIGH, then you subtract "lastlow" from the current millis() value and see if the result is greater than 30000UL, in which case you set the output LOW.
In other words, you keep the output HIGH until 30 seconds after the input goes HIGH - and stays HIGH for that period.
Please correct the subject line in your first post - you foolishly had Caps Lock on.
Thanks for your reply, any chance you can help me with the code, as I am not great at working out what the code will require.
Caps lock issue resolved
Thanks
The keys to unlock your problem are all in the examples.
I think the example "button" shows you how to see a change of state of a switch.
"Debounce" shows how to see a button press
"Blink without delay "
Shows how to do timing.
I think i would increment 30SecDelay by 1 for each button press
Then decrement 30SecDelay by 1 for each timing cycle.
Increment 30SecDelay by 30000
more thoughts :
for each button press, 30SecDelay is incremented by 30 seconds
the timing would be :
this is not code, just ideas on how things might set set up
loop()
ButtonState = digitalRead(button)
if (thing == ON ) {
if (millis() - buttonTime) >= 30SecDelay {
turn the thing off.
}
}
if (thing == OFF ) {
if there is a new button press
ButtonTime = millis() ; // only do this one time from off to on.
// after that, you only add 30 seconds
if(lastButtonState == HIGH & ButtonState == LOW) { // new change
thing = ON ; // OK to turn a thing that is on, to be on again.
30SecDelay = 30SecDelay + 30000 ; // 30,000 = 30 seconds
..other things here
.. before end of 'loop()'
lastButtonState = ButonState ;
} // ==== END LOOP
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.