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 Digital Hall sensor and the other is 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. In 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 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).
Figure 1: Hall Effect Sensor (Magnetic Sensor)
Connect the magnetic sensor to the Magicbit. For this demonstration, we connect the magnetic sensor to D32 pin of the Magicbit. After connect 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. Therefor 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 near by the sensor