Hall effect sensor with Arduino

What is Hall Effect, what is the Hall Effect sensor, how does the Hall Effect sensor works & how to connect the KY-024 linear magnetic and KY-034 analog Hall Effect sensor with Arduino are some questions that may arise in your mind while working with the Hall Effect sensor.

Hello everyone, welcome back to my channel today we are going to see about the hall effect sensor Arduino. so let’s begin.

What is Hall Effect??

When the current carrying conductor or semiconductor place is placed near the magnet which produces magnetic field perpendicular to the flow of current, then a potential voltage difference is created across conductor this voltage is known as Hall Effect.

hall sensor

To understand this we see one example, suppose as shown in fig. we have a metallic conductor which we will connect to the battery. One end of the conductor will be connected to the positive side of the battery and another end will be connected to the negative side of the battery. Due to this current starts flowing through the conductor. The flow of current will be from higher potential towards lower potential i.e. from the positive side towards the negative side. The flow of current is represented by (I) in fig. But the flow of electrons will be in opposite direction of than the current. Electron flow is represented by (e).  

hall effect

You can see the flow of electrons through the conductor. If you measure the voltage across the side of the conductor then you will get no potential difference but when you place a magnet near the current carry conductor then magnetic field lines are generated which will be perpendicular to the flow of current this will generate a force on a charged particle. The force exerted on charged particle is called Lorentz force. Now according to Fleming's left-hand rule your thumb, forefinger, and middle finger will be perpendicular to each other. If the forefinger represents magnetic field (M), the middle finger represents charge velocity (V) then the thumb will represent force (F) on charge. Consider charge is of negative charge because of electrons due to force applied on charge all negative charge electrons will be accumulated at one side of the conductor. 

hall effect measurement

The side which has a large number of electrons will represent the negative side and the side that has less number of electrons accumulated will represent the positive side. When we measure the voltage across the conductor through a voltmeter then we will get a voltage difference which is called as HALL voltage.

How Hall Effect sensor works??

hall sensor working

Hall Effect Sensors are triggered by an external magnetic field. The figure shown is just an example to demonstrate how Hall Effect actually works. When we connect the battery to the sensor terminal then current flows through it. Current start flowing from positive terminal or higher potentiometer towards negative terminal or lower potentiometer but electron travels from the opposite direction. The flow of electrons will be from the negative side toward the positive side. When we introduce a magnet close to the sensor with certain polarity then as discussed early the electrons will be deflected at one side of the sensor forming a curve shape flow of electrons. The magnetic flux lines exert a force on the conductor which deflects the charge carriers which are electrons towards one side of the conductor. The electron accumulated at one side of the sensor causes the potential voltage difference this voltage is called HALL voltage. The closer the magnet near the sensor more is the deflection of electrons toward one side hence more HALL voltage generation.

Hall voltages depend upon flux density and polarity (North and South Poles) generally a south pole of a magnet. Hall voltages are proportional to the strength of magnets. Hall sensor tells about magnet strength or magnitude and polarity of magnet which is a place near to it, for example, the sensor only generates a voltage when it is facing south pole and generates no voltage when the north pole is introduced. Hall voltages generated are small so a built-in amplifier is used along with it inside the Hall Effect sensor. Hall Effect sensors are low cost, high accuracy, fast response, and an easy-to-use sensor for detecting a magnetic field. Hall Effect sensor has immune to external environments such as vibration, dust, and water.

hall sensor

Digital  Hall sensor

Hall Effect sensor comes with two different output types analog and digital. Analog Hall sensors are also called linear hall sensors. In analog type Hall sensor when magnet strength increases then output voltage also increases. The Hall sensor uses an amplifier as the Hall voltage generated due to magnets is very small. The sensor uses an op-amp as an amplifier. The output of the analog hall sensor is directly taken out from the amplifier. The output of the hall sensor continues to increase until it reaches a saturation point. After the saturation point output voltage will have no effect on the magnetic field it will remain constant or flat curve. Analog hall sensor output is directly proportional to the strength of the magnetic field.

Digital/Analog Hall sensor

Digital Hall Effect uses a Schmitt trigger to trigger the output voltage. When the hall voltage is less than the pre-defined or set value then the output voltage is 0 or low and if the hall voltage is greater than the pre-defined value then the output voltage is 1 or high. There are two types of digital Hall sensors (Bipolar & Unipolar). The bipolar sensor operates when they are facing toward the South Pole and the unipolar sensor is operated when they are facing toward the North Pole.

hall current sensor

KY-035 Analog Hall sensor

In the ky-034 Hall sensor, we only have a digital pin that gives output in 1 & 0 when there is a magnetic field present or not. Ky-034 has no built-in LED so we will use an external LED to determine the magnetic field.                      

KY-024 linear Hall sensor

Ky-024 consists of both analog and digital output along with a built-in LED & built-in potentiometer to set the threshold. Ky-024 has two built-in LEDs. One LED indicates the sensor board module is in an ON state and another LED indicates the signal received by the sensor when the magnetic field is present. It has four pins (Analog Output, Digital Output, Ground, and VCC). It also has comparator LM393. By rotating the potentiometer, we can increase sensitivity or threshold value. If the value from the sensor is less than the threshold value then it will read 0 (LOW). If the value from the sensor is more than the threshold then it will read as 1(HIGH).

Difference between KY-024 vs KY-035 analog Hall sensor

Sr.no Parameter KY-035 KY-024
1) Operating voltage 3.3V to 5.5V 3.3V to 5.5V
2) Outputs only Digital Both Analog & Digital
3) Build in resistor 10kΩ 100kΩ potentiometer
4) Sensitivity Cannot set Can set sensitivity


