Hall Effect Sensor doing weird things

I am new to working with Arduino and I am currently working on a joystick as my school project. I´m using a hall effect sensor 49E as a X,Y and Y axis input. When I was about to test I opened Joy.cpl and found out that the input is jomping from 1 corner to another. When I took the sensor out so it was away from magnetic field it was still doing it. Does anyone know what might be causing it.
Thank you very much for any help.

Without more information we can just make guesses. I will not waste my time guessing.

Post a data sheet for the sensor.

Post a schematic of your wiring.

Post your test code. Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

This page tells how to interface the sensor and what to expect from its output. Is this what you are seeing?

Sorry for the mistakes.
Here is the datasheet can be found here https://dratek.cz/docs/produkty/0/910/49e.pdf

My code. I am using Joystick library that emulates arduino an a game controler:

#include <Joystick.h>
Joystick_ Joystick;
int JoystickX;
int JoystickY;
int JoystickZ;
int Throttle;

int currentButtonState0;
int lastButtonState0;
int currentButtonState1;
int lastButtonState1;
int currentButtonState2;
int lastButtonState2;
int currentButtonState3;
int lastButtonState3;
int currentButtonState4;
int lastButtonState4;
int currentButtonState5;
int lastButtonState5;
int currentButtonState6;
int lastButtonState6;

void setup() {
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  pinMode(A4, INPUT_PULLUP);
  pinMode(A5, INPUT_PULLUP);
  pinMode(A6, INPUT_PULLUP);
  pinMode(A7, INPUT_PULLUP);
  pinMode(A8, INPUT_PULLUP); 
  pinMode(A9, INPUT_PULLUP);

// Initialize Joystick Library
  Joystick.setXAxisRange(0, 1024); 
  Joystick.setYAxisRange(0, 1024);
  Joystick.setZAxisRange(0, 1024);
  Joystick.setThrottleRange(0, 1024);

void loop() {

// Read Joystick
  JoystickX = analogRead(A9); // Hall effect sensor connects to this analog pin
  JoystickY = analogRead(A8); // Hall effect sensor connects to this analog pin

// Read Rudder Pedals
  JoystickZ = analogRead(A6); // Hall effect sensor connects to this analog pin

// Read Throttle
  Throttle = analogRead(A4); // Potentiometer signal connects to this analog pin

// Read Switches
int currentButtonState0 = !digitalRead(7); // Button 0
  if (currentButtonState0 != lastButtonState0)
  Joystick.setButton(0, currentButtonState0);
  lastButtonState0 = currentButtonState0;

int currentButtonState1 = !digitalRead(A0); // Button 1
  if (currentButtonState1 != lastButtonState1)
  Joystick.setButton(1, currentButtonState1);
  lastButtonState1 = currentButtonState1;
int currentButtonState2 = !digitalRead(6); // Button 2
  if (currentButtonState2 != lastButtonState2)
  Joystick.setButton(2, currentButtonState2);
  lastButtonState2 = currentButtonState2;

int currentButtonState3 = !digitalRead(A1); // Button 3
  if (currentButtonState3 != lastButtonState3)
  Joystick.setButton(3, currentButtonState3);
  lastButtonState3 = currentButtonState3;
int currentButtonState4 = !digitalRead(A2); // Button 4
  if (currentButtonState4 != lastButtonState4)
  Joystick.setButton(4, currentButtonState4);
  lastButtonState4 = currentButtonState4;

int currentButtonState5 = !digitalRead(A3); // Button 5
  if (currentButtonState5 != lastButtonState5)
  Joystick.setButton(5, currentButtonState5);
  lastButtonState5 = currentButtonState5;
int currentButtonState6 = !digitalRead(A5); // Button 6
  if (currentButtonState6 != lastButtonState6)
  Joystick.setButton(6, currentButtonState6);
  lastButtonState6 = currentButtonState6;
// Output Controls



As my schematics were on the paper here is one that I made quickly

Do not use INPUT_PULLUP on the analog inputs for the Hall effect sensors.

I am adding a video to demonstrate how the input looks

Hi, @martinkopac
Welcome to the forum.

A hand drawn one is always better than one drawn in Paint.
Please post an image of your circuit.
What model controller are you using?

Do you have a DMM?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Thanks your reply somehow helped me solve my problem. I have borrowed a DMM from a friend and tried it out. Found out that the PCB I bought had a little production fault (the holes were not connected on both sides). I bought a new one and it works like charm.
So yeah thanks for a suggestion. :grinning:

The person did not request or pay for plated-through holes. You can easily fix the problem by putting a small wire through the hole and soldering on both sides of the board.

1 Like

The lack of PTH seems not a 'little' production fault, but a major one! :wink:

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