HallSensor \ Learning \ Wiring ALPHA 1.0
Author: Hernando Barragán
Description: Wiring is an electronic sketchbook and hardware electronics for developing ideas. It is a context for learning fundamentals of computer programming and prototyping with electronics within the context of the electronic arts.
Keywords: Wiring, Processing, Interactive Media, Electronic Arts, Programming, C, C++, Hernando Barragán

Search wiring.org.co:

This example is for Wiring version 0023+. 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

    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
      }
    }