|
// Hall sensor
// by Juan Guillermo (Coco) Gomez
int ledPin = 48; // diagnostic LED on the Wiring I/O board (pin 48)
int pinHall = 0; // Pin for the Hall sensor
int pinLed = 1; // Pin for the led that turns on if the magnetic field 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 the Wiring board diagnostic 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
}
}
|