Hall Effect Help

I created this code

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);

int hallSensorPin = 2;
int ledPin = 3;
int state = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(hallSensorPin, INPUT);
}

void loop(){

state = digitalRead(hallSensorPin);

if (state == LOW) {
lcd.setCursor(0,1);
lcd.print("ON");
digitalWrite(ledPin, HIGH);

} 

else {
digitalWrite(ledPin, LOW);
lcd.setCursor(0,1);
lcd.print("OFF");
}
}

However, for some reason, my hall effect sensor is flickering on and off. Is there any way to adjust my code to reduce sensitivity? Thanks so much.

Once I figure it out ,I'll be able to learn rpm detection.

pullup on input?
and also, hall effect sensors are not necessarily on-off only and can be linear (depend on polarity and intensity) and so on. Please show where you get the sensor from.

What is the part number of the Hall sensor?

That can be indicative of a floating input.

Change the INPUT to INPUT_PULLUP and try it.

1 Like

That worked. Thanks so much!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.