Hall Effect Sensor

A Hall effect device provides an output that varies in response to a magnetic field. The magnetic field may be a magnet which moves near to the device, or a varying electromagnetic field. Hall effect devices come in two types - analog and digital. The analog device has a variable output voltage that is proportional to the magnetic field density. The digital device has an output that is either high or low, depending on the magnetic field density and the manufactured set point. The digital device is an analog device with a comparator on the output set to trip at a specific magnetic field density.

The device we are using is an A3144 compatible device. They operate on 5V, have a digital output, and are readily available. They are also quite small, being smaller than a TO-92 transistor.

The video shows a magnet approaching the Hall effect sensor, and the LED on the Arduino going off when it gets close to the sensor. The sensor has a transistor at the output that is turned on by the presence of the magnet, causing the output to go to 0V. This value is read by the program and placed on the LED on pin 13, which turns it off.

Some uses for this device might be the sensing the rotation of the shaft on an anemometer or on a wind direction indicator. A tipping bucket rain gauge could use one, too. Another important use for Hall effect devices is to commutate brushless DC motors.

The schematic shows how the A3144 Hall effect sensor is wired. There are three leads on the device - VCC, GND, and signal output. The output is open collector, so it needs to be pulled high with resistor R1. The value of R1 can be anything from 1kΩ to 100kΩ, but I chose 10kΩ because it doesn't draw too much current and we aren't running the device very fast. For faster switching times, use a smaller resistor, but don't get below 330Ω or the device might be damaged by excessive current. Fastest switching times are obtained by using an 820Ω resistor. With that value, the device can run well over 100,000 switches per second.

The code

The code is about as simple as it can get, but we'll make it more useful later. The LED pin on the Arduino (pin 13) is set up as an output. When the pin goes high, the LED labeled "L" on the Arduino turns on. We read the value of the Hall effect sensor on pin 2, and output it on pin 13. When the sensor senses the magnet, the output goes low, and the LED goes off.

void setup() {
  pinMode(13, OUTPUT);

void loop() {

The usefulness of the Hall effect sensor is found in its ability to alert us when something magnetic comes close to it. We can make that happen by fastening a magnet to a moving object, and a Hall effect sensor to a stationary object. When the moving object gets close to the stationary object, the Hall effect device triggers. The main program is doing other things, then when the sensor triggers, an interrupt is fired to wake the program and generate a short pulse on the LED. In the real world, the pulse might not be used, but the program might count another tip of the rain bucket.

volatile int hallState = LOW;

int hallDevice = 2;
int LED = 13;

void setup() {
  // Set the LED pin to output.
  pinMode(LED, OUTPUT);
  // Hook the interrupt handler.
  attachInterrupt(digitalPinToInterrupt(hallDevice), hall_int, FALLING);

void loop() {
  if (hallState == LOW) {
    // Generate a 100mS pulse.
    digitalWrite(LED, HIGH);
    digitalWrite(LED, LOW);
    hallState = HIGH;

// The interrupt handler.
void hall_int() {

  // Toggle the state.
  hallState = LOW;

This tutorial has been about the digital or switch-type Hall effect device. The analog device is similar in function, but does not have a trigger. It simply outputs a voltage that is proportional to the magnetic field strength. The output of an analog Hall effect device would be connected to one of the analog inputs on the Arduino, and would be read like any other analog input.

Arduino Board Logo


Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support


Stay updated

Sign up if you would like to receive our once monthly newsletter.