I'm working on a project in my university and I'm having a trouble in calculate time. I have a conveyor and an IR sensor which I use to calculate the maximum and minimum distances of a box when it is moving on the conveyor. Then I want to calculate the time between the max and min distances of box. I have used millis() for timing but it is not accurate. Here is my code:
int IRpin = 0;
float volts, distance,firstdata;
int k = 0;
float min;
float mang[150];
int m;
void setup() {
Serial.begin(9600);
}
void loop() {
volts = analogRead(IRpin) * 0.0048828125;
distance = 13 * pow(volts, -1.10);
if (distance < 20)
{
Serial.println(distance);
mang[k] = distance;
k++;
}
else
{
if (k > 0)
{
min = mang[0];
for (int i = 1; i < k; i++)
{
if (min > mang[i])
{
min = mang[i];
m = i;
}
}
firstdata=mang[1];
}
I store data the sensor send to me in an array. Now I want to calculate the time between firstdata [mang(1)] and [(min)]. I use 0A41SK Sharp IR sensor. Thank you for your time and sorry for my bad english.
millis()
not accurate enough? What kind of accuracy do you need? – Edgar Bonet Jun 21 '16 at 9:04