Arduino Magnetic Hall Sensor Tutorial

by Utsource in Circuits > Arduino

984 Views, 0 Favorites, 0 Comments

Arduino Magnetic Hall Sensor Tutorial

20191119_185607.jpg
Hi guys in this instructables we will learn how to use hall Sensor with Arduino. So basically hall Sensor is a sensor which can sense the magnetic field around it and it can tell is there a magnetic field around it and how strong or weak Magnetic Field is around it.

Things You Need

1.jpg
Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png

For this instructables we will need following things :

Arduino uno

Hall sensor

Jumper wires
Breadboard (optional)

Connections

3.png
2-1.png
There are two ways to use a hall sensor :

1- digital hall Sensor

2- analog hall sensor

Digital hall sensor : for digital hall sensor you need to connect digital pin of hall sensor as shown in schmatics. This one will tell if there is a magnetic field or not.

Analog hall Sensor : for analog hall sensor you need to connect analog pin of hall Sensor as shown in schmatics. This one will tell that how strong Magnetic Field is.

Code

images(110).jpg
For the the digital hall sensor copy the following code :

const int hall_Sensor=2;
int inputVal = 0;

void setup()
{
pinMode(13, OUTPUT); // Pin 13 has an LED connected on most Arduino boards:
pinMode(hall_Sensor,INPUT); //Pin 2 is connected to the output of proximity sensor
Serial.begin(9600);
}

void loop()
{
if(digitalRead(hall_Sensor)==HIGH) //Check the sensor output
{
digitalWrite(13, HIGH); // set the LED on
}
else
{
digitalWrite(13, LOW); // set the LED off
}
inputVal = digitalRead(hall_Sensor);
Serial.println(inputVal);
delay(1000); // wait for a second
}

For analog hall Sensor copy the following code :
const int hall_Sensor=A0;
int inputVal = 0;

void setup()
{
pinMode(13, OUTPUT); // Pin 13 has an LED connected on most Arduino boards:
pinMode(hall_Sensor,INPUT); //Pin 2 is connected to the output of proximity sensor
Serial.begin(9600);
}

void loop()
{
if(digitalRead(hall_Sensor)==HIGH) //Check the sensor output
{
digitalWrite(13, HIGH); // set the LED on
}
else
{
digitalWrite(13, LOW); // set the LED off
}
inputVal = analogRead(hall_Sensor);
Serial.println(inputVal);
delay(1000); // wait for a second
}

Output

5.png
4.png
After uploading the code and Connecting the arduino via usb to computer and opening serial monitor and then you can see :

1- in case of digital hall sensor , if you take a magnet near to it then it will show 0 or 1 where 1 means the magnetic field is present and vice versa.

2- in case of analog hall sensor, if you take magnet near to hall sensor then you can see on serial monitor that it will show the intensity of magnetic field near it where 0 is no magnetic field and 1024 if very high magnetic field.