Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Project 21: Hall Sensor

Introduction

The KY-024 Hall Sensor module detects magnetic fields using a linear Hall-effect sensor and an LM393 comparator. It outputs both analog and digital signals to sense magnetic strength and presence. When a magnet is nearby, the output changes based on field strength or threshold. In this tutorial, we will learn how to connect and use the KY-024 with an Arduino.


Required Components

  • Arduino UNO
  • KY-024 Hall Sensor
  • Jumper wires
  • Breadboard (optional)

Pinout

Circuit Diagram / Wiring

  • KY-024 VCC → 5V (Arduino)
  • KY-024 GND → GND (Arduino)
  • KY-024 AO  → Pin A0 (Arduino)
  • KY-024 DO  → Pin D2 (Arduino)

Arduino Code / Programming

int analogPin = A0;  // Analog output
int digitalPin = 2;  // Digital output
int analogVal;
int digitalVal;

void setup() {
  Serial.begin(9600);
  pinMode(digitalPin, INPUT);
}

void loop() {
  analogVal = analogRead(analogPin);
  digitalVal = digitalRead(digitalPin);

  Serial.print("Analog Value: ");
  Serial.print(analogVal);
  Serial.print(" | Digital Output: ");
  Serial.println(digitalVal);

  delay(1000);
}

Explanation

  • The analog pin reads magnetic field strength with variable values.
  • The digital pin gives HIGH or LOW based on a preset threshold set by the onboard potentiometer.
  • Data is printed to the Serial Monitor for real-time observation.

Testing and Troubleshooting

  • Move a magnet near the sensor and observe changes in the Serial Monitor.
  • If no change, rotate the potentiometer to adjust the sensitivity.
  • Ensure the correct side of the magnet is facing the sensor for accurate detection.

    Leave a Reply

    Your email address will not be published.

    Need Help?