Friday 8 February 2019

Hall effect sensor with Arduino


Hall effect sensor:
The Hall effect sensor works on the principle of the Hall effect, which states that whenever a magnetic field is applied in a direction perpendicular to the flow of electric current in a conductor, a potential difference is induced. This voltage can be used to detect whether the sensor is in the proximity of a magnet or not.
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.
Pin diagram of Hall Effect:



Hall Effect Sensor Principles:



Hall Effect sensor with Arduino:



Code for Hall Effect sensor with Arduino:

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++;
}









0 comments:

Post a Comment

if you have any doubt please let me know