A Raspberry Pi Pico and KY-003 Hall Magnetic Sensor

In this article, we connect a KY-003 Hall Magnetic Sensor to a Raspberry Pi Pico, any Rp2040 type board will be suitable. We actually tested this with a Cytron Maker Pi Pico

We will use Micropython for these examples but of course you can use the Arduino IDE as well if you have Raspberry Pi Pico support enabled

This module uses a 3144EUA-S Hall-effect switch IC

Hall effect sensor is a type of sensor which detects the presence and magnitude of a magnetic field using the Hall effect. The output voltage of a Hall sensor is directly proportional to the strength of the field.

Hall sensors are used for proximity sensing, positioning, speed detection, and current sensing applications. Frequently, a Hall sensor is combined with threshold detection to act as a binary switch.

The sensor looks like this

Parts Required

You can connect to the module using dupont style jumper wire.

Name Link
Raspberry Pi Pico
37 in one sensor kit
Connecting cables

 

Schematic/Connection

Pico SENSOR
GPIO28 S
3v3 +
GND

 

Code Examples

Basic example

from machine import Pin, Timer
from time import sleep

# Initialization of GPIO28 as input
sensor = Pin(28, Pin.IN, Pin.PULL_DOWN)

# Continuous loop for continuous serial output
while True:
    if sensor.value() == 0:
        print("No magnetic field")
    else:
        print("Magnetic field")

    print("---------------------------------------")
    sleep(0.5)

 

REPL Output

You will need to find a magnetic source and move it close to the sensor

>>> %Run -c $EDITOR_CONTENT
No magnetic field
—————————————
No magnetic field
—————————————
No magnetic field
—————————————
No magnetic field
—————————————
No magnetic field
—————————————
No magnetic field
—————————————
No magnetic field
—————————————
No magnetic field
—————————————
Magnetic field
—————————————
Magnetic field

Links

https://github.com/getelectronics/rp2040learning/tree/main/Sensor%20Kit/KY-003%20Hall%20Magnetic%20Sensor

 

Related posts

A Raspberry Pi Pico and KY-001 Temperature Sensor

A Raspberry Pi Pico and KY-006 Passive Buzzer

A Raspberry Pi Pico and KY-012 Active Buzzer

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More