Using an Arduino to read RPM from the Hobbywing RPM sensor

I needed a quick way to get RPM data from my Brushless RC motor as my ESC did not support the feature. After a visit to Ebay and $4 later, I had a Hobbywing RPM sensor for brushless motors.

There wasn’t much documentation that came with it except connection instructions which were great for hooking it up, but not for how to use it with an Arduino. I checked online and found a few sketches, but not one of them worked correctly for some reason. I also hit a few snags writing my own function since I was not familiar with interrupts, but with the help of some good folks at the Arduino forums I was able to get it working without too much hassle.

The key thing to understand here is that to sync the interruptCount++ variable into the checkRPM() function, it must be guaranteed not to be interrupted or the data can get garbled. In the checkRPM() function you can see how noInterrupts() was called to disable interrupts prior to working with the interruptCount variable, and after the variable was accessed, the interrupts() function was called to re-enable interrupts. The same is to be said of setting the critical_rpm variable to the interruptCount value. Without these critical sections, the code returned strange values depending on usage.

How Accurate is the Hobbywing RPM sensor?

I actually do not know, I haven’t tested the Hobbywing sensor RPM against any other verified method. If however I follow the rule of using RPM = Kv rating of the motor multiplied by # of Volts, I can ballpark the RPM by trial and error using my power meter.

For example, in the sketch above, I have a variable ‘numpoles’ which I initially set to 22 (since my motor has 22 poles). However, when I compared the RPM output to the RPM the motor was rated for, it did not match. I just lowered the number of poles until the KV * Volts = RPM calculation, and RPM sensor values matched.

Does having an accurate RPM measurement really matter?

In this autonomous boat, I don’t feel that having a perfectly accurate RPM reading is necessary. My main goal is to check to see if the motor has stopped. If it has, then the motor monitoring function will restart the motor automatically. In the functions i’m writing, I do not take specific RPMs into account and currently use the sensor as an on off switch (If motor on then x). I may include an RPM measurement in the tracking payload, but its low on the list of priorities at the moment.