Sampling analog data

Sampling sata is particularly useful for analog sensors such as an LDR or a thermistor. Another good example is one of the MQ gas sensors that can be bought which take a period of time to ‘warm up’.

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

Here is a simple code example which shows this technique

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];
val = (val / samples);
return map(val, 550, 1023, 100, 0);


Please enter your comment!
Please enter your name here