If you need to measure RPM, count revolutions, or detect proximity without physical contact, a hall effect sensor Arduino setup is the most reliable approach. For digital switching applications, the A3144 (commonly sold as the KY-003 or KY-024 module) is the industry standard. It outputs a clean LOW signal when a magnetic field exceeds its threshold, and returns HIGH when the field drops below its release point.

This guide covers the exact wiring, a robust debounce code implementation for the Arduino Uno R4 Minima, and the specific debugging steps to take when your sensor refuses to trigger.

Project Overview & Difficulty Rating

Difficulty: Beginner to Intermediate (2/5)

Time Required: 20 minutes for wiring, 15 minutes for calibration and testing

Estimated Cost: ~$29.50 (Arduino Uno R4 Minima: ~$27.60, 5-pack of KY-024 A3144 modules: ~$1.90)

Core Concept: Magnetic field detection via the Hall Effect, open-drain outputs, and switch debouncing.

Unlike mechanical reed switches, which suffer from contact bounce and limited lifespans, the A3144 uses a solid-state Hall IC with an integrated Schmitt trigger. This provides hysteresis, meaning the turn-on and turn-off magnetic thresholds are slightly different, preventing rapid toggling when the magnet hovers right at the edge of the detection zone.

Hardware Spec Sheet & Pin Mapping

Before wiring, it is critical to understand that the A3144 output is open-drain. Open-drain vs push-pull is a common point of confusion: an open-drain output configuration means the internal transistor can pull the signal line to ground (LOW) but cannot actively drive it high. It requires an external or internal pull-up resistor to register a HIGH state when the magnet is absent.

Component Model / Variant Key Specification
Microcontroller Arduino Uno R4 Minima 5V logic, 48MHz Cortex-M4F
Hall Sensor IC Allegro A3144 (or KY-024 Module) Digital Switch, South-pole triggered, Open-drain
Pull-up Resistor 10kΩ (Internal or External) Required for open-drain HIGH state
Magnet Neodymium N52 (10x5mm) Must present South pole to flat face of IC

Pin Mapping Table

KY-024 Module Pin Wire Color (IEC 60446) Arduino Uno R4 Pin Function
GND Black / Blue GND Circuit Common
VCC Red / Brown 5V Power Supply (4.5V - 24V)
DO (Digital Out) Yellow / Orange D2 Switch Output (Active LOW)
AO (Analog Out) Green (Optional) A0 (Optional) Raw linear voltage (KY-024 only)

Wiring Steps & Circuit Assembly

  1. De-energize the board: Ensure the Arduino Uno R4 is unplugged from your PC or power supply before making connections.
  2. Connect Power: Run a jumper from the Arduino 5V pin to the KY-024 module VCC pin. Connect Arduino GND to the module GND.
  3. Wire the Signal: Connect the module's DO pin to Arduino Digital Pin 2. Pin 2 is preferred because it supports hardware external interrupts, which we will use in advanced RPM counting.
  4. Enable Pull-up: The KY-024 module usually includes a surface-mount 10kΩ pull-up resistor on the DO line. If you are using a bare A3144 IC instead of the module, you must wire a 10kΩ resistor between the DO pin and the 5V line, or rely on the Arduino's internal pull-up (configured in code).
  5. Verify Magnet Polarity: Use a compass or known magnet to identify the South pole. The flat, branded face of the A3144 IC is the sensing face, and it only triggers on the South pole.
Callout Tip: If you are running the sensor cable longer than 2 meters, the internal pull-up resistor is too weak and will act as an antenna for EMI. Use an external 4.7kΩ pull-up resistor at the Arduino end and route the cable away from AC mains wiring.

Complete Arduino Code (Target: Uno R4 Minima)

This code targets the Arduino Uno R4 Minima. It includes a startup diagnostic check to verify the sensor isn't shorted, and a software debounce routine to filter out mechanical vibration when the magnet passes the sensor.

/*
 * Hall Effect Sensor (A3144 / KY-024) Debounce & Diagnostic Code
 * Target Board: Arduino Uno R4 Minima (5V Logic)
 * Author: ElectricalFlux
 */

// --- Pin Definitions ---
const int HALL_SENSOR_PIN = 2;  // Digital Pin 2 (Interrupt capable)
const int STATUS_LED_PIN = 13;  // Built-in LED

// --- Debounce & State Variables ---
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 15; // 15ms debounce for mechanical vibration
int lastSensorState = HIGH;
int currentSensorState = HIGH;
unsigned long triggerCount = 0;

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 2000) { /* Wait for serial port on R4 */ }
  
  Serial.println("Initializing Hall Effect Sensor...");
  
  // Configure pin with internal pull-up as a fallback safety measure
  pinMode(HALL_SENSOR_PIN, INPUT_PULLUP);
  pinMode(STATUS_LED_PIN, OUTPUT);
  
  // --- Startup Diagnostic Check ---
  delay(100); // Allow line to stabilize
  int startupRead = digitalRead(HALL_SENSOR_PIN);
  
  // If the pin is stuck LOW immediately on boot, it's shorted to ground
  if (startupRead == LOW) {
    Serial.println("ERR: Hall sensor stuck LOW - short to ground detected.");
    while(1) { // Halt execution
      digitalWrite(STATUS_LED_PIN, HIGH);
      delay(100);
      digitalWrite(STATUS_LED_PIN, LOW);
      delay(100);
    }
  }
  
  Serial.println("Sensor initialized. Awaiting magnet...");
  lastSensorState = HIGH;
}

