HALL SENSOR

hall sensor

const int hallPin = 3; // the number of the hall effect sensor pin

const int ledPin = 2; // the number of the LED pin

// variables will change:

int hallState = 0; // variable for reading the hall sensor status

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT);

// initialize the hall effect sensor pin as an input:

pinMode(hallPin, INPUT);

}

void loop(){

// read the state of the hall effect sensor:

hallState = digitalRead(hallPin);

if (hallState == LOW) {

// turn LED on:

digitalWrite(ledPin, HIGH);

}

else {

// turn LED off:

digitalWrite(ledPin, LOW);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s