Created
March 18, 2013 15:32
-
-
Save sjurlur/5188018 to your computer and use it in GitHub Desktop.
Hall effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Hall Effect Switch | |
Turns on and off a light emitting diode(LED) connected to digital | |
pin 13, when Hall Effect Sensor attached to pin 2 is triggered by a magnet | |
Hall effect sensor used is the A1120EUA from Allegro Microsystems | |
This example code is in the public domain. | |
http://www.hobbytronics.co.uk/arduino-tutorial8-hall-effect | |
*/ | |
// constants won't change. They're used here to set pin numbers: | |
const int hallPin = 12; // the number of the hall effect sensor pin | |
const int ledPin = 13; // the number of the LED pin | |
// variables will change: | |
int hallState = 0; // variable for reading the hall sensor status | |
void setup() { | |
Serial.begin(9600); | |
// initialize the LED pin as an output: | |
pinMode(ledPin, OUTPUT); | |
// initialize the hall effect sensor pin as an input: | |
pinMode(hallPin, INPUT); | |
} | |
//rød er fram | |
void loop(){ | |
// read the state of the hall effect sensor: | |
hallState = digitalRead(hallPin); | |
Serial.println(hallState); | |
//Serial.println(analogRead(A0)); | |
if (hallState == LOW) { | |
// turn LED on: | |
digitalWrite(ledPin, HIGH); | |
} | |
else { | |
// turn LED off: | |
digitalWrite(ledPin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment