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 Answers 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!


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.


One possibility to consider is to use a 24-hour plug-in timer that controls the power to the Uno.

I.e. something that looks like this:

enter image description here

The circuit would be: AC outlet -> Timer -> USB charger -> Arduino

You could set the timer to turn off the power to the Uno at say 11:30 PM and turn on again on midnight.

Under such setup, millis() will be the time since the last Uno start, which will usually be the time since the previous midnight.

When debugging, you could set the time-at-Uno-start to other than midnight.

The caveats are:

  • Your situation allows for daily 30-minute (or whatever the timer increments are) downtime
  • Can tolerate timer shifts due to power outages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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