MyRoboPathOpen Robotics Lab
Arduino Uno #23 of 35
Est. 0.5 Hours
Budget: $2 - $4
Beginner

KY-024 Linear Hall-Effect Magnetic Field Sensor

Detect magnetic field strength and North/South polarity without physical contact for RPM tachometers and door sensors.

Sense invisible magnetic fields using the KY-024 linear Hall-effect sensor module (49E element + LM393). Measure magnetic flux magnitude and polarity directly on analog pin A0—distinguishing North vs. South poles—to build contactless door latches and wheel RPM counters.

Arduino Uno R3KY-024 Hall SensorMagnetic PolarityContactless SensingADC Deviation
KY-024 Linear Hall-Effect Magnetic Field Sensor Blueprint
KY-024 Linear Hall-Effect Magnetic Field SensorCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Understand the Hall Effect: magnetic flux perpendicular to current flow produces a proportional transverse voltage.
2Capture a startup zero-Gauss ADC baseline (~512) to cancel small module offset tolerances.
3Differentiate North vs. South magnetic poles cleanly by the sign (+/-) of the ADC deviation.
4Apply contactless magnetic sensing to robotics wheel RPM encoders and limit switches.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The KY-024 draws ~5mA from Arduino Uno 5V. In zero magnetic field, the 49E linear Hall element biases smoothly around half-supply (~2.5V, ADC ~512). Zero moving parts means infinite switch life; keep strong neodymium magnets away from magnetic storage or mechanical watches.

KY-024 Linear Hall-Effect Magnetic Field Sensor Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for KY-024 Linear Hall-Effect Magnetic Field Sensor
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P @ 16MHz1$8.00
KY-024 Linear Hall Sensor ModuleSS49E linear Hall IC + LM393 comparator1$1.50
Small Bar / Neodymium MagnetTest magnet for North/South polarity sensing1$0.50
2× 5mm LEDs + 220Ω ResistorsDual polarity visual indicators2$0.30

Electrical & System Architecture

Connect KY-024 (+) to 5V, (G) to GND, (A0) to A0, and (D0) to D2. Wire North/South polarity indicator LEDs (+220Ω each) to D8 and D9.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-024 Linear Hall-Effect Magnetic Field Sensor.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-024 Linear Hall-Effect Magnetic Field Sensor.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling KY-024 Linear Hall-Effect Module (49E) acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for KY-024 Linear Hall-Effect Magnetic Field Sensor.
Figure: Firmware execution flow and state transitions for KY-024 Linear Hall-Effect Magnetic Field Sensor.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Inspect KY-024 Hall Element & Pinout

Duration: 5 Mins

Locate the tiny 3-leg black 49E Hall IC extending from the front of the PCB.

KY-024 Linear Hall-Effect Magnetic Field Sensor hardware layout diagram
Stage 1: KY-024 Linear Hall-Effect Module (49E) hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • Verify pin labels: A0, G (GND), + (5V), D0.
  • Keep magnets at least 15cm away during Arduino boot so startup zero-calibration is accurate.
  • Note that the flat branded face of the 49E sensor is most sensitive to perpendicular magnetic lines.
Engineering & Tuning Tip: Because Hall sensors are solid-state, they work right through wood, plastic, or 3D-printed robot enclosures!
2

Wire KY-024 to A0/D2 & Dual Polarity LEDs

Duration: 5 Mins

Connect power, analog/digital outputs, and Pole A (D8) / Pole B (D9) indicator LEDs.

KY-024 Linear Hall-Effect Magnetic Field Sensor breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • Connect KY-024 + → 5V, G → GND, A0 → A0, D0 → D2.
  • Wire Red LED (+220Ω) to D8 and Blue/Green LED (+220Ω) to D9.
  • Plug in USB cable with no magnet near the breadboard.
Engineering & Tuning Tip: Using two different LED colors makes seeing North vs. South magnetic polarity instantaneous!
3

Verify Zero-Field Midpoint (~512)

Duration: 5 Mins

Run the diagnostic check and confirm neutral A0 rests cleanly near 500–530.

KY-024 Linear Hall-Effect Magnetic Field Sensor power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (<6mA)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • Upload the diagnostic snippet and open Serial Monitor.
  • Confirm resting ADC is roughly 512 (≈2.5V).
  • Bring one end of a magnet close—watch ADC rise toward 700–900; flip the magnet—watch ADC drop toward 150–350!
Engineering & Tuning Tip: If both poles change ADC very slightly, move the magnet closer to the flat face of the black 49E sensor chip.
4

Upload Magnetic Polarity Detector Firmware

Duration: 10 Mins

Flash the auto-zeroed polarity and relative flux intensity detector.

KY-024 Linear Hall-Effect Magnetic Field Sensor serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • Upload the production sketch below with magnets kept away during startup.
  • Present one pole of the magnet → D8 LED illuminates and Serial prints POLE + strength.
  • Flip the magnet 180° → D9 LED illuminates and Serial prints POLE - strength.
