Pages: [1]   Go Down
Author Topic: delay Function Accuracy [SOLVED]  (Read 766 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: August 26, 2011, 10:58:38 am by Robotkid » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24424
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How accurate do you need to be for a ten minute interval?
(no long periods will not damage anything)
Logged

"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.

Austin, TX
Offline Offline
Faraday Member
**
Karma: 64
Posts: 6055
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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){
return (analogRead(pin) * .004882814);
}

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12286
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
delay( 1000UL * 60UL );
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 193
The people the people they see me and they know
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, thanks.
I'll try that.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12480
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Code:
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;
}

Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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
Logged

Pages: [1]   Go Up
Jump to: