Controlling a relay for a set amount of time per hour.

Hello everyone,

I have been playing with my Arduino Mega for a few weeks right now and am a complete newbie. I have managed to get my sketch running with some of the componenets that I am looking for. I am building a reef controller, to control my saltwater fish tank. I already have a sketch running my LED lights, temperature, and clock. I am having a few issues with my relays and my automatic top off system.

I managed to get a relay working with a float switch, it is very simple float switch drops low and turns on the relay. My problem is I am trying to find a tutorial or some code to limit the amount of times that the relay is activated.

I am going to be using a small water pump to pump water from a container to my tank. I need to figure out a way to only allow the relay to activate for a set number of seconds and only allowed to activate 3 times per hour. This is a big safety issue that I need to have in case the relay sticks or in case the float switch malfunctions. Too much water too fast will be a big problem

Any help you can give or direct me to is greatly appreciated.

Thank you,


Similar topic:,117540.0/topicseen.html
count down timer.

Thanks Magician,

the link is similar unfortunately, I do not know how to edit it for my needs. Are they any tutorials that I can research to help?



OdessaDan: Thanks Magician,

the link is similar unfortunately, I do not know how to edit it for my needs. Are they any tutorials that I can research to help?



Take a look at the Blink Without Delay example. Load it, tweak it, and play with it until you completely understand what each part of it does. It's a fundamental concept that should be completely understood before any type of non-trivial timing operations are attempted.

Once you completely understand how it works, you have to decide what "3 times per hour" means. Does that the counter resets at the top of every hour? Do you keep track of the last 3 times it turned on to make sure that there is no more than 3 in any given hour increment? If you fully understand how millis() works, writing the 3-times per hour code should be doable.

sir i am new to arduino , i want to control water pump with dtmf decoder using arduino , i make a program to control the water pump but i also want for mobile charging for two hours , so i want to control the relay for two hours and then trun off for 16 hours , i tried many times but no sucess when i apply a delay function for 2 hour on relay an 16 hour off relay then it does not sense the dtmf decoder output until it reaches upto 2 + 16 hours , i will try using mill function but when time of on and off exceeds more than 1 minute its output remains always high and does not low, please help me, i will try this from seven days

Hi, Welcome to the forum.

This is a very old thread , dated 2012. You would be better to start a new thread for your request.

Please read the first post in any forum entitled how to use this forum.,148850.0.html

If you have some code you will need to post it as well, the link above will tell you how to do it.

The fact that you have attempted to fix your problem is good but we need to see it.

Thanks.. Tom... :)