Engineering & Tuning Tip: A ±25 ADC deadband ignores Earth's tiny geomagnetic field and stray electronics noise.
5

Measure Magnetic Falloff Distance

Duration: 5 Mins

Observe how magnetic flux density falls off rapidly (inverse cube law) as you pull the magnet away.

KY-024 Linear Hall-Effect Magnetic Field Sensor live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • Record signed delta at 5mm, 15mm, and 30mm from the 49E element.
  • Confirm both LEDs turn OFF cleanly outside the deadband.
  • Verify reliable repeatability across 10 consecutive passes.
Engineering & Tuning Tip: Glue a tiny magnet onto a spinning robot wheel and count pulses per second to measure exact wheel RPM!

Subsystem Benchtop Verification Scripts

Test each hardware subsystem independently before deploying the full autonomous firmware.

1Bench Diagnostic: KY-024 Linear Hall-Effect Module (49E) Hardware Check

Subsystem Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for KY-024 Linear Hall-Effect Module (49E) before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// Diagnostic: Raw KY-024 Linear Hall Voltage Monitor
void setup() { Serial.begin(115200); }
void loop() { Serial.print("Hall A0: "); Serial.println(analogRead(A0)); delay(150); }
Expected Output: Rests near ~512 with no magnet; swings up (>650) for one pole and down (<350) for opposite pole.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_ky024_hall_magnetic_sensor.ino
arduino_uno_ky024_hall_magnetic_sensor.inoArduino C++
/**
 * Project 23: KY-024 Linear Hall-Effect Magnetic Polarity Detector
 * Board: Arduino Uno R3 | Pins: A0 (Hall AO), D8 (Pole + LED), D9 (Pole - LED)
 */
const uint8_t HALL_AO = A0;
const uint8_t LED_POS = 8;
const uint8_t LED_NEG = 9;
const int DEADBAND = 25;

int zeroFieldAdc = 512;

int sampleHall() {
  long sum = 0;
  for (uint8_t i = 0; i < 8; i++) sum += analogRead(HALL_AO);
  return sum / 8;
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_POS, OUTPUT);
  pinMode(LED_NEG, OUTPUT);
  delay(200);
  zeroFieldAdc = sampleHall();
  Serial.print(F("KY-024 Hall Sensor Ready | Zero-Field Baseline: "));
  Serial.println(zeroFieldAdc);
}

void loop() {
  int raw = sampleHall();
  int delta = raw - zeroFieldAdc;

  bool posPole = (delta > DEADBAND);
  bool negPole = (delta < -DEADBAND);

  digitalWrite(LED_POS, posPole ? HIGH : LOW);
  digitalWrite(LED_NEG, negPole ? HIGH : LOW);

  Serial.print(F("Raw: ")); Serial.print(raw);
  Serial.print(F(" | Flux Delta: ")); Serial.print(delta);
  Serial.print(F(" | Field: "));
  if (posPole) Serial.println(F("POSITIVE POLE (+)"));
  else if (negPole) Serial.println(F("NEGATIVE POLE (-)"));
  else Serial.println(F("NEUTRAL"));
  delay(150);
}

Firmware Architecture Explanation:

  • Auto-calibrates the zero-Gauss ADC resting point on boot to cancel sensor offset drift.
  • Splits signed deviation above +25 and below -25 into distinct magnetic pole indicators.
  • Averages 8 fast ADC reads per cycle for smooth proximity readings.

Operational Verification & Pin State Matrix

1Double-check all 5 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Rests near ~512 with no magnet; swings up (>650) for one pole and down (<350) for opposite pole.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for KY-024 Linear Hall-Effect Magnetic Field Sensor
Input / StatePin / SignalDetected ConditionExpected Output
Delta > +25A0 > 537Positive Pole PresentD8 LED ON, D9 OFF
|Delta| ≤ 25A0 ≈ 512No Magnet NearbyBoth LEDs OFF (Neutral)
Delta < -25A0 < 487Negative Pole PresentD9 LED ON, D8 OFF

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for KY-024 Linear Hall-Effect Magnetic Field Sensor
ProblemLikely CauseDiagnostic CheckEngineering Solution
Readings never change near a magnetMagnet held sideways or weak fridge magnet too far awayBring magnet pole face within 5mm of flat 49E facePresent magnet pole directly perpendicular to the black IC face.
One LED stays permanently ON at restMagnet was sitting near breadboard during boot calibrationRemove magnets and press Arduino Reset buttonKeep magnets away during startup calibration.
Raw reads 0 or 1023Wired to D0 instead of A0 or loose power leadVerify jumper lands on A0 silkscreen pinConnect Arduino A0 to KY-024 A0 and confirm 5V/GND.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 1Contactless Door Security Alarm

Sound Project 5 buzzer whenever a door magnet pulls away from the Hall sensor.

Level 2Spinning Wheel RPM Tachometer

Count falling edges on D2 per second to compute exact motor shaft RPM.

Level 3Proportional Magnetic Glow Lamp

Map abs(delta) to PWM brightness on D9 so the LED glows brighter as a magnet nears.