HOW to Detect South Magnetic Field with ESP32
Description
In this kit, there is a Hall sensor which mainly adopts a A3144 linear Hall element. The element P1 are composed of a voltage regulator, a Hall voltage generator, a differential amplifier, a Schmitt trigger, a temperature compensation circuit and an open-collector output stage. In the experiment, we will use the Hall sensor to detect the magnetic field and display the test results on the shell.
Working Principle
When the sensor detects no magnetic field or a north pole magnetic field, the signal terminal will be high level; when it senses a south pole magnetic field, the signal terminal will be low levels.
The stronger the magnetic field strength is, induction distance is longer.
Required Components
|
|
|
|
|
---|---|---|---|---|
ESP32 Board*1 |
ESP32 Expansion Board*1 |
Keyestudio DIY Hall Sensor*1 |
3P Dupont Wire*1 |
Micro USB Cable*1 |
Connection Diagram
Test Code
from machine import Pin
import time
hall = Pin(15, Pin.IN)
while True:
value = hall.value()
print(value, end = " ")
if value == 0:
print("A magnetic field")
else:
print("There is no magnetic field")
time.sleep(0.1)
Test Result
Connect the wires according to the experimental wiring diagram and power on. Click “Run current script”, the code starts executing, the string and the data will be displayed in the “Shell“ window. When the sensor detects no magnetic fields or the north pole magnetic field, Shell will show“1 There is no magnetic field”and the LED on the sensor will be off.
When it detects the south pole magnetic field, the Shell will show“0 A magnetic field”and the LED on the sensor will be on, as shown below. Press “Ctrl+C”or click“Stop/Restart backend”to exit the program.