Detect Magnetic Field with Hall Effect Sensor

Detect Magnetic Field with Hall Effect Sensor

Objective

Learn how to use a Hall Effect sensor to detect the presence of a magnetic field and display the results using Arduino.

Required Components

Working Principle

The Hall Effect sensor produces an output voltage when exposed to a magnetic field, enabling detection and measurement of the field's presence.

Circuit Diagram

Hall Effect Sensor Circuit Diagram

Arduino Code


const int hallPin = 2;  // Hall Effect sensor connected to digital pin 2
int hallState = 0;

void setup() {
    Serial.begin(9600);  // Initialize serial communication
    pinMode(hallPin, INPUT);  // Set the Hall Effect sensor pin as input
}

void loop() {
    hallState = digitalRead(hallPin);  // Read the sensor state

    if (hallState == HIGH) {
        Serial.println("Magnetic Field Detected!");
    } else {
        Serial.println("No Magnetic Field.");
    }

    delay(1000);  // Wait for 1 second before the next reading
}
            

Results

The Arduino serial monitor will display either "Magnetic Field Detected!" or "No Magnetic Field," depending on the sensor's state.

Applications

Conclusion

Hall Effect sensors are highly useful for detecting and measuring magnetic fields in a wide range of applications.