Hall effect sensors won't reset

Hello all.

Are hall effect sensors "latching" switches? If so, is the LED supposed to stay on?

Context:
I'm working on a stepper motor project and I have the stepper motor working the way we want, but I wanted to incorporate some hall effect sensors to use as end-stops. I wired a couple of them up to my project, passed a magnet in front of them and each one responded with a lit up LED when the magnet passed by it. When I uploaded my code, I couldn't get them to work correctly.

Instead of messing with the entire code, I isolated the sensors by running a minimized version of my code with just the basics.....read the sensors then print out the values in the serial monitor.

When I ran this code, both sensors read high right from the start. When I put a magnet in front of them, the LED would come on and the value in the window would show low (like it's supposed to). When I took the magnet away, the LED went off, but the value stayed at 0 (low). The other sensor reacted the same way. The only way I could "reset" them was to re-set the controller.

Below is a photo of these sensors I am using and the code (in case there is something in there that I messed up).

Thank you for your time,
Ron.

/* StepperZ_Project_rev29                         */
/* Program to control stepper motor with joystick along with 2 end stops  */

#include <AccelStepper.h>

/* ------- Defining Pins --------------------------------- */
const byte stepPin = D1;
const byte dirPin = D2;
const byte enaPin = D5;
const byte upStop = D6;
const byte downStop = D7;
const byte xJoyPin = A0;

/* ------- Pin Variables --------------------------------- */
int xJoy = 0;
int dirVal = -1;
int upStopVal = 1;
int downStopVal = 1;

/* ------- Variables for Calculations & Settings --------- */
long speedVal = 0.0;
long fastSpeed = 50000.0;
long slowSpeed = 100.0;
long accelFast = 500.0;
long accelSlow = 50.0;
long newPos = 0.0;

/* ------- Define the Stepper Driver --------------------- */
AccelStepper xStepper(AccelStepper::DRIVER, stepPin, dirPin);

/* ---------------- SET - UP FUNCTION -------------------- */
void setup()
/* ------------------------------------------------------- */
{
  Serial.begin(115200);

  xStepper.setMinPulseWidth(10);

  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enaPin, OUTPUT);
  pinMode(xJoyPin, INPUT);
  pinMode(upStop, INPUT);
  pinMode(downStop, INPUT);

  pinMode(enaPin, LOW);
  pinMode(upStop, LOW);
  pinMode(downStop, LOW);

  xStepper.setMaxSpeed(fastSpeed);
  xStepper.setAcceleration(accelFast);
  xStepper.setSpeed(0);

  delay(5);
}


/* ================= LOOP FUNCTION ======================= */
void loop()
/* ======================================================= */
{
  xJoy = analogRead(xJoyPin);                 /* check initial value of joystick and stops */
  upStopVal = digitalRead(upStop);
  downStopVal = digitalRead(downStop);

  Serial.println("");
  Serial.print("Stop values are = ");
  Serial.print(upStopVal);
  Serial.print(" & ");
  Serial.println(downStopVal);

  delay(1000);

}

It should work, they should not be "latching". I don't know what is going on.

Could you do a few things ?

  1. Make a minimal sketch, just the two inputs and the Serial Monitor.
  2. It does not compile for an Arduino Uno. Which Arduino board and which Arduino IDE version are you using ?
  3. What is the datasheet of the hall switch ? Can you give a link to where you bought the module ?
  4. How is the hall switch connected ?
  5. What happens if you turn the magnet North side towards the hall switch and then the South side and so on.

Koepel,

I appreciate you responding. I will do the sketch suggestion and get back to you.

For the other questions:
2. I'm using an ESP8266 NodeMCU and the regular Arduino IDE (ver. 1.8.18).
3. I haven't seen the data sheet. Sorry about the link. I was intending on supplying it in the original post. I purchased it from Amazon at this link.
4. I have the sensors wired with the signal wired going to D6 & D7 on my controller along the 3.3v and ground. Three wires each. I'm pretty sure those aren't wrong.
5. When I turn the magnets over to the opposite side (pole). The sensors will not respond (as expected).

I was pretty sure it should work too, that's why I posted. This is really strange to me.

Thank you again,
Ron.

Koepel,

Below is the sketch I just used. The sensors still respond the same. By the way, I didn't mention it in my post or my first reply, I had the sensors hooked up to their own 5v supply and it didn't change anything then either. I also got 2 more new sensors out and hooked them up and got the same response.

This is really baffling.

#include <AccelStepper.h>

/* ------- Defining Pins --------------------------------- */
const byte upStop = D6;
const byte downStop = D7;

/* ------- Pin Variables --------------------------------- */
int upStopVal = 1;
int downStopVal = 1;

/* ================ SET - UP FUNCTION ==================== */
void setup()
/* ======================================================= */
{
  Serial.begin(115200);

  pinMode(upStop, INPUT);
  pinMode(downStop, INPUT);

  pinMode(upStop, LOW);
  pinMode(downStop, LOW);

  delay(5);
}

/* ================= LOOP FUNCTION ======================= */
void loop()
/* ======================================================= */
{       /* check initial value of stops */
  upStopVal = digitalRead(upStop);
  downStopVal = digitalRead(downStop);

  Serial.println("");
  Serial.print("Stop values are = ");
  Serial.print(upStopVal);
  Serial.print(" & ");
  Serial.println(downStopVal);

  delay(1000);

}

To all, especially @Koepel,

I found the issue and it was me messing up. I re-tried the sensors with the stripped down sketch and with 5v supply to the sensors and they are reacting correctly.

I apologize for wasting your time.
Ron.

I'm glad you found the problem :smiley:
That is indeed the problem. Some hall switches start at 4.5V.
The ESP8266 has pins that are more or less 5V tolerant, so you may use the hall module with 5V.

If you upgrade to a ESP32, then you need better hall switches that work at 3V. The ESP32 does not have 5V tolerant pins.