Go Down

Topic: Code required to run a task at set time daily. (Read 413 times) previous topic - next topic

Yahenda

Hello all,

I have a ridiculously simple task I need some help with... I've built a robotic cat laser toy and I want it to turn on at a specified time of day, run for a few minutes, then turn off, and have that repeat daily.

I have an Elegoo Uno r3 (with shield) attached to a turret with a couple of servos, a laser, and a DS-3231 RTC module. From testing, they all seem to be connected properly.

I've already got the code sorted for when it's on (moving the laser about somewhat randomly with short intervals), what I need is code to set/keep time and start and stop the movement every day.

Please let me know what else you need to know about my setup. I know it's not a complex thing I'm looking for, but I've tried to teach myself and I just don't have the patience or maybe the aptitude to learn this whole new language when, at this point, all I really want to do with it is build this toy :)

Thanks very much for your time.

-Yahenda

wvmarle

I'd figure a small adaptation to the examples that come with the various DS3231 libraries should do the job.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

patduino

#2
Mar 12, 2019, 05:35 am Last Edit: Mar 12, 2019, 05:36 am by patduino
Hi Yahenda,

Here's a thought.  Why not simply plug the system into a timer?  You could modify the sketch to only run for a short amount of time then stop.  The next day the timer will restart the system...  every day.

Plus the system won't need to be powered all of the time.

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

Yahenda

I'd figure a small adaptation to the examples that come with the various DS3231 libraries should do the job.
Hi wvmarle, thanks for the reply... I've tried with DS3231 libraries' examples but I can't get the unit to learn and keep time... I know what you call a small adaptation seems simple to you, but as I said, it's a whole other language to me. If it's really that simple, please, by all means tell me exactly what to do and I will try! :D

Thx

Yahenda

#4
Mar 12, 2019, 07:35 am Last Edit: Mar 12, 2019, 07:36 am by Yahenda
Hi Yahenda,

Here's a thought.  Why not simply plug the system into a timer?  You could modify the sketch to only run for a short amount of time then stop.  The next day the timer will restart the system...  every day.

Plus the system won't need to be powered all of the time.

Pat.
Hi patduino... Thanks for the idea... what kind of timer are you talking about? Is it something that might be included in some of the starter kits one can by? I've got the 'UNO R3 Project Super Starter Kit' and a Elegoo v2.0 - 37 sensor kit. Any specifics would help.

Thanks

wvmarle

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

patduino

wvmarle,

Yes, exactly like that.  Just a simple timer that automatically turns a lamp on / off in the evening.
There are 10 types of people in the world, those who understand binary, and those that don't.

cedarlakeinstruments

#7
Mar 12, 2019, 12:43 pm Last Edit: Mar 12, 2019, 12:47 pm by cedarlakeinstruments
Yahenda,
The actual code to turn things on and off at specific times using the RTC library is pretty simple. I have a series of Arduino programs that does something very similar: changes the selling price of an item based on the time of day.

In my experience, the harder part is setting the time of day (setting the clock) and setting your feeder on/off times. You can do it with various types of user interfaces: from the serial connection, with a touchscreen, or with an LED and a couple of pushbuttons.

It's trivial to hardcode these things, but changing them tends to require a fair amount of code because anything that is going to be adjusted by an actual person requires a lot of error-handling work. That's where most of the work (and cost) comes in.

If you'd like me to modify the code I have for your use, send me a PM. However, I think you'll find it's simpler and costs less to just use an off the shelf timer like patduino suggested. Blatant self-promotion, but I also sell these timers

:-)
Electronics and firmware/software design and assistance. No project too small

blimpyway

I would rather put a start button and let the cat push it whenever it likes.

Yahenda

wvmarle,

Yes, exactly like that.  Just a simple timer that automatically turns a lamp on / off in the evening.
patduino and wvmarle - Thanks for your suggestions, I believe you're right, that's the most straightforward solution... and just now, as your suggestion got me thinking outside of the 'project kit' box... I realized I've got some wifi sockets for my lamps controlled by my Google Home mini! I could create a routine that turns the laser on and off daily, automatically... and I've already got the stuff I need right here, right now! XD

The BEST feeling. Thank you!



It's trivial to hardcode these things, but changing them tends to require a fair amount of code because anything that is going to be adjusted by an actual person requires a lot of error-handling work. That's where most of the work (and cost) comes in.

cedarlakeinstruments - I think you get what I'm saying exactly... Although it would be fascinating to deep dive into all the possibilities, realistically it's a larger investment than I'm prepared to make right now, for this. Thanks for the coding offer and don't worry about self-promo, we all could use some - when we're all a little shameless, there's no shame ;)



I would rather put a start button and let the cat push it whenever it likes.
blimpyway - I like that idea very much! I will look into that, too :D



martinius96

I have solution for that via external webserver for Arduino with Ethernet shield. If some interested, PM.
Arduino and website programmer

cedarlakeinstruments

I have solution for that via external webserver for Arduino with Ethernet shield. If some interested, PM.
Maybe it's just me, but this seems like so much overkill for a basic timer.
Electronics and firmware/software design and assistance. No project too small

KASSIMSAMJI

Maybe it's just me, but this seems like so much overkill for a basic timer.
mee too
Expert To Be: Machine Learning And Computer/Machine Vision (ML/CV/MV)

Go Up