Time Check

HI, im new to using an Arduino. I'm looking into making an "smart garden" with an Arduino Uno. A project that checks soil moisture and turns on LED lights.

At specific times I want to turn on the LED's and check the soil, can I do this without buying an RTC or Wifi adapter?

I want to keep as many pins free as I can to add more sensors later on, i.e temperature, fan, heaters + more LED's, moisture sensors.

I've looked into the blink without delay example but couldn't work out how to make this work like a 24 hour loop?

any advice would be appreciated.
:confused: :confused:

I've looked into the blink without delay example but couldn't work out how to make this work like a 24 hour loop?

Post what you tried, and we can help you with that.

Joebrock:
I want to keep as many pins free as I can to add more sensors later on, i.e temperature, fan, heaters + more LED's, moisture sensors.

The RTC will connect to A4 and A5. You can also connect a number of "port expanders" which add eight or sixteen I/O pins each to the same pins if you needed them, so it makes little sense to try and not use a RTC which is essential if you really want the times to be accurate.

You may be able to keep some modest accuracy of daily event times by tweaking the code and using a daylight sensor to synchronise it (within an hour or so) over the longer term.

Use a RTC -that will be much easier than trying to tune the time using other methods and your code will be much easier to write. I had a project some time back on a processor that did not have a time base as such so I had to fine tune a time base and the fine tuning was a pain - in your case you are looking for a 24 hour time - so you will need to watch the time base run for probably 24 hours to see how accurate it is - then tweak it and watch for 24 hours then repeat - not something I would want to do

Is easy to make the blink without delay measure a 24hr period. The number of milliseconds is simply 246060*1000. But millis() is not super accurate and over a few days it will lose or gain a few seconds, and over a period of months this could grow into a few hours. Plus, the temperature will affect how quickly it looses or gains time. If running on battery power, the battery voltage could also affect the accuracy. This might still be good enough for you, I don't know.

But you also said that you want to do things "at specific times". This is much more difficult without an rtc. You can give the Arduino the current time when you upload your sketch, and it can keep time from there. But as soon as you reset the Arduino, or remove the power, when it starts up again, the Arduino will go back to that time of sketch upload. Alternatively, you can attach a keypad and display, and get the user to key in the time when the Arduino starts up. It's much simpler to use an rtc!

If you get an rtc, look for one based on the ds3231 chip, not the older ds1302 chip. They cost only a little more and are much more accurate and temperature stable.

Thanks for all the replies, looks like the best option is just to buy the RTC.

Joebrock:
Thanks for all the replies, looks like the best option is just to buy the RTC.

Not necessarily.
You could decide to go down a very different path.
i.e. use wifi and ntp for clock synchronization
Once you have wifi, you wouldn't necessarily need an RTC since you can get the datetime from an ntp server.

For example, you could make the leap to leave 8 bit AVR based Arduinos behind and jump to using low cost 32 bit ESP8266 based devices to get gobs more speed, flash(4-16 megabytes vs 32k), RAM, wifi, on board file system support. And no more odd ball PROGMEM stuff to deal with.
With wifi, lots of things become possible including integrating into existing home automation systems like IFTT and openHAB, which can integrate into things like Alexa.

With WiFi you could also configure and control your device using a web page which can likely reduce the cost and complexity of the h/w since no added h/w is needed for a user interface.

--- bill

bperrybap:
For example, you could make the leap to leave 8 bit AVR based Arduinos behind and jump to using low cost 32 bit ESP8266 based devices…

Why not use a ESP32 based device?
Which adds two cores, real multitasking and a massive amount of special hardware modules.

Whandall:
Why not use a ESP32 based device?
Which adds two cores, real multitasking and a massive amount of special hardware modules.

Sure. It costs a little bit more and is a little bit bigger but has also more capabilities.