Hall Effect Sensor

Hall Effect Sensor

tilt

Hall effect sensors detect whether a magnet is near. Useful for non-contact/waterproof type switches, position sensors, rotary/shaft encoders.


Components

1 x Hall Effect Sensor
1 x Arduino Uno
1 x 10K Ohm Resistor
1 x LED
jumper wires
 

Setup


Arduino sketch

Adapted from Adafruit example.

#define HS 4
#define LED 13

void setup() {
  pinMode(LED, OUTPUT);
   Serial.begin(9600);
  pinMode(HS, INPUT);
  digitalWrite(HS, HIGH);  // activate internal pullup
}

void loop() {
  Serial.println(digitalRead(HS));
  if(digitalRead(HS) == LOW) {
    digitalWrite(LED, HIGH);
    delay(100); // simple debounce
  } else {
    digitalWrite(LED, LOW);
    delay(100);
  } 
}