Questions tagged [time]

Use this tag for questions regarding how to get the time on an Arduino, how to create or use clocks with an Arduino, or anything that has time as a substantial factor in it. Also consider using [programming] or other more specific tags.

Use this tag for questions regarding how to get the time on an Arduino, how to create or use clocks with an Arduino, or anything that time would be a substantial part of the problem/question.

Also consider using or other tags specific to your problem.

212 questions
135
votes
4 answers

How can I handle the millis() rollover?

I need to read a sensor every five minutes, but since my sketch also has other tasks to do, I cannot just delay() between the readings. There is the Blink without delay tutorial suggesting I code along these lines: void loop() { unsigned long…
Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81
20
votes
5 answers

How do I get an accurate time?

I've made a clock using an Arduino, but the time seems to drift. I am aware of the rollover issue; the clock seems to drift by about 15 minutes over the course of a week. I'm using a custom PCB with this resonator from Digi-key. The code reads the…
John Walthour
  • 323
  • 1
  • 3
  • 8
15
votes
3 answers

Is it possible to find the time taken by millis?

The function millis would be running in the span of 100+ microseconds or less. Is there a reliable way to go about measuring the time taken by a single millis call? One approach that comes to mind is using micros, however, a call to micros will…
asheeshr
  • 3,847
  • 3
  • 26
  • 61
12
votes
3 answers

High precision timing on Arduino for serial communication

I am using an Arduino Uno to send time and voltage information over the serial port to Python to plot. However the interval timings between successive time stamps appears to be increasing over time, affecting my plotting. This is especially true…
hawkar
  • 553
  • 2
  • 6
  • 12
12
votes
4 answers

Arduino Time Clock Accuracy

I'm currently trying to create an Arduino time clock by using the PJRC Time library (http://www.pjrc.com/teensy/td_libs_Time.html). I know that since most of the Arduino boards are running with a 16MHz clock and a single resonator, the time can…
KK6FSL
  • 125
  • 1
  • 1
  • 6
10
votes
3 answers

Arduino time keeping using millis() is not accurate or correct?

I have been using the Arduino to record some data. In my Arduino sketch I also used the millis() function so I can keep track of the time at which each value I am measuring is taken. However, I noticed that the timing isn't correct. For example 30…
hawkar
  • 553
  • 2
  • 6
  • 12
10
votes
3 answers

Convert to and from Unix Timestamp

What is the best way to convert between date, hours, min, seconds to Unix timestamp in milliseconds in Arduino? I need to have this conversion, since I'm using RTC (date, hours, min, secs etc) and communicating Unix timestamp over BLE I found some…
Dzung Nguyen
  • 417
  • 1
  • 8
  • 17
10
votes
5 answers

Can I make delayMicroseconds more accurate?

I'm trying to bit bang DMX data and that requires 4us pulses. Not having much luck with the results I'm checking to see how good the Arduino is at delaying... Seems to be pretty terrible at it. Here's a quick little test I did: unsigned long…
bwoogie
  • 203
  • 2
  • 9
10
votes
5 answers

Why is my real time clock getting the wrong time from my PC?

I want my real-time clock to set its time as the time on my PC. However, when I run the following sketch, the real-time clock reports the time as being 32-33 seconds earlier than my PC says the time is. #include #include…
lunafish
  • 101
  • 1
  • 1
  • 4
10
votes
3 answers

How to get current time and date in arduino without external source?

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.
Mohamed Mbarki
  • 131
  • 1
  • 2
  • 6
8
votes
1 answer

The difference between "time_t" and "DateTime"

I've run into an issue trying to combine 2 different Arduino timer projects I've found online. For both projects I'm using a DS3231 RTC, but have been able use the DS1307 library just fine in my code. The first set of code I picked up started…
Vinterwoo
  • 259
  • 2
  • 4
  • 7
6
votes
5 answers

Is there any better choice other than using delay() for a 6-hours delay?

I am designing an incubator system and I need to drive a motor forward and reverse every 6 hours. Is there any better choice other than using delay()? A 6-hours delay seems a little unprofessional.
henzup
  • 63
  • 1
  • 3
6
votes
2 answers

What's the most accurate way to time-stamp analogRead data?

I want to sample an Analog sensor as fast as possible, and time-stamp each sample that I take as accurately as possible. Currently, I'm doing the following: val = analogRead(SENSOR_PIN); clocktime = micros(); writeData(val, clocktime); // writes…
Josh
  • 163
  • 1
  • 6
5
votes
4 answers

Individually control ~200 LEDs

I am planning to build a LED polar clock, so it will need about 181 LEDs (12 Month, 31 Day, 7 Day-of-week, 12 Hour, 60 Minute, 59 Second) and I need to control each one individually. I will be buying everything from scratch so I ask for help…
dylan p.
  • 51
  • 1
5
votes
1 answer

I2C RTC returning bad times - sometimes

I have a TinyRTC I2C clock in one of my Arduino projects, and it works most of the time. But occasionally, it will report the time as 165 hours, 85 minutes and 25 seconds (165:85:25) for a couple of seconds, then go back to the correct time. I…
David
  • 51
  • 2
1
2 3
14 15