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.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerThe 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.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| KY-024 Linear Hall Sensor Module | SS49E linear Hall IC + LM393 comparator | 1 | $1.50 |
| Small Bar / Neodymium Magnet | Test magnet for North/South polarity sensing | 1 | $0.50 |
| 2× 5mm LEDs + 220Ω Resistors | Dual polarity visual indicators | 2 | $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.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling KY-024 Linear Hall-Effect Module (49E) acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Inspect KY-024 Hall Element & Pinout
Locate the tiny 3-leg black 49E Hall IC extending from the front of the PCB.
- 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.
Wire KY-024 to A0/D2 & Dual Polarity LEDs
Connect power, analog/digital outputs, and Pole A (D8) / Pole B (D9) indicator LEDs.
- 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.
Verify Zero-Field Midpoint (~512)
Run the diagnostic check and confirm neutral A0 rests cleanly near 500–530.
- 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!
Upload Magnetic Polarity Detector Firmware
Flash the auto-zeroed polarity and relative flux intensity detector.
- 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.
Measure Magnetic Falloff Distance
Observe how magnetic flux density falls off rapidly (inverse cube law) as you pull the magnet away.
- 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.
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 DiagnosticMinimal standalone sketch to verify pin wiring and signal response for KY-024 Linear Hall-Effect Module (49E) before running the full project firmware.
// 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); }Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* 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
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Delta > +25 | A0 > 537 | Positive Pole Present | D8 LED ON, D9 OFF |
| |Delta| ≤ 25 | A0 ≈ 512 | No Magnet Nearby | Both LEDs OFF (Neutral) |
| Delta < -25 | A0 < 487 | Negative Pole Present | D9 LED ON, D8 OFF |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Readings never change near a magnet | Magnet held sideways or weak fridge magnet too far away | Bring magnet pole face within 5mm of flat 49E face | Present magnet pole directly perpendicular to the black IC face. |
| One LED stays permanently ON at rest | Magnet was sitting near breadboard during boot calibration | Remove magnets and press Arduino Reset button | Keep magnets away during startup calibration. |
| Raw reads 0 or 1023 | Wired to D0 instead of A0 or loose power lead | Verify jumper lands on A0 silkscreen pin | Connect 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:
Sound Project 5 buzzer whenever a door magnet pulls away from the Hall sensor.
Count falling edges on D2 per second to compute exact motor shaft RPM.
Map abs(delta) to PWM brightness on D9 so the LED glows brighter as a magnet nears.