Code example for A1301 Hall Effect Sensor Author: Rob Tillaart Contact: rob dot tillaart at gmail dot com
0.1 2010-07-23: Initial page 0.2 2010-08-21: added some info
A Hall Effect sensor varies an output voltage depending on the magnetic field it is in. I played with the A1301 and made some simple code to see it work.
If there is no magnetic field applied the sensor outputs approx 2.5 Volts, half of the supply voltage, typical 5V. Depending on the Pole the output drops to 0V or rises to 5V with 2.5mv / Gauss.
I used the UA package device and it qas quite easy to connect to the Arduino:
I did not use any other components for the simpe test.
Note that the (UA package) device has a specific oriention and the datasheet states one should hold the magnet at the logo side of the device. It works quite well on the other side but the logo side might be the calibrated one.
Because the power supply may not be exactly 5V one need to read the sensor a number of times to find the average 0 Gauss point. For the sensor I used the analogRead(0) returned 505 on average. In a later (non Arduino) experiment I used a 9Volt battery and an LM7805 to get exact 5.0 Volt.
Note that the strength of the field depends on the distance, however I did not found the right formula yet so just a pointer to http://en.wikipedia.org/wiki/Magnet to get started :)
Happy tinkering, Rob
No class for this sensor yet :)
/*
* FILE: MM01
* AUTHOR: Rob van den Tillaart
* DATE: 2010 03 19
* URL: http://www.arduino.cc/playground/Code/HallEffect
*
* PURPOSE: use a A1301 as magnetometer
*
* Pinlayout A1301
* ==================
* 1 GND
* 2 signal connected to Analog 0
* 3 Vdd +5V
*
*/
int time = 0;
int oldtime = -1;
int rawMM = 0;
#define BNULL 505L // My midpoint, calibrate this
#define BFAC 1000L // 2500 mv == 1000 Gauss in 505 steps
void setup()
{
// setup serial - diagnostics - port
Serial.begin(9600);
}
void DoMeasurement()
{
// measure magnetics
rawMM = analogRead(0); // Range : 0..1024
Serial.print("MM: ");
Serial.print(rawMM);
long B = rawMM - BNULL; // adjust midpoint
B = B * BFAC / BNULL; // adjust scale -> -1000 .. +1000 Gauss
Serial.print(" = B in Gauss: ");
Serial.print(B);
if (B > 0) Serial.println(" South-pole");
else if (B <0) Serial.println(" North-pole");
else Serial.println();
}
void loop()
{
time = millis()/1000;
if (time == oldtime)
{
delay(100);
}
else
{
oldtime = time;
DoMeasurement();
}
}
The precision ?
The A1301 has a precision of 2.5mVolt per Gauss. There also exist a A1302 with approx. double precision 1.3mVolt / Gauss.
Datasheet
A1301 http://www.allegromicro.com/en/Products/Part_Numbers/1301/1301.pdf
LM7805 http://www.eidusa.com/Electronics_Voltage_Regulator.htm
Tesla vs Gauss
1 Tesla = 10000 Gauss
I am not sure where I should post this, but the information regarding "precision" is misleading. The word "sensitivity" should be substituted for the word "precision".
regards, kfilar
| Last Modified: | June 29, 2011, at 09:23 PM |
| By: | kfilar |