Can't get hall effect sensors to work (double input, always on)

Hi,
I'm currently having some trouble getting my hall effect sensors to work. Originally I bought these (KY-003/A3144 digital hall effect sensor and they were working fine until I decided to downsize my project a bit. Each of the hall effect sensors I bought came with their own little pcb, led and resistor. So they were pretty bulky. Eventually I decided to just cut the hall effect sensor from their pcb to use them on a single pcb.

This is what it currently looks like
Cables on the left:
red: VCC
black: ground
yellow/blue/white/green: Pro Micro pin 10,16,14,15

I'm using the Joystick-library to turn these into contactless buttons for a HID controller. The problem now is, that they are not working properly anymore. I'm able to activate the sensors with a magnet, but putting the magnet close to the hall effect sensors also triggers a second sensor. Sometimes one of the sensors stays active the whole time, even after moving the magnet further away.

So, the question now is: What am I doing wrong here? The only thing that is now missing compared to the "bulkier" version is the led and the resistor. Removing the led shouldn't affect the sensor, so... is it the resistor? Do I have to add some pullup-resistors, even when using INPUT_PULLUP?

Thanks in advance!

Do you have a data sheet or ID for the sensor IC? If not, you are operating blind.

It is possible for magnetometers and Hall effect sensors to become saturated and "stuck" when exposed to high magnetic fields. Cycling the power should solve the problem. Also try reversing the magnet poles and withdrawing it slowly.

This is the data sheet provided by the shop where I bought them, hope it helps

The sensor is open collector, so pullup resistors of some sort are required. You might try adding a 10K external pullup, if INPUT_PULLUP doesn't solve the problem.

Nice picture but not much help to me. An annotated schematic showing all connections, power and ground would help a lot.

Which ProMicro.
8Mhz/3.3volt or 16Mhz/5volt.
Sensors are 5volt only.
Leo..

Thats because they are closer together.

DOes it STAY stuck if you remove the magnet altogether? Is there some iron nearby that could be magnetised?

@gilshultz Here's the schematic

@Wawa It's the 5volt pro micro

@johnerrington

Thats because they are closer together.

The distance between the sensors didn't change.
This is what it originally looked like (minus the sensors of course)

DOes it STAY stuck if you remove the magnet altogether? Is there some iron nearby that could be magnetised?

I've added the pullup-resistors as seen in the schematic. Once I plug in the usb cable, one of the sensors is immediately shown as active (=LOW). The longer I leave the pro micro connected, the more sensors are shown as active, even without any magnets nearby.

Here's the code that I'm currently using, just in case:

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
  4, 0,                  // Button Count, Hat Switch Count
  false, false, false,     // X and Y, but no Z Axis
  false, false, false,   // No Rx, Ry, or Rz
  false, false,          // No rudder or throttle
  false, false, false);  // No accelerator, brake, or steering

void setup() {
  // Initialize Button Pins
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  //pinMode(10, INPUT_PULLUP);
  //pinMode(14, INPUT_PULLUP);
  //pinMode(15, INPUT_PULLUP);
  //pinMode(16, INPUT_PULLUP);
  

  // Initialize Joystick Library
  Joystick.begin();
}

// Last state of the buttons
int lastButtonState[4] = {0,0,0,0};
int buttonMap[4] = {6,7,8,9};

// ButtonMap = 0, Pin 10 = UP
// ButtonMap = 1, Pin 15 = RIGHT
// ButtonMap = 2, Pin 16 = DOWN
// ButtonMap = 3, Pin 14 = LEFT

// ButtonMap = 4, Pin 9 = Button 1
// ButtonMap = 5, Pin 8 = Button 2
// ButtonMap = 6, Pin 7 = Button 3
// ButtonMap = 7, Pin 3 = Button 4
// ButtonMap = 8, Pin 2 = Button 5
// ButtonMap = 9, Pin 4 = Button 6

// ButtonMap = 10, Pin 20 = Select Button 1
// ButtonMap = 11, Pin 19 = Start Button 2

// ButtonMap = 12, Pin 5 = Other Button
// ButtonMap = 13, Pin 6 = Other Button
// ButtonMap = 14, Pin 18 = Other Button
// ButtonMap = 15, Pin 21 = Other Button


void loop() {

  // Read pin values
  for (int index = 0; index < 4; index++)
  {
    int currentButtonState = !digitalRead(buttonMap[index]);
    if (currentButtonState != lastButtonState[index])
    {
      switch (index) {
       
        case 0: // Black Button 1
          Joystick.setButton(0, currentButtonState);
          digitalWrite(0, HIGH); 
          break;
        case 1: // Black Button 2
          Joystick.setButton(1, currentButtonState);
          break;
        case 2: // Black Button 3
          Joystick.setButton(2, currentButtonState);
          break;
        case 3: // Black Button 4
          Joystick.setButton(3, currentButtonState);
          break;

      }
      lastButtonState[index] = currentButtonState;
    }
  }

  delay(10);
}

Incorrect wiring or defective sensors.

Are you sure that you installed the sensors the right way around?

1 Like

dont post links, post the images

I suggest you write a SIMPLE sketch to test a single sensor without using the joystick library. You can adapt this

You forgot to annotate the schematic, no signal definitions or voltages. No clue what Pin ? is. No microprocessor shown. No power supplies shown.

After trying out a bunch of stuff I'm starting to think that there is something wrong with the wiring. I've replaced the sensors and the Pro Micro, but I'm still getting the same behaviour:
sensors switching high/low all by themself, no magnet used

This kind of behaviour only occurs with the board posted above though:

So I went back to my breadboard (as @johnerrington suggested) and it seems to be working just fine:

Breadboard works, prototype-pcb (whatever they're called) does not.
Checked for continuity too, but nothing wrong there either.

If that stripboard is something like our "veroboard" it has copper tracks on the bottom side that would short out all your connections!
image

Wire the hall sensor directly to Vcc & Gnd, leaving the signal pin free. Wave a magnet and see if the onboard LED comes on & off. No onboard LED. Monitor signal lead voltage vs gnd, voltage should swing.
This is an incoming QA test with a known magnet at known distances (must actuate & must release). But you can test with a breadboard to make sure your parts work. Then, if there is an issue, you can be certain it's the SW, or wiring and not your part. Most sensor modules can be easily tested this way. Output devices a a little harder, you test the input to Gnd or Vcc and see if the output changes.

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