Introduction: Arduino Magnetic Hall Sensor Tutorial

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.

Step 1: Things You Need

For this instructables we will need following things :

Arduino uno

Hall sensor

Jumper wires
Breadboard (optional)

Step 2: Connections

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.

Step 3: Code

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
}

Step 4: Output

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.