Applications of Hall Effect Sensor

  • Magnetic field sensing element
  • Proximity detectors
  • Linear or Angular displacement transducers
  • For detecting the rotating direction and speed of objects
  • Controlling motor
  • Disk drives
  • Keyboard switch
  • Tachometers

 Parts Required

  • KY-024 & KY-035 (hall sensor)
  • Arduino
  • Jumper wires
  • LED
  • Breadboard

Circuit Diagram

a3144 hall effect sensor

Connect the ground pin of the ky-035 sensor to the ground pin of Arduino, the VCC pin to 5v, and the Signal pin to 8. Also, connect the positive lead of LED to Arduino pin 11.

Code -

int Hall_pin_dig=8;    // for digital pin
int Hall_sensor_dig;  
int led_pin=11;        // led pin define

void setup() 
{
 pinMode(Hall_sensor_dig,INPUT);
 pinMode(led_pin,OUTPUT);
 Serial.begin(115200);
}

void loop() 
{
Hall_sensor_dig = digitalRead(Hall_pin_dig);  // for digital values
Serial.println(Hall_sensor_dig);  
if(Hall_sensor_dig==HIGH)
{
  digitalWrite(led_pin,LOW);
  Serial.println("Magnet NOT detected");  
}
else
{
  digitalWrite(led_pin,HIGH); 
  Serial.println("Magnet detected");  
}  
delay(1000);
}
 

First, initialize pins of Analog Hall sensor & LED. We have declared a variable name Hall_sensor_dig to read values from the Analog Hall sensor. In the void setup, we configure pins as INPUT or OUTPUT. We want to read values from the Hall sensor pin so we will declare it as INPUT and LED as OUTPUT. We also configure the baud rate to 115200.

In a void loop, we continuously read values from the Hall sensor and store values in variables. if we place the magnet close to the Hall sensor then the output we get is LOW. here we used LED which gets turned ON when output is LOW & gets turned OFF when output is HIGH (the magnet is not present). 

OUTPUT - 

hall current sensor

Now we used the serial monitor to observe the output. To open up the serial monitor, click on Tools > Serial Monitor or use the shortcut (SHIFT + CONTROL + M). Here you can see in the Serial monitor when there is no magnet near the Hall sensor then the digital output will be 1 and message ("Magnet not present"). But when we place a magnet near the Hall sensor then the digital output will be 1 ("Magnet detected").  

Circuit Diagram



linear hall sensor


Connect the ground pin of the ky-024 sensor to the ground pin of Arduino, Analog pin to A0.VCC pin to 5v and Signal pin to 9. Also, connect the positive lead of LED to Arduino pin 11.

Code -

int Hall_pin_dig=8;    // for digital pin
int Hall_pin_An= A0;  // for analog pin
int Hall_sensor_An;
int Hall_sensor_dig;  
int led_pin=11;        // led pin define
void setup() 
{
 pinMode(Hall_pin_An,INPUT);
 pinMode(Hall_sensor_dig,INPUT);
 pinMode(led_pin,OUTPUT);
 Serial.begin(115200);
}

void loop() 
{
 // for digital values
Hall_sensor_dig =digitalRead(Hall_pin_dig);  // for digital values
Serial.print("Digital Values:");  
Serial.println(Hall_sensor_dig);  
if(Hall_sensor_dig==HIGH)
{
  digitalWrite(led_pin,HIGH);
  Serial.println("Magnet detected");  
}
else
{
  digitalWrite(led_pin,LOW); 
  Serial.println("Magnet NOT detected");  
}  

// analog values
 Hall_sensor_An = analogRead(Hall_pin_An); // for analog values
 Serial.print("Analog Values:");
 Serial.println(Hall_sensor_An); 
 
// if(Hall_sensor_An < 390)
// {
//    digitalWrite(led_pin,HIGH);
//     Serial.println("Magnet detected"); 
// }
//
// else
// {
//   digitalWrite(led_pin,LOW);
//  Serial.println("Magnet NOT detected"); 
//  }

  Serial.println("");
  Serial.print("");
  delay(2000);
 }
  
First, initialize the pins of the Hall sensor & LED. We have declared a variable name Hall_sensor_dig and Hall_sensor_An to read both values digital and analog from the same hall sensor. In the void setup, we configure pins as INPUT or OUTPUT. We want to read values from the Hall sensor pin so we will declare it as INPUT and LED as OUTPUT. We also configure the baud rate to 115200.

In the void loop, we continuously read values from the Hall sensor and store values in a variable. if we place the magnet close to the Hall sensor then the output we get is HIGH. here we used LED which gets turned ON when output is HIGH & gets turned OFF when output is LOW (the magnet is not present). 

OUTPUT -

hall sensor Arduino

Now we used the serial monitor to observe the output. To open up the serial monitor, click on Tools > Serial Monitor or use the shortcut (SHIFT + CONTROL + M). Here you can see in the Serial monitor when there is no magnet near the Hall sensor then the digital output will be 0 and analog output will be changed. But when we place a magnet near the Hall sensor then the digital output will be 1 and the analog output will be near 471. We can adjust the sensitivity by rotating the potentiometer in the clockwise or anti-clockwise direction.

 Conclusion - 

Today we learn about what is Arduino hall effect sensor, how to use the Hall sensor Arduino, the application of the Hall sensor & working principle of the Hall sensor. hall sensors are very small and very useful devices having a variety of applications.


"I hope you find this IoT blog very helpful to you. In the upcoming lesson, we will see more about IoT sensors till then bye. See you all in my next blog."

Close Menu