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
How accurate do you need to be for a ten minute interval?
(no long periods will not damage anything)
Will using the timer for longer periods of time make the arduino timer less accurate and/or damage my arduino?
How would damage occur?
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.
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:
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(100060);
i++;
}float getVoltage(int pin){
return (analogRead(pin) * .004882814);
}
delay( 1000UL * 60UL );
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
OK, thanks.
I'll try that.
If timing is critical, at least use a higher baudrate and reduce the math ![]()
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;
}
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