void loop() {
  int reading = digitalRead(HALL_SENSOR_PIN);
  
  // State change detection with debounce
  if (reading != lastSensorState) {
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != currentSensorState) {
      currentSensorState = reading;
      
      // Trigger on the falling edge (magnet detected, output goes LOW)
      if (currentSensorState == LOW) {
        triggerCount++;
        digitalWrite(STATUS_LED_PIN, HIGH);
        Serial.print("Magnet Detected | Total Triggers: ");
        Serial.println(triggerCount);
      } else {
        digitalWrite(STATUS_LED_PIN, LOW);
      }
    }
  }
  
  lastSensorState = reading;
}

For high-speed RPM counting (e.g., measuring a motor shaft spinning at 3000 RPM), polling the pin in the loop() might miss pulses. In that scenario, switch to hardware interrupts using attachInterrupt(digitalPinToInterrupt(HALL_SENSOR_PIN), countPulse, FALLING). You can read more about configuring hardware interrupts in the official Arduino attachInterrupt documentation.

Debugging: First 3 Checks & Common Error Strings

When a hall effect sensor Arduino project fails to register a magnet, the issue is almost always magnetic polarity or pull-up configuration. If your Serial Monitor outputs the exact error string ERR: Hall sensor stuck HIGH - check wiring or pull-up (or if it simply never registers a LOW state), follow these first three checks in order:

  1. Verify Magnet Polarity (The #1 Culprit): The A3144 is unipolar. It only reacts to the South pole of a magnet. If you are using the North pole, the sensor will remain permanently HIGH. Flip the magnet 180 degrees. If you don't know which pole is which, use a smartphone compass app to identify the South-seeking end.
  2. Measure the Pull-Up Voltage: Set your multimeter to DC Voltage. Connect the black probe to Arduino GND and the red probe to the DO pin. With no magnet present, you must read between 4.8V and 5.0V. If you read 0V or a floating value (like 1.2V), your pull-up resistor is missing, broken, or the internal INPUT_PULLUP failed to engage.
  3. Check the Air Gap: The A3144 has an operate point (Bop) of roughly 25 to 45 Gauss. A standard ceramic fridge magnet will not trigger it from more than 5mm away. You need a Neodymium magnet, and the air gap between the magnet surface and the black plastic body of the sensor must be less than 10mm.

If the sensor reads LOW constantly, even without a magnet, the signal wire is shorted to ground, or the module's onboard voltage regulator (if present on the KY-024) has failed and pulled the output transistor gate high.

Extending and Simplifying the Build

How to Simplify:
If you only need a visual indicator and do not care about counting triggers or logging data to a PC, strip the code down to the bare minimum. Remove the Serial initialization and debounce logic. Simply wire the sensor's DO pin to an N-channel MOSFET gate (like a 2N7000) to drive a 12V LED strip directly, bypassing the Arduino entirely. The A3144 can sink up to 25mA, which is enough to drive a standard 5V indicator LED directly if you place a 220Ω resistor in series.

How to Extend:
To build a full tachometer, add an I2C OLED display (SSD1306, 128x64) to visualize the RPM in real-time. Calculate RPM by counting the number of triggers over a 1-second window using millis(), then multiplying by 60. For even greater precision, measure the time delta (micros()) between consecutive FALLING interrupts and calculate instantaneous RPM: RPM = 60000000 / deltaMicros. For a deeper dive into the physics of how the semiconductor lattice generates this voltage, refer to this comprehensive guide on the Hall Effect.

Frequently Asked Questions

Can I use a hall effect sensor Arduino setup to measure AC current?

No, not with the A3144. The A3144 is a digital switch designed for proximity and RPM detection. To measure AC or DC current without breaking the circuit, you need a linear hall effect sensor (like the SS49E) paired with an op-amp, or a dedicated current sensor IC like the ACS712 or ACS724, which includes an integrated flux concentrator and analog output scaled to amps.

Why is my hall effect sensor Arduino RPM reading double the actual speed?

This happens when your code triggers on both the FALLING and RISING edges of the signal, or when your magnet is long enough to trigger the sensor, release it, and trigger it again on the opposite pole if you are mistakenly using a bipolar latch sensor instead of a unipolar switch. Ensure your interrupt is set to FALLING only, and verify you are using a single, short Neodymium magnet.

What is the difference between the KY-003 and KY-024 hall effect sensor Arduino modules?

Both modules typically use the same A3144 digital switch IC. The difference is in the module layout: the KY-003 is a basic 3-pin board with just VCC, GND, and DO. The KY-024 is a 4-pin board that adds an AO (Analog Out) pin and an onboard LM393 comparator with a trimmer potentiometer. The AO pin on the KY-024 provides a raw analog voltage that drops as a magnetic field approaches, allowing you to measure relative magnetic field strength, not just a digital on/off state.