I have browsed the forums and the web and found some useful information but nothing that fully answers my question so I am asking for help.
I am working with a Hall Sensor to sense magnetic field when exposed to a bipolar magnetic strip and actuate a cylinder if conditional statements are true.
Applicable Hardware:
-Microcontroller: Arduino Mega 2560
-Hall Sensor: HHP-SU 696 (see attached data sheet)
Problems:
- The Hall sensor is picking up a lot of background "noise".
For calibration I use a smoothing function to take 500 readings while computing the running average with the final value taken as the analog value returned by the Hall sensor when no magnetic field is applied. This appears to be working ok, see attachment "calibration_image".
The raw analog value returned by the Hall sensor via the serial monitor appears very jumpy. My calculations to convert from analog to Gauss depend on the raw value so I have tried to smooth it the same way as in calibration. While this does smooth the value it is not enough, my final analog value should be close to zero but it still fluctuates too much (ideally I need it as close to zero as possible). See "compensated_analog". KEEP IN MIND THIS IS WHEN NO MAGNETIC FIELD IS APPLIED.
Question: How do I go about filtering or smoothing to get that analog value closer to zero? (see smoothing function below)
- I convert the analog value (returned from the Hall sensor to the Arduino) to Gauss. Because the Hall sensor's extreme sensitivity (29.2 [mV/T]) one jump in analog value is a far too large jump in Gauss because the poles on the magnetic strip I am working with are approx 150 to 200 Gauss and -150 to -200 Gauss. See "analog_to_Gauss" for my conversion calculations.
Question: How do I accurately scale down the analog to gauss conversion factor?
I am not an Arduino master by any means. If I forgot to add any necessary details please let me know.
Smoothing function used:
// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
// see: http://arduino.cc/en/Tutorial/Smoothing
float noFieldHallCalibraiton2() {
const int numReadings = 50;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int breakCount = 1; // used to determine how many samples to calibrate over
// setup output table
Serial.print("Loop Count");
Serial.print("\t");
Serial.print("Raw [analog]");
Serial.print("\t");
Serial.println("Smoothing FN [analog] ");
//*************************************************************************
// initialize readings to 0
for(int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
//*************************************************************************
while(1) {
// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = analogRead(HallSensorPin);
// add the reading to the total:
total= total + readings[index];
// send it to the computer as ASCII digits
Serial.print(breakCount);
Serial.print("\t\t");
Serial.print(readings[index]);
Serial.print("\t\t");
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
average = total / numReadings;
Serial.println(average);
delay(1); // delay in between reads for stability
// this determines when to break
breakCount++;
if(breakCount == 500) {
break;
} //end if
} //end while loop
return(average);
} //end noFieldHallCalibration2
HHP-SU_696.pdf (65 KB)







