by Rachel Young
The Sensor
The KY-024 Linear Magnetic Hall Sensor is a magnetic sensor that reacts when a magnetic field is present. The sensor provides both digital and analog outputs, but for my project I only utilized the digital output. The sensor’s digital output acts as a simple on/off switch with a value of either 0 or 1 (low or high).
The sensor has four components, as pictured on the diagram above:
- Analog Input Pin (goes to A0)
- Ground (goes to GRND)
- Board Power Line (goes to 5V)
- Digital Signal Pin (goes to digital pin)
Random Sensor Project
For my project I incorporated a real-life application of magnetic fields – an MRI scanner. When the MRI is turned on, the protons in the human body align with the magnetic field produced by the machine. The result is a 90º shift from the original direction of the protons. My project illustrates this phenomenon with the use of LEDs as well as LCD animations.
Schematics
The natural state (no magnetic field present) is when the upper LED is lit and the arrows on the LCD are moving in an upwards direction. When a magnetic field is present, the rightmost LED will light up and the LCD will picture arrows moving towards the right.
Code
Here is the portion of my code that deals with the sensor itself. I have removed the parts that include the LCD and LEDs since it is relatively straightforward:
Animations
As previously mentioned, my project also included animated arrows that appeared on the LCD and moved in specific directions depending on the status of the output. Within the LiquidCrystal library, there is a function called createChar() that allows you to create custom characters on the LCD. Each character is represented by an array of 8 bytes (one per row), and the five least significant bits of each byte determine the pixels in a given row.
In order to create my animations, I used this nifty tool that allows you to draw the characters as you want them to appear on the LCD. The tool then generates the code for the given character so that you can use it without having to write the bytes by hand.
Images
Useful Tutorials / Materials
- https://arduinomodules.info/ky-024-linear-magnetic-hall-module/
- https://nerd-corner.com/hallsensor-ky-024-arduino-code/
- https://projecthub.arduino.cc/tusindfryd/57d77608-cd7e-4d6a-b52f-7a604cc121c5
Leave a Reply