Difference between revisions of "ECE 110/Equipment/Hall Effect Sensor"

From PrattWiki
Jump to navigation Jump to search
(Sample Code)
(Sample Code)
Line 16: Line 16:
 
The code below has three variables:
 
The code below has three variables:
 
* <code>Hall_In</code> stores the analog input pin number that is connected to the sensor's third lead,
 
* <code>Hall_In</code> stores the analog input pin number that is connected to the sensor's third lead,
* <code>VCC</vode> stores the voltage used to power the sensor (typically 5 V), and
+
* <code>VCC</code> stores the voltage used to power the sensor (typically 5 V), and
 
* <code>Hall_sensitivity</code> stores the sensitivity of the sensor in volts per gauss, which for the A1324 is 0.005 V/G
 
* <code>Hall_sensitivity</code> stores the sensitivity of the sensor in volts per gauss, which for the A1324 is 0.005 V/G
  

Revision as of 15:46, 18 August 2022

$$\newcommand{E}[2]{#1_{\mathrm{#2}}}$$

Pins

  • 1 (left): Supply voltage $$\E{V}{CC}$$, typically 5 V
  • 2 (middle): GND
  • 3 (right): vout between 0 and $$\mathrm{V}_{\mathrm{CC}}$$

Operation

The voltage on the third pin will vary depending on the supply voltage and the magnetic flux density through the Hall effect sensor. If the magnetic flux density is 0 G (where G stands for gauss), the third pin will read

Assuming a 5 V external supply, pin 3's voltage will be between 0 and 5 V. A voltage of 0 V indicates the strong presence of a south pole while a voltage of 5 V indicates the strong presence of a north pole. An output of 2.5 V indicates no magnetic field. The sensitivity is 5 mV/G (where G stands for gauss)

Sample Code

The code below has three variables:

  • Hall_In stores the analog input pin number that is connected to the sensor's third lead,
  • VCC stores the voltage used to power the sensor (typically 5 V), and
  • Hall_sensitivity stores the sensitivity of the sensor in volts per gauss, which for the A1324 is 0.005 V/G

The code will read the voltage from the specified analog pin as a value between 0 (for 0 V) and 1023 (for 5 V). It then converts that into a voltage measurement (assuming a 5 V based Arduino). Finally, it converts the voltage measurement into a flux density measurement based on the sensitivity of the Hall effect sensor and prints out the analog pin reading, the equivalent analog pin voltage, and the measured magnetic flux denisty.

const int Hall_In = 0;
const float VCC = 5.0;
const float Hall_sensitivity = 0.005; # 5 mV/G

void setup() {
  Serial.begin(9600);
}

void loop() {
  float Hall_Reading = analogRead(Hall_In);
  float Hall_Voltage = Hall_Reading * 5.0 / 1023.0;
  float Hall_Gauss = (Hall_Voltage - (VCC/2)) / 0.005;
  Serial.print("Analog reading = ");
  Serial.print(Hall_Reading);
  Serial.print(" ");
  Serial.print("Analog voltage = ");
  Serial.print(Hall_Voltage);
  Serial.print(" ");
  Serial.print("Flux density = ");
  Serial.println(Hall_Gauss);
  delay(100);
}