Go Down

Topic: Turn on Relay on button press and add time with every other press (Read 311 times) previous topic - next topic

banestrix

I am a noob, I have some knowledge of c and c++ but that is it. I can solder stuff and I have made couple of diy amplifiers. Just got arduino nano and i wanted to do the following but i need your help.

1. On button switch press relay turns on for 10minutes.
2. If no button switch is pressed again it will turn off after 10min.
3. If button is pressed it will add 10min on top of the time that is left.

Ive read that i need millis function (i am reading that now how it works) and by now i have managed to make the onboard led blink for the time that i want :)

I will also need suggestion how to connect the button switch (example: D2 to 100kohm to gnd, D2 to button to +5V)?


6v6gt

Do multiple button presses cause the length of time to be extended by multiples of 10 minutes. Or does a button press simply keep the device alive for another 10 minute period.

mugambi

I will also need suggestion how to connect the button switch (example: D2 to 100kohm to gnd, D2 to button to +5V)?


As far as I can tell , you got the hardware part down pretty well.
To help on code I have to see it , however assuming code works as per logic outlined,  since D2 is the button, where is the relay?

And, pray, if you got this part down right, how are you handling millis overflow every 50+- 20 days? Come to think of it, what's the problem? And by the way say what to @6v6gt?

cloxart

You do not need any resistor if you set the pin as INPUT_PULLUP and I think it may be easier to set up a timer instead of calculating millis()

banestrix

There is no code. I cant ever start because i have no idea how. All that is in my mind is (again I am a noob):
 
 button = how many times the button was pressed
 for (int i=0;i<=button;i++){delay of 10min }
that is it..i really have no idea how to do this..now using google for other simple stuff...
For now i know i must use millis because with delay i cant add more time to the countdown process...

cloxart

the way i would do it is set up a timer (look for timerone library on google) that calls an interrupt routine every (say) 1  second. in the interrupt routine you decrease a variable by 1 (and you do not let it go below 0). if the button is pressed you raise the value of the variable to X (meaning the time you want the relay to stay on) if you want to ADD a set time each time the button is pressed you do INCREASE the variable by X. then you check, if the variable is more than 0 you set the relay ON, if it is 0 you set it OFF. this is the way i usually handle multiple non blocking timers

patduino

Hi Banestrix,

See PM for more, but do you also want a display of some sort to indicate how many minutes are left?

From your posted pseudocode, it looks like you want the timer to extend by an addition 10 minutes for each press, rather than merely restarting the 10-minute timer.


Pat.

There are 10 types of people in the world, those who understand binary, and those that don't.

DannySwarzman

You do not need any resistor if you set the pin as INPUT_PULLUP and I think it may be easier to set up a timer instead of calculating millis()
If you do this, you need to connect the button between the input and ground.

Go Up