Introduction
In this tutorial, we will learn about the KY-003 module, what is a Hall-effect switch and we will build a simple project to sense magnetic fields using the KY-003 with an Arduino.
Magnetic Hall Sensor KY-003
The KY-003 Module will be our main component for this tutorial. This module has a 3144EUA-S Hall-effect switch IC and mounted on a breakout board with an LED and resistor. Figure 1 shows the module as seen in fritzing.
Pinout
The KY-003 module has three pins.
Component Pin | Arduino Uno board Pin |
---|---|
(-) | GND |
middle | +5V |
S | Signal |
What is a Hall-Effect Switch?
A hall effect switch changes its state when it senses a magnetic field. In the case of our module, it connects its Signal pin to Ground (GND) whenever it senses a magnetic field nearby. Figure 2 shows the Block Diagram of the IC taken from its datasheet.
Project - Arduino Magnetic Field Detector
After learning about the KY-003 module and the 3144EUA-S IC, it is now time to build a project using the module. Our project will activate the built-in LED of an Arduino Uno when there is a magnetic field near the KY-003 module.
Components
For this project, we need the following components:
- Arduino Uno board (1 pc.)
- KY-003 Magnetic Hall Sensor (1 pc.)
- Jumper wires
Wiring Diagram
Figure 3 shows the connection between the Arduino Uno and the KY-003 Magnetic Hall Sensor.
The KY-003 module pins are connected to the Arduino Uno board as follows:
Component Pin | Arduino Uno board Pin |
---|---|
(-) | GND |
middle | +5V |
S | 10 |
The 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-003.ino and upload it to your Arduino board.
// Arduino and KY-003 module tutorial
void setup() {
pinMode(10, INPUT_PULLUP); // KY-003 module is connected to pin 10
pinMode(13, OUTPUT); // pin 13 is internally connected to built-in LED
}
void loop() {
// check if KY-003 senses a magnetic field
if(digitalRead(10) == LOW) digitalWrite(13, HIGH); // switch On LED if KY-003 senses a magnetic field nearby
else digitalWrite(13, LOW); // switch Off LED
}
Project Test
Apply power to your Arduino Uno board. If a magnet is placed near the KY-003 module, the Arduino’s built-in LED will light-up.