Go Down

Topic: Instant reading of one sensor whilst averaging another simultaneously (Read 930 times)previous topic - next topic

piashaw

I'm trying to figure out a way if it is possible to have 2 different sensors displayed with one of them showing instant results and the second an average of results.

I have been using a "for loo"p for the averaging with an SHT75 sensor, putting the readings into an array etc. The problem is, is that the time taken to read the sensor 10 times is many many seconds which means that my other sensor which is a pressure sensor is not being polled..

Is there anyway to continuously display the pressure sensor reading and average the SHT75 in the background?

MAny thanks

ps I'm quite new to programming!

Shpaget

Poll your real time sensor and display both its result and the average result continuously, but use timer interrupt to trigger the other sensor and code that calculates the average only when needed (in intervals).

piashaw

Thanks scotty.

Is there any sample code you have for the average readings, namely the rolling average. Is it a particular function which I haven't found yet?

Thanks

Peter

Khalid

use blink without delay with few boolean statements...
Simply...You can't afford me..

Author Of:
http://my-woodcarving.blogspot.com/
http://www.free3dscans.blogspot.com/
http://my-diysolarwind.blogspot.com/

Oops..some one gave me Karma...

ash901226

ouh you could always use something like
Code: [Select]
`if (Count <=10)Something1=analogRead(A1);Something2=analogRead(A2);Total1=Something1+Total1;Total2=Something2+Total2;count++;else{  Average1=Total1/Count;  Average2=Total2/Count;  Serial.println(Average1);  Serial.println(Average2);  Count=0;}`

Shpaget

Code: [Select]
`a = b;b = c;c = d;...j = analogRead(sensor);someDisplayFunctionOrOther ((a + b + c + ... + j) / 10);`

robtillaart

partial code with 2 sensors using a running average (TODO add 2 functions to read the sensors)
Code: [Select]
`int average;void setup(){  Serial.begin(115200);  average = readSensor2(); // initial value}void loop(){  int direct = readSensor1();  int average = average*0.6 + readSensor2()*0.4;  // weighted running average;  60% old/40% new  other weights possible of course;  Serial.print(direct);  Serial.print("\t");  Serial.println(average);}`

for 1 sensor both the last value an
Code: [Select]
`int average;void setup(){  Serial.begin(115200);  average = readSensor2(); // initial value}void loop(){  int direct = readSensor1();  average = average*0.6 + direct*0.4;  Serial.print(direct);  Serial.print("\t");  Serial.println(average);}`
Rob Tillaart

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

piashaw

Thanks everybody. Will try a few of the suggestions and see which works out best for this sensor. As teh temperatures could fluctuate wildly (intentionally). I reckon the a=b etc option is best as it will clear the buffers out reasonably quickly when I take the probe from room temperature into a hot air duct. But the other principle may well be useful for another project I'm doing.

Thanks again.

PaulS

Quote
As teh temperatures could fluctuate wildly (intentionally).

Really? Any real sensor is going to have some lag time between when the sensed condition changes and when the reported value changes. If you read frequently, you will not get wild fluctuations.

Unless you are using a torch and a bucket of ice water to heat and cool the sensor directly, wild temperature fluctuations are unlikely.

Go Up

Please enter a valid email to subscribe