To Whom It May Concern,
Currently I am trying to create a code to display linear displacement measurements of a electromagnetic piston with the hall effect sensor in real time on a graph. This is the code we have so far. I am not entirely sure whether I am taking the right approach. Any insight would be greatly appreciated.
Thank You!
int TOMILLIGAUSS = 977;
int NOFIELD = 507;
const unsigned long hallInterval = 200;
unsigned long hallTimer = 0;
void setup() {
hallTimer = millis();
Serial.begin(9600);
}
void DoMeasurement()
{
//*********************** measure magnetic field of hall effect sensor 1***************************
int raw1 = analogRead(0); // Range : 0..1024
// Uncomment this to get a raw reading for calibration of no-field point
//Serial.print("Raw reading: ");
//Serial.println(raw);
long compensated1 = raw1 - NOFIELD; // adjust relative to no applied field
long gauss1 = compensated1 * TOMILLIGAUSS; // 1000; // adjust scale to Gauss
//Serial.print("1 = ");
Serial.println(raw1);
//Serial.println(" milliGauss ");
//Hall effect sensor 2**
int raw2 = analogRead(1);
long compensated2 = raw2 - NOFIELD; // adjust relative to no applied field
long gauss2 = compensated2 * TOMILLIGAUSS; // 1000; // adjust scale to Gauss
//Serial.print("2 = ");
Serial.println(raw2);
//Serial.println(" milliGauss ");
//***Hall effect sensor 3
int raw3 = analogRead(2);
long compensated3 = raw3 - NOFIELD; // adjust relative to no applied field
long gauss3 = compensated3 * TOMILLIGAUSS; // 1000; // adjust scale to Gauss
//Serial.print("3 = ");
Serial.println(raw3);
//Serial.println(" milliGauss ");
}
void loop() {
if( (millis() - hallTimer) >= hallInterval) {
DoMeasurement();
hallTimer = millis();
}
}