Simple Arduino LED on off timer sketch

billybob983

New member
I hate to do it as I wanted to search for it, but I have to ask. Anyone know of a simple Arduino schematic/sketch? I just want to turn LEDs on and then off. No dimming, nothing! No meanwells, nada, straight on and off! Of course it would be on a 24hr timer programmable through the sketch.

Thanks.
 
I don't think the arduino has a built in RTC. You will need to add additional components if you want a real clock that holds time and date when power is lost.
 
Your LEDs still will need a driver, to control current to the string. On/off can be had with a simple driver and a extension cord timer... If simplicity is the goal, going to an arduino for that function seems silly.
 
I have a RTC already on the arduino Mega with a 20x4 screen giving me a reliable title, am/pm clock, water temp readings with hot and cold relay (in this case LED's for now) functions. I just need to learn some button logic code for the pumps and feeding and the lights. I know absolutely NO coding from scratch whatsoever, but, if I can find a sketch of one working channel of lights or a light bulb for that matter, driven by a timing scheme/sketch, I can work it out from there like I have with everything else. I will just use some transistors to drive the circuit, maybe even a mosfet or relay or????

I already have the lights and things on a timer(s) cord(s). Problem is, they get out of sync. I want everything on one clock. I am also making a power bar like neptunes for the whopping price of $15 to tie it all in. Then I can bring my push button logic to turn on lights when I want them on and then back to normal routine when I am done playing.

I have searched google until I was blue in the face and just have not found what I am looking for, per above requirements. Found just about everything else for blinking LED's and such...............but. I was hoping someone might know a link I missed for the lights.

Edit: Did I mention I will be using the sketch to turn on and off the skimmer and return pump at sep times also?
 
Last edited:
Ah, well that is a different story all together. Do you have the relay board for flipping the switches on the AC side? Knowing what the relay board is expecting as a signal will help narrow down what sort of code you need on the arduino. Simple ones will probably want a digital 5V signal per relay, so a pin per relay is necessary. That is as simple as assigning a pin to be a output, wiring it to the relay input, telling it to go high.
 
Yes, exactly. As of now, I have a 8 analog relay board to be fitted inside a 8 plug power strip which will be connected via VGA cord. I am just going for the simple 5v signal to "x" component to SS or analog relay. I need to get a schematic for the board but i think it is already setup to just use the 5v from the arduino. I also think running 8 of them would drain the arduino so I may need a separate circuit. I will check into that later. Setting the "int" for the relay is easy. I have NO idea about making the code for the timing. Once I see it, I can duplicate it. I just need to see it, lol, based off a 24 hour clock schedule. Getting tired of finding the romper room "delay 2000 on" "delay 2000 off" sketches. I know where getting into "milli" territory here and possibly more. Lots of PWM circuits also that are killing me (as far as not being what I want). I am afraid I am almost all searched out.
 
I don't know much about firing off things based off events or interrupts and whatnot, but i think you could have a simple loop checking the time every X often, then if that matches certain conditions fire off the required code. There is a time library that lets you get the hour() and minute(). Checking if the time is 10am would be seeing if hour() is 10, then if minute() is 0. Once both are true, fire the lights on code and return to the time checking loop when done. Or if you don't want to use ifs you can use a switch... If you check too fast, you will fire that code many times obviously, even checking it every 30 seconds would possibly fire it twice. You could check only every minute, or check however fast you want and put an extra variable for has the code run today, which is set to true the first time its run and set to false at midnight or when the code to turn whatever it was off is run.

Pseudocode...
bool lightsOn = false

while true{
switch (hour()){
case 0 ... case 9
break
case 10
if lightsOn == false{
run lightsOn()
lightsOn = true}
break
case 11 ... 21
break
case 22
if lightsOn == true{
run lightsOff()
lightsOn = false}
break
}
pause X
}

May not be efficient, and 'programming' the relay times involves changing the actual sketch... This also is only checking every hour interval, but you can add further checks in those hour slots you care about to check down to whatever increment you want. Aiming for a window too small (like an exact second) could result in it never happening if you check only every 10 seconds or so, so be aware of that.
 
Last edited:
Back
Top