Go Down

### Topic: delay Function Accuracy [SOLVED] (Read 1 time)previous topic - next topic

#### Robotkid

##### Aug 24, 2011, 06:38 pmLast Edit: Aug 26, 2011, 05:58 pm by Robotkid Reason: 1
I am making a datalog for a temperature sensor.
It takes a reading every 10 minutes but I am not sure as to the accuracy of the Arduino's delay function.
Will using the timer for longer periods of time make the arduino timer less accurate and/or damage my arduino?
Thanks
Robotkid

#### AWOL

#1
##### Aug 24, 2011, 07:07 pm
How accurate do you need to be for a ten minute interval?
(no long periods will not damage anything)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#### James C4S

#2
##### Aug 24, 2011, 07:09 pm
Quote
Will using the timer for longer periods of time make the arduino timer less accurate and/or damage my arduino?

How would damage occur?

Quote
I am not sure as to the accuracy of the Arduino's delay function.

A better question might be what kind of accuracy do you expect?  Minutes, seconds, milliseconds?

If the timing is critical (within a couple of seconds) then you probably want to look at using a RTC.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

#### Robotkid

#3
##### Aug 24, 2011, 11:52 pm
I ask about the accuracy because my test program that only ran for 5 minutes taking a reading every minute.
It took one reading at the beginning and then stopped.
I am going to adapt for my UNO and try it on there. (I was using my NANO before)

My code is below:

Quote

int temperaturePin = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
if(i >=6)
{
Serial.println("Stopped");
while(true);
}
float temperature;
temperature = getVoltage(temperaturePin);
temperature = (temperature - 0.5)*100;
Serial.println(temperature);
delay(1000*60);
i++;
}

float getVoltage(int pin){
}

#4
##### Aug 25, 2011, 12:20 am

Quote
delay( 1000UL * 60UL );

#### Kctess5

#5
##### Aug 25, 2011, 01:21 am
Yeah make sure your using unsigned long. Also for greater accuracy you should use the millis() function. That way the time it takes to run the code inbetween delays won't matter

#6
OK, thanks.
I'll try that.

#### robtillaart

#7
##### Aug 25, 2011, 05:25 pm

If timing is critical, at least use a higher baudrate and reduce the math

Code: [Select]
`int temperaturePin = 0;int i = 0;void setup(){  Serial.begin(115200); // 12 x as fast as 9600 }void loop(){  if (i >= 6)  {    Serial.println("Stopped");    while(true);  }  float temperature = getTemperature(temperaturePin);  Serial.println(temperature);                     delay(1000UL * 60 UL);  i++;                               }float getTemperature(int pin){return (analogRead(pin) * 0.4882814 - 50;}`

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Robotkid

#8
##### Aug 26, 2011, 05:57 pm
Quote
If timing is critical, at least use a higher baudrate and reduce the math

No, timing isn't very important so this doesn't affect to much. I tried out 300baud just to see how slow it was and it actually didn't make to much of a difference with the data I was sending.
Thanks anyway though

Go Up

Please enter a valid email to subscribe