This example is for Wiring version 0024+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
Hall sensor by Juan Guillermo (Coco) Gomez
A hall sensor is a magnetic field sensor, it can detect when a magnet is nearby. This example turns on a light (LED) connected to a digital pin when a magnet is near the Hall sensor
A hall sensor is a magnetic field sensor, it can detect when a magnet is nearby. This example turns on a light (LED) connected to a digital pin when a magnet is near the Hall sensor

int ledPin = 48; // onboard LED in the Wiring hardware (pin 48) int pinHall = 0; // Pin for the Hall sensor int pinLed = 1; // LED that turns on if the magnet is near void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin as output pinMode(pinLed, OUTPUT); // sets the digital pin as output pinMode(pinHall, INPUT); // sets the digital pin as input digitalWrite(ledPin, HIGH); //turn on onboard LED } void loop() { if (digitalRead(pinHall) == HIGH) // If a magnet is near the Hall sensor { digitalWrite(pinLed, HIGH); // turns ON the LED } else { digitalWrite(pinLed, LOW); // if not turns OFF the LED } }