Micropython Lesson 14
Use hall effect sensor to detect magnetic fields
- Using Hall Effect sensor and detect magnetic fields.
- Applications of Hall Effect Sensor
There are actually, two different types of Hall sensors one is a Digital Hall sensor and the other is an Analog Hall sensor. The digital Hall sensor can only detect if a magnet is present or not (0 or 1). But an analog hall sensor’s output varies based on the magnetic field around the magnet that is, it can detect how strong or how far the magnet is. This project will aim only at the digital Hall sensors, for they are the most commonly used ones.
In a Hall Effect sensor, a thin strip of metal has a current applied along with it. In the presence of a magnetic field, the electrons in the metal strip are deflected toward one edge, producing a voltage gradient across the short side of the strip (perpendicular to the feed current).
Connect the magnetic sensor to the Magicbit. For this demonstration, we connect the magnetic sensor to the D32 pin of the Magicbit. After connecting the magnetic sensor to the Magicbit connect it to your pc and upload the code below.
from machine import Pin import time hall_sens = Pin(32, Pin.IN) while True: print(hall_sens.value()) time.sleep_ms(1000)
This Magnetic sensor gives digital outputs. Therefore, you can open the serial monitor and see the outputs. ‘1’ for occurred a magnetic field near to the sensor ‘0’ for there is no any considerable magnetic field nearby the sensor