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!
Answer from Dat Ha on Stack ExchangeAn 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.
Get date and time information from laptop
Get current time in arduino?
How to put date and time in arduino code
How to fetch time and date from computer's RTC?
Videos
Hello,
I want to measure the time that takes to transmit a package from arduino to a device connected to the computer. I've thought about taking the current time in arduino when I send the package and take the current time in the Java app that is running in the computer when it receives a packet and then calculate the difference. There is no problem to take the current time in the Java part, but in the arduino's one I don't know how to do it. I've tried the Time library but if I use the now() method I get the time since the code is running. For example I've a delay of 5 seconds in the setup() and then I call the now() method and it returns 5.
Anyone know how to get the current time or have any idea to calculate the transmision time between the two devices?
Thanks!
I'm starting a project with UNO, making a counter counting how many time a door is opened. I'm using an ultrasonic sensor and trying to record the date and time when the door is opened, then print it into the serial monitor.
I plug the Arduino into my PC. Remembering UNO has no built in RTC module whatsoever, how can I record the time with my PC's RTC?