Hello, I'm fairly new to Arduino. I want to create a clock that will display the current date and time, based on the system (for example, the program would take my computer's date and time, and put it on the serial monitor). For now, I'd like to just stick to the serial monitor, but in the future I will most likely have it on an LCD display. All I'd like to know is if there are any functions I can create within Arduino, or functions pre-made in libraries that I can use in order to find the system date and time. I would preferably like the date in numbers (just for simplicity). Thank you all for your help, and sorry if I posted in the wrong topic area!
Start by looking at the time library.
http://playground.arduino.cc/code/time
The Arduino does not have a built-in clock in hardware. To get time out of it, you need to build in something like the time library the other poster linked.
That has real limits however. If you unplug or reset the Arduino, the current time is lost and you have to re-set the current time.
What you really want is to buy an inexpensive realtime clock unit that communicates over I2C or similar interface. There are number of those available. You would want one that has a battery backup so it keeps the current time even if it stops getting power from the Arduino. I've seen several of these available online. If you search Adafruit.com for "RTC" you'll find several.
muntasirms:
Hello, I'm fairly new to Arduino. I want to create a clock that will display the current date and time, based on the system (for example, the program would take my computer's date and time, and put it on the serial monitor). For now, I'd like to just stick to the serial monitor, but in the future I will most likely have it on an LCD display. All I'd like to know is if there are any functions I can create within Arduino, or functions pre-made in libraries that I can use in order to find the system date and time. I would preferably like the date in numbers (just for simplicity). Thank you all for your help, and sorry if I posted in the wrong topic area!
muntasirms:
Hello, I'm fairly new to Arduino. I want to create a clock that will display the current date and time, based on the system (for example, the program would take my computer's date and time, and put it on the serial monitor).
This is not as simple as it seems - if I take your requirement literally.
You will need a program running on your PC (perhaps written in Python) which sends the time from the PC to the Arduino. You can't at the same time display things on the Serial Monitor because the connection to the PC is already taken up with the Python program.
Your best bet is probably to use an RTC module as @DuncanC has suggested.
...R
Thank you all for your help! In fact, I am trying to (in the long run) create some kind of watch which will communicate wirelessly with a phone for the time. My brother has been working on the android app development aspect, while he's left me to program the hardware. Our original plan was to send the watch the time through an app in the phone, though with an RTC that removes the point of having that aspect of the app. Thanks again for the help, and if anyone else finds a way to take the system time, let me know.
muntasirms:
Thank you all for your help! In fact, I am trying to (in the long run) create some kind of watch which will communicate wirelessly with a phone for the time. My brother has been working on the android app development aspect, while he's left me to program the hardware. Our original plan was to send the watch the time through an app in the phone, though with an RTC that removes the point of having that aspect of the app. Thanks again for the help, and if anyone else finds a way to take the system time, let me know.
You said:
...if anyone else finds a way to take the system time...
That's the thing. There is no system time on an Arduino. You have to use custom software (like the time library somebody suggested) that runs on the Arduino to try to keep track of the time, and that software is fragile. Anything that changes system timers will screw it up, as will resetting the Arduino, removing power, etc.
Getting time from a smartphone and keeping the time software on the Arduino correct will get messy fast. There are lots of edge cases to deal with. You'll drive yourself nuts.
You are much better off using a battery-backed RTC (Real Time Clock) unit connected to your Arduino. Spend a few bucks on hardware and solve the problem the right way. You can write your program to periodically compare the time from the user's phone to the time reported from the RTC and update the time on the RTC. That way it would set itself, which would be cool. Or you could simply add a set button that would query the phone for the current time and set the RTC, and let the user press the set button when they first start using it.
if the clock is stationary and within the range of wifi, you could put a wifi module and set/update the time with an ntp server.
ethernet module if you have enough wire. ![]()
synch the time on power up, and compare to your arduino's time (Time.h library) with the ntp server periodically (daily or even weekly, perhaps)and update if you have an error.
you'll have a pretty nice clock that can then communicate with the rest of the world (like your android app....)