Random Sensor: KY-025 Magnetic Reed Sensor

The KY-025 is a magnetic reed sensor. First, let’s delve into a Reed switch before looking at the rest of the hardware.

Reed Switches

Reed switch – https://microcontrollerslab.com/reed-switch-arduino-field-dectection/

A reed switch sits in a container to protect it. Upon the presence of a magnetic field, the metal inside connects letting electricity flow through. Otherwise, the switch is considered open. The reed switch does have magnetic poles. In my testing of the sensor, I found certain magnets affect the switch when placed on the top or bottom of the reed switch of the KY-025.

Magnetic Presence – https://microcontrollerslab.com/reed-switch-arduino-field-dectection/

Now onto the sensor.

The KY-025

KY-025

The sensor has 4 pins, AO (Analog Output), G (Ground), + (Power), and DO (Digital Output). Upon connection of the G and +, the L1 LED should light up to show the sensor is on. L2 LED should light up if a magnetic field is detected by the reed switch. The AO or Analog Output once connected to the Arduino gives a voltage output. The DO or Digital Output once connected to the Arduino gives a threshold output returning a 1 if it has been reached or a 0 if it has not. The AO and DO are inverse of each other meaning the AO dips if the threshold is reached.

Example Set Up

In my example, I set up a breadboard with two LEDs to signify when a magnetic field is present.

Wiring Set Up

Hook up your KY-025 so that the blue wire is hooked to A0 on the KY-025, the black wire is hooked to G on the KY-025, the red wire is hooked to + on the KY-025, and the white wire is hooked to DO on the KY-025.

Example Wiring

Code

Simple value output of Analog and Digital readings

To start us off, we set up all our pins, SensorAnalog, SensorDigital, ledRed, and ledGreen, to their correct wiring on the Arduino. We declare values, aValue and dValue, for storing our readings from the outputs, SensorAnalog and SensorDigital. Within setup(), we declare the types of pins for Arduino. Within loop(), we first assign our aValue and dValue to the readings on the KY-025. Using the dValue(), we can tell if there is a magnetic field and consequently light up the green LED if there is one or the red LED if there isn’t one. Finally, we wait half a second before turning both lights off and print our values into the Serial Monitor.

Upon running this code along with the wiring if you glance at the Serial Monitor, the analog output or voltage is interesting. Unlike the digital output which returns a 0 or a 1 if the limit has been reached, the analog gives a value of around 1023. Online resources have pointed out that this output is a voltage reading. I have tried playing around with it but my magnets always give a fluctuating reading of 19-20.

Video of Example

Resources

These are the websites I used to gather the information I found on the KY-025. They offer explanations along with some more examples.

KY-025 ANALOG, MAGNETIC REED SENSOR: https://sensorkit.joy-it.net/en/sensors/ky-025

Reed Switch Interfacing with Arduino – Magnetic Field Detection: https://microcontrollerslab.com/reed-switch-arduino-field-dectection/


Posted

in

by

Tags:

Comments

Leave a Reply

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