Introduction
This experiment demonstrates how to use a Hall Effect sensor to detect magnetic fields with an Arduino.
Components Needed
- Hall Effect Sensor
- Arduino (e.g., Uno, Nano)
- LED
- 220-ohm Resistor
- Jumper wires
Circuit Setup
- Connect the Hall Effect sensor to a digital input pin on the Arduino (e.g., D2).
- Connect the LED to one of the digital pins of the Arduino using a 220-ohm resistor in series.
When the Hall sensor detects a magnetic field, the LED will light up.
Code for Hall Effect Sensor
Upload the following code to your Arduino to detect magnetic fields:
const int hallPin = 2;
const int ledPin = 13;
void setup() {
pinMode(hallPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(hallPin) == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED when magnetic field is detected
} else {
digitalWrite(ledPin, LOW); // Turn off LED when no magnetic field
}
}
Explanation
The Hall Effect sensor detects magnetic fields and sends a signal to the Arduino. If the signal is HIGH, the LED is turned on.
Troubleshooting
- If the LED doesn't light up, ensure that the Hall Effect sensor is connected correctly and positioned near a magnetic field.
- If the circuit is unresponsive, check the sensor's power and connections.