ELEC2645 - Embedded Systems Project - 'Sensor-matic!'
The aim of the project is to create an interface between a distance and a temperature sensor and an LCD screen.
Noise Cancellation In The SRF02 Sensor
Purpose:
- The SRF02 Distance Sensor is subject to interference when taking readings.
- The readings can fluctuate massively - even when the sensor is held in one position against a stationary solid object (i.e. a wall).
- Typically, the fluctuates jumped up by 200+ cm.
- This effect was observed at multiple distances suggesting the interference is random as opposed to systematic.
Method:
- The problem can be tackled in a number of different approaches.
- The easiest method is to simply calculate an average.
- This method requires that 'X' amount of readings are taken every iteration and summed together.
- The total sum is divided by the 'X'.
- This reduces the significance of random errors (although doesn't eliminate them).
Code:
- The initial total distance (int totalDistance) is set to equal zero.
- The number of readings (previously 'X') was selected to be 10.
- A 'For Loop' counts through 10 readings per iteration and each time.
- The value of the distance at each stage is added to the totalDistance variable.
- The final total is divided by 10 to give an output distance.
// Cancelling Out Sensor Noise Fluctuations
int totalDistance = 0; // Create a Total Function
for (int iteration = 0; iteration < 10; iteration++) { // Loop Through 10 Iterations
totalDistance = totalDistance + srf02.getDistanceCm();
lcd.refresh();
}
Results:
- The output is shown on the Nokia LCD screen.
- The output is less susceptible to interference - the variations are much closer to the truth value.
- A very high value would still cause an inaccurate reading - the code can be improved to solve this problem.
Improvements:
- Cumulative/Rolling Average - Rather than 10 readings being taken and then the average found. A cumulative average continuously calculates the average based on the current ten numbers in an array/sample space. On the eleventh reading, the first one is neglected and a new average is found. The process repeats by discarding the 'firsts' element in the array and entering in the 'tenth' and recalculating.
- Current Method inc. Rejection - The current method of determining the average can be implemented however to determine more accurate values, extra code could be implemented which rejects a distance which is above/below by 30% of the previous. In order to make sure the average is unaffected, the rejected distance would need to be replaced with another value - perhaps the distance of the previous reading.
Top Comments