Categories

Arduino tip sampling analog data

Sampling sata is particularly useful for analog sensors such as an LDR or a thermistor

You can change the amount of samples to take and the interval which is in millioseconds

int sampleData(int analogPin, int samples = 10, int sampleInterval = 100) 
{ 
int sampleData[samples];
int val = 0;
for (int i = 0; i<samples; i++) 
{
sampleData[i] = analogRead(analogPin);
val = val + sampleData[i];
delay(sampleInterval);
}
val = (val / samples);
return map(val, 550, 1023, 100, 0);
}
Share

Leave a Reply