[SOLVED] Are these hall effect sensors too fast for arduino?

I have recently found a motor in a box of bits I was given.
It looks similar to the robot motors we use but only has a geared output on one side.
It also has a piece of circuit board on the end of the motor with a magnet wheel and two hall effect sensors.


If I use the button sketch from the examples and add a serial.println line into it so I can monitor one or the other sensors it just goes crazy when I turn the motor by hand, I assume this is because of bounce.
If I use the debounce program and lower the debounceDelay to 1 millisecond it works fine by turning the motor by hand but only sees a few of the signals when I apply 5v to the motor. The input is pin 2 which I understand is a PWM pin.
Is there another way of reading the signal or is the motor just too fast to monitor on an arduino?

  • Mechanical switches bounce, not had hall effect sensors do this.

  • Would help if we could see an oscilloscope capture.

2 Likes

I have an oscilloscope but it may take a while to set it up on this desk. I will return when I do.

If they're digital hall sensors, they likely have built in hysteresis (think Schmitt trigger) and would be unlikely to suffer from bounce.

If they're analog hall sensors that's a whole other ball of wax. But my money would be on them being digital.

Hall sensors on motors will likely need external pull up and be read with interrupts.
Although I see some parts (resistors) on that hall board.
Leo..

I get a perfect square wave with the motor running supplied by 5v


The scope is set to .5 milli seconds.

1 Like

Which take about 1ms to print a single character when set to 9600 baud.
Leo..

3 Likes
  • Yes, speed up your baud rate.

  • Expand the display to look at the rising and falling edges.

Speeding up the display on the debounce sketch to 115200 and 230400 doesn't seem to make much difference with a debounceDelay of 1, I can see the number rising but it looks to speed up quite a bit when I turn the power off and the motor is slowing down.
On the scope If I slow the trace down so there is only 1 cycle on the screen it is wavering a tiny bit at the edges but it is still a pretty good square wave.

With 0.5ms/1ms waves, adding a 1ms debounce delay is too much.

Per

Along with your oscilloscope trace, you likely do not need a debounce.

Could you show an oscilloscope trace from this case:

Adding some Serial.println() to the Button code adds some debouncing effect while the printing happens. https://github.com/arduino/arduino-examples/blob/fdbfc5b070623bbd560eecad7a387689f83053ce/examples/02.Digital/Button/Button.ino#L25-L51

A simple tachometer sketch for classic 5 volt UNO, Nano, PRO Mini.


unsigned long timerStart;
const byte encoderPin = 2; // interrupt 0 pin
volatile unsigned long count; // pulse count
unsigned int timerEnd = 1000, pps;

void setup()
{
  Serial.begin(9600);
  attachInterrupt(0, readEncoder, FALLING);
  pinMode(encoderPin,INPUT_PULLUP);
}

void loop() {
  if(millis() - timerStart >= timerEnd)
  {
    noInterrupts();  
    pps = count;
    count = 0;
    interrupts();
    Serial.print(pps);
    Serial.println("\tpulses per second");
    timerStart += timerEnd;
  }
}
 
void readEncoder()
{
  ++count;

}

I see two hall sensors on that motor (speed, direction, four wires).
Leo..

For quadrature pulses? Needed for direction / positioning, not for tach (speed).

direction, positioning and speed.
Leo..

Of course. :slightly_smiling_face:

The solution to reading these signals lies in using interrupts, basically doing the counting in the background and independent from the rest of your code.

The signal is far from being too fast for an Arduino to read (it's only about 1 kHz, it can happily handle three orders of magnitude faster), but it is too fast for it to read while you're doing many other things, such as trying to do Serial communication for every one pulse. Actually a 1 kHz signal can be handled without interrupts but it's getting rather tricky to ensure you don't miss pulses.

1 Like

Thanks Guys that is brilliant and thank you jCA34F the sketch works well. I can alter the voltage with my bench power supply to the motor and the speed follows. Around 3000 pps at 5v.
Yes there are two hall effect devices and on the cct board it says 5v, gnd, A & B so I suppose it could act as a rotary encoder.

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