Vibration causing false hall effect readings

I wrote this sketch to move 2 actuators on a mobile fertilizer spreader. When stationary, it works as intended. The issue I am having is that when the machine moves through the field, the vibrations from the tires causes the arduino to read “false” hall effect movement, even though the actuators have not moved.

As my sketch is designed to keep the actuators at a target location, these false/phantom readings cause the actuators to drift.

I have tried dampening the mounting box with rubber which helped but did not cure it. My next thought is to detach the interrupt to prevent the sketch from reading the phantom pulses. Unless someone has come across this before and has another idea.

McClaryActuatorswithHallSensorsV4.ino (31.4 KB)

Load the demo sketch from the encoder library. Does it see the ‘false’ pulses from the actuator?

If so, then you either have a wiring problem, an interference problem or an actuator problem.

If the demo sketch doesn’t see any false pulses then you have a code problem. I doubt that many people will have the time to debug your 1000+ lines of code, however looking at the very last function you appear to be testing for equality using a single “=” instead of “==”.

mikb55 - from my testing, as you suggested it is the actuators that are susceptible to vibrations. I confirmed this with the manufacturer, much to my disappointment.

I did correct the errors you found as well, thanks for that.

Seeing as this is the issue and that there is little option for me to change equipment out, this is why I was looking at detaching the interrupt, or, possibly using hystersis to hide some of the false readings.

I did see reference to this in another post, where a hall sensor could be sitting "on the edge" and cause what I am seeing.

Which Arduino board is involved - i.e. are pins 18,29,20,21 interrupt-capable or not? That encoder library will auto-select whether to use interrupts on the pins, and you probably want interrupts on both pins for accurate performance when there's vibration.

With a quadrature encoder you have to read its state at least as often as it changes when cycling through the 4 states - without interrupts on the pins this means you'd have to poll at a high rate.

A quick observation - you are using a glacially slow 9600 baud rate for serial, if you can change this to 115200 do so, this will make your whole sketch far more responsive. The large number of serial prints each time through loop() is really needed? Can you not just report every second or something like that?

MarkT - I am using an Arduino Mega 2560, I am using the interrupt pins.

I can change the baud rate - and no the serial prints are not necessary anymore I was using them for diagnostics.