INTRODUCTION:
In this tutorial, we will learn about the KY-024 module, what is a hall-effect sensor and we will build a simple project using the KY-024 module and an Arduino.
LINEAR MAGNETIC HALL SENSOR KY-024
The KY-024 Module will be our main component for this tutorial. This module has a 49E linear hall-effect sensor, and an LM393 differential comparator mounted on a breakout board with a potentiometer and several resistors.
The module has an analog output to give the actual reading of the hall-effect sensor. The module also has a digital output signal when the sensor value is greater than the threshold value set by VR1. Figure 1 shows the module as seen in wiring diagram.
PIN OUT:
The KY-024 module has four pins:
PIN | DESCRIPTION |
---|---|
A0 | Analog Output |
G | Ground |
(+) | +5V |
D0 | Digital Output |
WHAT IS A HALL EFFECT SENSOR?
A hall-effect sensor is an electronic component that measures the magnetic field intensity.
PROJECT – ARDUINO AMBIENT THERMOMETER:
After learning about the KY-024 module and the hall-effect sensor, it is now time to build a project using the module.
Our project will get the analog and digital signals from the KY-024 module, display it on the serial monitor and control the Arduino’s built-in LED.
PROJECT COMPONENTS:
For this project, we need the following components:
- Arduino Uno board (1 pc.)
- KY-024 Linear Magnetic Hall Sensor (1 pc.)
- Jumper wires
WIRING DIAGRAM:
Figure 2 shows the connection between the Arduino Uno and the KY-024 Linear Magnetic Hall Sensor.
The KY-024 module pins are connected to the Arduino Uno board as follows:
COMPONENT PIN | ARDUINO UNO PIN |
---|---|
A0 | A0 |
G | Ground |
(+) | +5V |
D0 | 8 |
CODE:
Below is the Arduino sketch for our project. I have added comments to explain important parts of the code. Save the code as KY-024.ino and upload it to your Arduino board.
// Arduino and KY-024 module void setup () { pinMode (13, OUTPUT); // built-in LED pin set to output pinMode (8, INPUT); // module digital output connected to Arduino pin 8 Serial.begin(9600); // initialize serial } void loop () { Serial.print("Analog pin: "); // display analog and digital values to serial Serial.print(analogRead(A0)); Serial.print(" | Digital pin: "); if (digitalRead(8) == HIGH) { Serial.println("High"); digitalWrite (13, HIGH); // if magnetic field is higher than threshold , switch-On built-in LED } else { Serial.println("Low"); digitalWrite (13, LOW); } delay(100); // wait 100 milliSeconds }
PROJECT TEST:
Apply power to your Arduino Uno board and open the Serial Monitor in the Arduino IDE.
Arduino will output the analog value sent by the module to the serial monitor.
If the value reaches the threshold setpoint set by VR1, the built-in LED of the Arduino will also light-up.
Adjust the threshold by turning VR1.