How to use a Hall Effect Sensor
What is a Hall Effect Sensor?
The hall effect sensor is a type of magnetic sensor which can be used for detecting the strength and direction of a magnetic field produced from a permanent magnet or an electromagnet with its output varying in proportion to the strength of the magnetic field being detected.
Wiring
Getting started
The following code uses digitalRead()
to get a integer (1/0) representing the detection of magnet.
const int hallSensorPin = 2; // Hall Effect sensor connected to digital pin 2
int hallSensorState; // Variable to store the state of the sensor
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
pinMode(hallSensorPin, INPUT); // Set the Hall Effect sensor pin as an INPUT
}
void loop() {
hallSensorState = digitalRead(hallSensorPin); // Read the state of the sensor
Serial.println(hallSensorState);
delay(100);
}