In this project, we have used a hall sensor that is able to detect a magnet and also the pole of the magnet.


In this project, we have used a hall sensor that is able to detect a magnet and also the pole of the magnet.

About Project

Hall Effect Sensor

Few tips about Hall Sensor are as follows: The digital Hall sensor can only recognize if a magnet is present or not (0 or 1) but an analog hall sensor’s output varies depends on the magnetic field around the magnet that is it can recognize how powerful or how distant the magnet is. This project will direct only at the digital Hall sensors for they are the most usually utilized ones.

As per law “when a conductor or semiconductor with current flowing in one direction was organized perpendicular to a magnetic field a voltage could be estimated at right angles to the current path”.

With the help of this technique, the hall sensor will be capable to recognize the appearance of the magnet around it.

Hall sensor model.jpg

Arduino Hall Effect Sensor Working

Once we upload the code to the Arduino. We have utilized a 9V battery to power the whole set-up you can utilize any preferable power source. Now take the magnet close to the sensor and your LED will shine and if you get it away it will turn off.

What really happens inside is, when we take the magnet close to the sensor modifies its state. This change is sensed by the interrupt pin which will ask the toggle function inside which we change the variable “state” from 0 to 1. Hence the LED will turn on.

Now, when we drive the magnet away from the sensor, again the output of the sensor will develop. This change is again mentioned by our interrupt statement and hence the variable “state” will be modified from 1 to 0. Thus the LED if Turned off. The same repeats every time you take a magnet close to the sensor.

IoT Training Online will give you a thorough view of Customized IoT Solutions.

        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);

void loop() {
digitalWrite(ledPin, state);

void test() {
state = !state;
rasika Joshi
hIoTron offers an End-to-End IoT Training with live use cases using IoT hardware kit.