Customer:
I’m having trouble with a hall sensor I purchased. My setup is: Hall sensor pin 1 to 5V, pin 2 to GND, and pin 3 to digital pin 2. I also have an LED on digital pin 13 with GND on the board.
Here’s my code:
int hallPin = 2;
int ledPin = 13;
int hallState;
void setup(){
Serial.begin(9600);
pinMode(hallPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop(){
hallState = digitalRead(hallPin);
if (hallState == HIGH){
Serial.print("No Magnet: ");
digitalWrite(ledPin, LOW);
}
if (hallState == LOW){
Serial.print("Magnet Is Near Sensor: ");
digitalWrite(ledPin, HIGH);
}
Serial.println(hallState);
delay(100);
}
When I bring a magnet close to the sensor, nothing happens. I’ve tried both poles of the magnet with the same result. What am I doing wrong?
Originally submitted via email support on 24 March 2016. Migrated to the forum for community visibility.