Menu Close

Arduino – Digital and Analog Hall Magnetic Sensor

This tutorial of Robo India explains the working concept of Hall Magnetic sensor as Digital and Analog sensor.

1. Introduction:

This project uses a Hall Effect sensor to detect the presence of a magnet. Whenever a magnet moves past this sensor, it can detect it. It varies its output voltage in response to a magnetic field. Hall Effect sensors are available with either analog or digital outputs.

The analog output sensors provide linear output values and are taken directly from the output of the operational amplifier with the output voltage being directly proportional to the magnetic field passing the Hall sensor.

Digital output sensors employ a Schmitt trigger with built in hysteresis connected to the op-amp. The sensor device switches between the “off” and “on” condition, when the sensor output exceeds a preset value.

2. Working Principle:

The Hall Effect sensor works on the principle of the Hall Effect. The Hall element is constructed from a thin sheet of conductive material with output connections perpendicular to the direction of current flow. When subjected to a magnetic field, it responds with an output voltage proportional to the magnetic field strength.

3. Hardware required

S.No.ItemQuantity
1.Arduino 1
2.Linear analog Hall magnetic module 1
3.Male to Female Jumper Wires 3

4. Building Circuit

Digital Interfacing:

Analog Interfacing:

5. Programming:

You may download this Arduino sketch (code) for digital output from here.

//Robo India tutorial on Hall Magnetic Module
//https://www.roboindia.com/tutorials

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
}

You may download this Arduino sketch (code) for analog output from here.

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
}


6. Output

After uploading the code, put a magnet close to the linear Hall sensor, and the built-in LED of Arduino will turned OFF, and indicator LED on the linear Hall sensor will light up.

The sensor outputs a logic 1 (+5V) at the digital output when a magnet is placed in front of the sensor and a logic 0 (0V), when there is no magnet in front of the sensor.

Do the same for Analog output. Arduino scales an analog signal in a range of 0-1023.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

1 Comment

Leave a Reply