Linear Hall Magnetic Sensor with Arduino

arduino logo

Welcome to the World of Sensors and Modules with Arduino!

The Linear Hall Magnetic Sensor Module is a versatile electronic component utilized for measuring magnetic fields with precision and accuracy in Arduino projects. In this sensors and modules guide, we’ll explore its working principle, key features, applications, and how it can enhance your Arduino projects.

If you’re new to Arduino, why not take a look at our Getting Started with Arduino guides. These guides are designed for beginners to learn the fundamental basics of Arduino programming.

How the Linear Hall Magnetic Sensor Works

Linear Hall Magnetic Sensor Modules operate based on the Hall Effect, where the output voltage varies linearly with changes in the magnetic field strength perpendicular to the sensor’s surface. When exposed to a magnetic field, the sensor generates a voltage proportional to the field strength, allowing for precise measurement.

Features and Specifications:
  • Operating Voltage: 5V
  • High Sensitivity: Linear Hall Magnetic Sensor Modules boast high sensitivity, enabling precise detection of magnetic fields.
  • Output: Analog and Digital Signals
  • Adjustable Gain: Some modules offer adjustable gain settings, allowing users to fine-tune sensitivity based on specific application requirements.
  • Size: 45mm x 15.5mm
  • Compatibility: This sensor is also compatible with other devices like the Raspberry Pi, ESP32, and ESP8266 etc…

Necessary Equipment:

  • Arduino (e.g., Arduino Uno)
  • Linear Hall Magnetic Sensor Module
  • Jumper wires
  • Breadboard (optional)

Pin Configuration

Connecting the Linear Hall Magnetic Sensor Module to an Arduino is fairly simple. The connections are as follows:

  • A0 on the Linear Hall Magnetic Sensor Module to Analog pin A0 on the Arduino.
  • G on the Linear Hall Magnetic Sensor Module to GND on the Arduino.
  • + on the Linear Hall Magnetic Sensor Module to 5V on the Arduino.
  • D0 on the Linear Hall Magnetic Sensor Module to Digital pin 2 on the Arduino.

Pin labels may vary.

Magnetic Linear Hall Sensor with Arduino Diagram

KY-024 Linear Hall Magnetic Sensor Module Fritzing Part is created by arduinomodules.info and published under Creative Commons Attribution-ShareAlike 4.0 International license

Arduino Code Example

// Define the pins to which the Linear Hall Sensor Module is connected
const int analogSensorPin = A0;  // Connect the analog output pin to this analog pin
const int digitalSensorPin = 2;   // Connect the digital output pin to this digital pin

void setup() {
  // Initialize the Serial communication for debugging
  Serial.begin(9600);
  
  // Set the digital sensor pin as input
  pinMode(digitalSensorPin, INPUT);
}

void loop() {
  // Read the analog value from the Linear Hall Sensor Module
  int analogSensorValue = analogRead(analogSensorPin);
  
  // Read the digital value from the Linear Hall Sensor Module
  int digitalSensorValue = digitalRead(digitalSensorPin);

  // Print the sensor values to the Serial Monitor
  Serial.print("Analog Sensor Value: ");
  Serial.println(analogSensorValue);
  
  Serial.print("Digital Sensor Value: ");
  Serial.println(digitalSensorValue);
// Add Conditional Statement to do something if magnet detected if (digitalSensorValue == 1){ Serial.println("Magnet Detected"); } // Add a short delay for stability delay(500); }

Breaking Down the Code

Constant Declaration
  • Defines constant variables representing the analog and digital pins to which the Linear Hall Sensor Module is connected.
Setup Function
  • The setup function is executed once when the Arduino starts.
  • Initializes serial communication for debugging.
  • Sets the digital sensor pin as an input to read digital values from the module.
Loop Function
  • The loop function is executed repeatedly.
  • Reads the analog value from the Linear Hall Sensor Module using analogRead and stores it in analogSensorValue.
  • Reads the digital value from the Linear Hall Sensor Module using digitalRead and stores it in digitalSensorValue.
  • Prints the analog and digital sensor values to the Serial Monitor.
  • Checks if a magnet is detected based on the digital sensor value:
    • If the digital sensor value is HIGH (1), prints “Magnet Detected” to the Serial Monitor.
  • Adds a short delay for stability using delay.

Sensitivity Adjustment

The trim pot allows you to fine-tune the sensitivity of the sensor. By adjusting the trim pot, you can control how sensitive the sensor is to changes in magnetic fields. This can be useful for fine-tuning the sensor’s response to achieve the desired detection range or accuracy.

Applications and Usage Scenarios

Proximity Detection

Utilize Linear Hall Sensor Modules for proximity detection applications, such as detecting the presence of magnets or metallic objects.

Position Sensing

Employ these modules for position sensing tasks, such as determining the position of a magnet along a linear or rotational axis.

Current Sensing

Implement Linear Hall Sensor Modules for current sensing applications, where the magnetic field generated by current-carrying conductors is measured to determine current flow.

Speed Measurement

Can be used for speed measurement applications, such as measuring the rotational speed of motors or machinery equipped with magnets.

Magnetic Field Mapping

Create Arduino projects that map magnetic fields in a given area using Linear Hall Sensor Modules, providing valuable insights into magnetic field distribution.

Proximity Switches

Develop proximity switches that trigger actions based on the presence or absence of magnets or metallic objects, leveraging the sensitivity of Linear Hall Sensor Modules.

Motor Control Systems

Integrate Linear Hall Sensor Modules into motor control systems to monitor rotor position or detect commutation in brushless DC motors.

Conclusion

In this sensors and modules guide, we explained the functionality of the Linear Hall Magnetic Sensor Module, exploring its working principles, and demonstrating how to interface it with an Arduino for practical applications. Linear Hall Magnetic Sensors offer a robust solution for measuring magnetic fields in Arduino projects, with their high sensitivity, linear output, and wide range of applications. Whether used for proximity detection, position sensing, current sensing, or speed measurement, these modules provide a versatile and reliable tool for makers and hobbyists alike, opening up a world of possibilities for magnetic field measurement and control.

Discover the endless possibilities for Arduino projects with more of our Sensors and Modules guides.

Luke Barber

Hello, fellow tech enthusiasts! I'm Luke, a passionate learner and explorer in the vast realms of technology. Welcome to my digital space where I share the insights and adventures gained from my journey into the fascinating worlds of Arduino, Python, Linux, Ethical Hacking, and beyond. Armed with qualifications including CompTIA A+, Sec+, Cisco CCNA, Unix/Linux and Bash Shell Scripting, JavaScript Application Programming, Python Programming and Ethical Hacking, I thrive in the ever-evolving landscape of coding, computers, and networks. As a tech enthusiast, I'm on a mission to simplify the complexities of technology through my blogs, offering a glimpse into the marvels of Arduino, Python, Linux, and Ethical Hacking techniques. Whether you're a fellow coder or a curious mind, I invite you to join me on this journey of continuous learning and discovery.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights