RPM Sensor Wiki - Knowledge Share

Hi all,

I want to write the Wiki for using RPM sensors.

I don’t know everything about implementing the various sensors on the various flight controllers out there. So I am creating this thread to encourage others to share their own knowledge and tips. Also, if I have made a mistake in the information I have written below, please do point it out. I will then collate all of the information into a Wiki page.

What I know so far:
In principle, any rpm sensor that outputs a PWM signal can be used by ArduPilot. Common RPM sensor types include:

  • Hall effect sensors such as this.
  • Back EMF sensors such as this
  • Optical sensors. Need an example, and have not got any experience with getting these working.

Note that this guide will be covering external RPM sensors using the AP_RPM library. It will not be covering the ESC RPM that can be obtained using a UART for ESC Telemetry. The wiki for that already exists here.

There are already few forum threads which discuss RPM sensors. The two with the most info are these:

Getting the hardware setup
For using hall effect sensors a magnet and pick up sensor are required. Often, a hole or recess needs to be drilled and the magnet glued in. For traditional helicopters the best place to glue the magnet is in the autorotation tail rotor drive gear. For example:

The hall effect sensor will then be installed on the airframe, being careful to ensure that the sensor and magnet are sufficiently close for the magnetic field to affect the sensor. For example:

For IC engines the magnet should be mounted onto the output shaft and the sensor onto the case. For example:
All 2-stroke and 4-stroke ICE will need the magnet and sensor installed for ignition timing. The same sensor can be used to read the RPM in ArduPilot.

The orientation of the magnet does matter. The sensor will only change the output voltage in the presence of one of the poles of the magnet (N or S). The polarity depends on the sensor. To easily identify which is the correct polarity I have adapted an Arduino sketch from diyhacking.com. You can find the sketch here.

To use the sketch, connect the signal pin of the sensor to pin 2 on the Arduino (an interrupt pin). Connect the Gnd to Gnd and Vcc to 5V. Set the detect_on variable to true. Upload the code to your Arduino. Open the serial monitor. All being well, when you bring the magnet close to the sensor, with the correct polarity, the serial monitor will print ‘detect’.

I have found that the hall effect sensors that I have need a pull up resistor to be added. Solder in a resistor (resistance value doesn’t matter too much. I used 360 ohm because I had it lying around.) between the 5v line and the signal line, like below:

It is also worth noting that not all sensors are made to adopt the ‘standard’ wire colouring that you might expect. This sensor for example requires that the GND and VCC are swapped from the norm (i.e. red is GND and VCC is black). So the Arduino sketch above is a good way to debug this and easily swap the sensor leads around until you find what works.

Final note on the Arduino sketch. It will also plot the measured rpm to the serial plotter. To do this, set the detect_on variable to false. Set the number of magnets using the n_magnets variable (for example, some choose to have 2 magnets 180 degrees opposed). and open the serial plotter tool. This offers a relatively easy environment to get the sensor working properly, before introducing the additional complexity of ArduPilot into the mix.

If using a back EMF sensor for a brushless electric motor. Something like this. Hardware setup is straight forward. Simply solder the two input wires to any two of the three AC motor wires. The order does not matter, any two will do. The three wire output then gets plugged into the flight controllers AUX/PWM rail.

Setting up ArduPilot

You will need to plug the rpm sensor into either an AUX port on a Pixhawk, or a PWM port on a different flight controller.

The next step is to ensure that the port you have plugged the rpm sensor into is configured as a GPIO pin to receive a signal input. You can do this by setting the BRD_PWM_COUNT parameter. Set this number to the highest PWM output number you are using. All remaining FMU outputs are then assigned to be GPIO, and are therefore available to read an input. For example, on a pixhawk, setting BRD_PWM_COUNT to 8 will leave all AUX pins as GPIO pins.

The next step is to let Ardupilot know which pin the RPM sensor is connected to. This is done by setting the RPM_PIN parameter. Note that this is not the pin number as printed on the casing/silk screen but the pin number as it is assigned in the hwdef.dat file. For example, if you are using a pixhawk then Aux pin 1 is set as pin 50. If you aren’t using a Pixhawk, to find out what the pin number is for your board then look through the list of hwdef.dat files here to find the firmware for your board. Then find the PWM out list, and the number you want will be in the brackets of the GPIO() function. For example, for an F405 wing PWM 9 corresponds to 58:

If you have multiple magnets then you will need to set the RPM_SCALING parameter. E.g. for 2 magnets set RPM_SCALING = 0.5.

If using the AUX ports on pixhawk then set RPM_TYPE to 2. If using a PWM port on a pixhawk or a different board set RPM_TYPE to 1.
^^^ I am not 100% sure that this is correct. Can somebody please verify when it is correct to set RPM_TYPE to 1. The difference between the two wasn’t obvious to me looking at the code. ^^^

In principle the RPM sensor is now set up and should work. You can verify by plotting rpm1 and rpm2 in the live tuning plotter on mission planner.

Initially, don’t change the RPM_MIN, RPM_MAX, RPM_MIN_QUAL parameters as these could make it appear that the sensor isn’t working at all. For example, if the scaling isn’t correct and the RPM value is greater than RPM_MAX, then the value in mission planner will just indicate ‘0’. Once you are happy that you have got a clean and reliable RPM signal, then think about changing the aforementioned parameters. Keep in mind, if you have two rpm sensors then the aforementioned parameters are valid for both rpm sensors and should be set accordingly to encompass the RPM range seen by both sensors.


As I say, any advice, tips, or corrections are greatly appreciated.

Hi Matt,

Thanks for the write-up. I’m trying to do something similar on a Pixhawk 2.1 with a Castle Creations HV160 ESC that conveniently outputs a pulse per commutation.

I’ve read elsewhere that all of the AUX outputs have to be either PWM or GPIO https://hackaday.io/project/20311-measuring-engine-rpm-with-the-pixhawk . That’s a problem for me as I have 12 PWM outputs! However it looks like that was with the Pixhawk 1. Do you know if its possible to mix and match the AUX ports on Pixhawk 2?


Hi Sam,

Good question. I’m not 100% sure but I believe that you can now mix and match AUX ports on pixhawk. If you set BRD_PWM_COUNT to 12 say, you should have all of your pwm outs, AUX 1 to 4 will be pwm out, and AUX 5 and 6 should be set to GPIO for you to use one as an RPM pin.

Let me know how you get on as I have the same ESC and would like do the same thing.

On The Cube family, BRD_PWM_COUNT only changes the number of AUX ports that are PWM. The main outs are PWM output only. So the default BRD_PWM_COUNT value of 4 has AUX 1-4 as PWM and AUX 5-6 as GPIO.

Thank you for the clarification on this.

Am I correct in saying that for non-cube pixhawks, the pwm count includes the PWM outputs? So my example above would be correct for non-cube pixhawk boards?

PR for the RPM sensor wiki is here:

Hello guys!

I am trying to connect an IC engine RPM sensor in my pixhawk. I have a Pixhawk 4 and a PM07. Does anyone knows where should I connect the sensor in this power module? I have followed the explanation above, but my RPM1 output in mission planner only gives me a constant -1.0 value.
Thanks in advance,

Hi Rodrigo,

Have you followed the wiki?

Have you tried connecting it to a PWM channel on the flight controller first to make sure it is working there before trying to get it to work via the power module?

Can you upload a .param file for me to have a look at please.

Hello Matt!

How are you?
Yes, I have changed the BRD_PWM_COUNT and RPM_PIN parameters.
I am sending the .param file now.
To be honest, I don’t know how I can plug it directly in the Pixhawk 4. Because my sensor uses a servo connector and this pixhawk does not have this kind of connector. Do you have any idea of how to plug it without the Power module?


copter.param (14.4 KB)

Just to double check, is this the board you are using?

Looking at your params you want AUX5 which by my reckoning are these pins:

That is assuming that you have connected FMU-PWN-out on your board to FMU-PWM-in on your power module.

Can you confirm that you have connected it in this way?

Are you using an IC with an ignition system? If so are you taking the reading off of the hall effect sensor that is used for the ignition system? If so, how have you done this, with a y-splitter?

Are you getting 5V to the hall effect sensor?

Hello Matt!

Yes! That is exactly my power module and I have connected the sensor in this port.
My ICE has ignition system and I am using its sensor. And I am using a Y-splitter. Is this a problem?

