RPM Meter With STM32

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects. New tutorials on Tuesdays and Fridays.

Although it is somewhat of a nuisance to buy (because it is not available in many internet stores), I find it necessary to discuss STM32 L432KC. This chip deserves special affection, as it is ULTRA LOW POWER. However, for those who do not own the STM32, it can be replaced in this project by the Arduino Uno. To do this, simply change the pin of the Interrupt input.

Let's then create an RPM meter using the STM32 L432KC and an infrared sensor. This same program can also be used to measure wind speed. The low-power feature of this microcontroller is perfect for IOT.

Step 1: Modules

For our project today, we use the 8-digit MAX7219CWG, as well as the Infrared Module.

Step 2: STM32 NUCLEO-L432KC

Step 3: Demonstration

In our assembly, we have the STM32, the 8-digit display, and the pulse input. The infrared card has a phototransistor and a LED that catches the light by bouncing off a white ribbon. This tape is attached to a wheel and, at each turn, will generate a pulse, which will be captured by the STM32 interrupt.

We have a diode and a capacitor in the assembly that were used to prevent the noise of the tape reading signal from reaching the STM32, which would make it interpret the on and off.

The demonstration shows our project, as well as the Minipa meter (both in operation).

Step 4: Assembly

Step 5: Program

We will do a program in which the infrared module will trigger an interrupt in the STM32 L432KC every "turn," and we will do the calculations to display the RPM on the display.

Step 6: Libraries

Add the following "DigitLedDisplay" library.

Simply access "Sketch >> Include Libraries >> Manage Libraries ..."

Step 7: Source Code

Libraries and Variables

Let's start the source code including the DigitLedDisplay library. We’ll show the display object. I set the interrupt pin, which will be 12. Also, I enter a volatile operator for both the RPM counter and time in order to avoid any collision problems.

/* Include DigitLedDisplay Library */
#include "DigitLedDisplay.h" /* Arduino Pin to Display Pin 7 to DIN, 6 to CS, 5 to CLK */ //DigitLedDisplay ld = DigitLedDisplay(7, 6, 5); //arduino DigitLedDisplay ld = DigitLedDisplay(4, 2, 3); //STM32 L432KC int pin = 12; //pino de interrupção (módulo IR) volatile unsigned int rpm; //contador de rpm volatile unsigned long timeold; //tempo


In the Setup, we configure the display operation, as well as configure the interruption as Rising.

void setup() {
Serial.begin(115200); /* Set the brightness min:1, max:15 */ ld.setBright(10); /* Set the digit count */ ld.setDigitLimit(8); ld.printDigit(0); attachInterrupt(digitalPinToInterrupt(pin), interruptPin, RISING); rpm = 0; timeold = millis(); }


Finally, we determine the interval of 1 in 1 minute to update the display. After cleaning the screen, we print the RPM. We perform the function that the interrupt will call. We calculate RPM and update time.

void loop() {
delay(1000); ld.clear(); ld.printDigit(rpm); } void interruptPin() { rpm = 60*1000/(millis() - timeold); timeold = millis(); }

Step 8: Files

Download the files:





    • Toys Contest

      Toys Contest
    • First Time Author

      First Time Author
    • Make it Glow Contest 2018

      Make it Glow Contest 2018