3

I'm working on a project using Arduino Uno and SD card shield. I'd like to store a variable at a specific time everyday in the SD card. How can I get the current time in Arduino ? Any help would be appreciable.

NOTE : Arduino is NOT connected to PC.

3

An accurate enough way is to use the millis() function. It will return the value in milliseconds since the start of the Arduino. If you start the Arduino at a specific time, you will be able to calculate the exact date and time.


Why not an external module?? An RTC such as the DS3231 in merely 5$ and it includes a temperature sensor for you!

2

without external source

You can't. The Arduino Uno has no real-time clock. A real-time clock is only something like $1 from eBay. For example the DS1307 or DS3231. I found 5 x boards pre-assembled with the clock chip, including battery holder, crystal, chip, and circuit board for $US 4.20 on eBay. Batteries not supplied.

Hook that up to the I2C pins (A4 and A5), set the time once using a suitable sketch, and then you are ready to roll.


If you just want to do something every 24 hours (not necessarily at 9:36 a.m.) then you can just use millis to find when the appropriate number of milliseconds has elapsed. The result from millis will wrap every 49 days roughly but you don't have to worry about that.

Note that this won't let you log the date and time, but you can log something (eg. the temperature) every day, you would just have to know when you started logging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.