Project tutorial
Hall effect sensor with Arduino

Hall effect sensor with Arduino © Apache-2.0

In this project we will use interrupts function of Arduino to detect the magnet near Hall sensor and glow a LED

  • 12,180 views
  • 1 comment
  • 24 respects

Components and supplies

Apps and online services

About this project

Sensors have always been a vital component in any Project. These are the ones which convert the real real-time environmental data into digital/variable data so that it can be processed by electronics. There are many different types of sensors available in the market and you can select one based on your requirements. In this project we will learn how to use a Hall sensor a.k.a Hall effect sensor with Arduino. This sensor is capable of detecting a magnet and also the pole of the magnet.

Why detect a magnet?, You may ask. Well there are a lot of applications which practically use Hall Effect sensor and we might have never noticed them. One common application of this sensor is to measure speed in bicycles or any rotating machines. This sensor is also used in BLDC motors to sense the position of Rotor Magnets and trigger the Stator coils accordingly. The applications are endless, so let’s learn how to Interface Hall effect sensor Arduino to add up another tool in our arsenal. Here are some projects with Hall sensor

In this tutorial we will use interrupts function of Arduino to detect the magnet near Hall sensor and glow a LED. Most of the time Hall sensor will be used only with Interrupts because of their applications in which high reading and executing speed is required, hence let us also use interrupts in our tutorial.

Hall Effect Sensors:

Before we dive into the connections there are few important things that you should know about Hall Effect sensors. There are actually, two different types of Hall sensors one is Digital Hall sensor and the other is Analog Hall sensor. The digital Hall sensor can only detect if a magnet is present or not (0 or 1) but an analog hall sensor’s output varies based on the magnetic field around the magnet that is it can detect how strong or how far the magnet is. In this project will aim only at the digital Hall sensors for they are the most commonly used ones.

As the name suggests the Hall Effect sensor works with the principle of “Hall effect”. According to this law “when a conductor or semiconductor with current flowing in one direction was introduced perpendicular to a magnetic field a voltage could be measured at right angles to the current path”. Using this technique, the hall sensor will be able to detect the presence of magnet around it. Enough of theory let’s get into hardware.

Code

codeArduino
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
int val=0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), test, CHANGE);
Serial.begin(9600);
}

void loop() {
digitalWrite(ledPin, state);
Serial.println(val/2);
}

void test() {
state = !state;
val++;
}

Schematics

circuit
Circuit diagram of interfacing hall effect sensor with arduino 0 ju2ajwdhuf

Comments

Add projectSign up / Login