I have not checked about the 5V in the hall effect sensor. I will take a look into it.

Thank you very much!

No, no problem at all. You can do this, I am just trying to understand your setup.

After you have checked that you are getting 5v the next thing to do is to check that your ‘signal’ line is:
a) Actually where your signal should be. Not all hall effect sensors are wired in the way that the PWM inputs are expected (i.e. some times the voltage line and signal are swapped).
b) Changing voltage as the magnet comes near the sensor.

To check the above it is useful to use either an oscilloscope or an Arduino with this debugging script

Hi Matt

Today I resumed to work with the RPM sensor again. I just followed your instructions and everything worked as expected! Thank you very much!


1 Like

Hi Rodrigo. I’m glad you got it working :+1:


@tridge @bnsgeyer @IAMMATT @ChrisOlson

I am having a issue with an RPM sensor, ArduCopter v4.0 + and warning message “RPM: failed to attach to Pin255".

The RPM sensor is Align Beast X (One of the ones Chris recommends) with Vcc and GND swapped and pull up 360ohm resistor between Vcc and signal. (As per this RPM Sensor Wiki thread. RPM Sensor Wiki - Knowledge Share). I have had it on the oscilloscope and works fine and it outputs 0 to 5v steps similar to this picture with a passing magnet.

Autopilot is : Cube Black V4.0.6
Relay_Pin = -1
RPM_Max = 10000
RPM_Min = 10
PRM_Min_Qual = 0.5
RPM_Pin = 55 (Sensor plugged into Aux 6)
RPM_Scaling= 0.5
RPM_Type = 2

RPM displays “-1” when the magnets are stationary but was expecting “0” to be displayed.

I mention the problem in Bill’s TradHeli Autotune thread but it’s not the right place to ask and thought it best to ask the question in here.

As you can see at the bottom of the screen grab below. I can get a RPM reading of 1338 with the cordless drill spinning two magnets. The warning message “RPM: failed to attach to Pin255” still appears though. I did try a few different versions of firmware on the same airframe to try and narrow down what might be causing it.

ArduCopter V3.6.8-L1Nav, RPM worked fine and did not display the warning message. :+1:

Helipilot v21-beta-cubeBlack, RPM worked fine but got the warning msg “RPM: failed to attach to Pin255”

ArduCopter V4.0.6-ATNH-rc1, RPM worked fine but also got the warning message “RPM: failed to attach to Pin255” (see below and log file.)


It looks like something in ArduCopter V4.0 is causing it. After Googling it, It would seem Matt @IAMMATT had a similar problem with SITL.

Do you have any idea what might be causing this warning message?

Thanks and regards,

1 Like

Update to my post above:

Thanks to Bill, the warning message “RPM: failed to attach to Pin255" is fixed now. After looking at my log file, he found that I had RPM2_TYPE set to 2 and RPM2_PIN set to -1 which was causing the warning. I wasn’t using RPM2 so setting it back to RPM2_TYPE to 0 fixed the issue.

Hello to everyone¡¡ I am trying to active 4 RPM sensors, in order to read angular velocity of each motor of a quadcopter. In the Full List Parameters I can only configure two of them. I modified the firmware code adding the lines for RPM3_PIN and RPM4_PIN and changed the number of maximum RPM measurements to 4. I loaded the code as : Load custom firmware using Mission Planner. But the New Parameters added do not appear. I am using EMF sensors, Hobbywing RPM sensors. Actually, I can see the the signal of two of these sensors. Does anyone know what could be wrong? A

Arpm4 ny tip will be really appreciated. Thank you.

Hi Giovanna.
Have you instantiated two more instances of Rpm sensor as well as adding the new params?

Also, it looks as though you are overwritting the variables of the second instance or Rpm sensor. E. G. _scaling[1] in 3_SCALING should be _scaling[2] (you will need to increase the size of the arrays that store these too)

Hi Matt¡ Thank you for answering. Yes. I added two more instances and new params.


I changed the code as you suggested. But where can I change the size of the arrays? As I understand the size of the arrays depends on the variable RPM_MAX_ INSTANCES in the AP_RPM.h header file.
I still can not see these new parameters in Mission Planner. Please help ¡¡¡