0% found this document useful (0 votes)
219 views10 pages

RPM Measurement (Tachometer)

The program measures the RPM of a DC motor by using an IR sensor and STM32 microcontroller. It calculates RPM from the pulse width captured by a timer interrupt, and displays the result on an I2C LCD screen. It also transmits the RPM data to a ThingSpeak channel via WiFi using an ESP8266 module.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
219 views10 pages

RPM Measurement (Tachometer)

The program measures the RPM of a DC motor by using an IR sensor and STM32 microcontroller. It calculates RPM from the pulse width captured by a timer interrupt, and displays the result on an I2C LCD screen. It also transmits the RPM data to a ThingSpeak channel via WiFi using an ESP8266 module.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

RPM MEASUREMENT (TACHOMETER)

OVERVIEW OF PROJECT:
The program initializes the peripherals, GPIO, UART, I2C, and TIM2 timer. It then captures the input signal
of the timer using TIM2_IRQn interrupt configuration and calculates the frequency and RPM (Revolutions
Per Minute) of the input signal. It displays the RPM value on an I2C LCD screen. Additionally, it uses an
ESPDataLogger library to initialize and connect the microcontroller to a Wi-Fi hotspot.

BLOCK DIAGRAM:

COMPONENTS REQUIRED:
1. STM32-NUCLEO411RE.
2. LM393 IR SENSOR.
3. DC MOTOR 12V.
4. 16X2 LCD DISPLAY.
5. I2C MODULE.
6. CONNECTING WIRES.
7. ESP8266 WIFI MODULE.
8. BREAD BOARD
9. DC MOTOR SPEED CONTROL MODULE
HARDWARE INFORMATION:
 LM393 IR SENSOR:

1. Infrared LED or IR Transmitter:


Infrared Transmitter is a light emitting diode (LED) which emits infrared radiations called as IR LED’s.
Even though an IR LED looks like a normal LED, the radiation emitted by it is invisible to the human eye.
Infrared ray’s wavelength ranging is from 700 nm to 1 mm.
2. Photodiode Receiver or IR Receiver:
Normally IR receivers are photodiode. It is a semiconductor which has a P-N junction. A photodiode
is capable to detect infrared rays. It’s operated in Reverse Bias. The photodiode has very High resistance in
the absence of infrared rays and becomes low when infrared rays fall on it.
3. Variable Resistor (Trim pot)
IR sensor has an on-board variable resistor (potentiometer). This variable resistor is a 10k preset. It
is used to set the range of operation. Rotate the present knob to adjust the detection distance, the
effective operation range 2-10 cm. If the present knob rotated clockwise, the detection range will be
increased. If it rotated counter-clockwise, the detection range will be decreased. For accurate detection of
speed 2-5cm is suggested.
4. LM393 Comparator:
The LM393 is a comparator IC that compares the voltage levels of two inputs and produces a digital
output based on the comparison. It is commonly used in various electronic circuits such as level detectors,
oscillators, and signal amplifiers.
To use the LM393, you need to connect the inputs to the two voltage sources you want to
compare, and connect the output to the next stage of the circuit. The output of the LM393 will be either
high or low depending on the voltage levels of the inputs.
5. Dc Motor Speed Control Module:
When using a PWM DC motor speed regulator, a series of pulses are sent to the motor at a variable
frequency, with the duration of each pulse (i.e., its width) being adjustable. By adjusting the width of the
pulses, the effective voltage applied to the motor is changed, which in turn changes its speed.

NOTE:
 Explanation for white paper pasted on Motor body:
It is universal that black colour absorbs the entire radiation incident on it and white colour
reflects the entire radiation incident on it. The surface of the object can be divided into two types:
reflective surface and non-reflective surface. If the surface of the object is reflective in nature i.e., it
is white or other light colour, most of the radiation incident on it will get reflected back and reaches
the photodiode. Depending on the intensity of the radiation reflected back, current flows in the
photodiode. If the surface of the object is non-reflective in nature i.e., it is black or other dark
colour, it absorbs almost all the radiation incident on it.
CONNECTIONS:
Make connections as per table given below.

STM-PINS IR-SENSOR I2C MODULE


5V VCC VCC
GND GND GND
PA5 OUT -
PB8 - SCL
PB9 - SDA

NOTE: LCD and I2C are connected together via bread board.
IOC CONFIGURATIONS:
 Create a new project, use default configurations.
 Now go to pin out configurations enable Timer-2 in Timers section, select channel-1 as Input
capture direct mode.
 Now go to parameter settings, select prescaler, counter period (ARR), polarity selection, as follows.
 Prescaler = 50000-1
 Counter period = 0xffff-1
 Polarity selection = Raising Edge
 In pin out view enable PA5 pin as Timer-2 channel-1.

 Go to clock configuration, select HSE >> HCLK-50MHz, as Timer-2 max-frequency that connected to
APB-2 is 50MHz.
 By using reference manual of STM32 and correlate the bus with timer used.
 TIM2 is connected to APB1 Bus which Clock frequency Max up to 50MHz.
 Click on the NVIC Settings and Enable the TIM2 global interrupt
 Now enable I2C-1 by clicking on connectivity, select I2C.
 Save the configurations and generate code.
PROGRAM CODE:

 Include below header files in USER CODE Includes section.

 Write the below code in USER CODE BEGIN 0.


 Write the below code in USER CODE BEGIN 2.

 Write the below code in USER CODE BEGIN WHILE.

 lcd_send_data function in I2c-lcd library.


 The input to the function is a single character, which will be split into two 4-bit nibbles.
 The first nibble (data_u) contains the upper 4 bits of the input character, while the second
nibble (data_l) contains the lower 4 bits of the input character.
 A 4-element array (data_t) is created to store the 4 different transmissions that need to be
made to the LCD screen.
 Each of these transmissions is created by bitwise OR appropriate nibble with a control byte
(0x0D for enable=1, rs=0, and 0x09 for enable=0, rs=0).
 Finally, the HAL_I2C_Master_Transmit function is used to send the data_t array to the
specified I2C slave device (SLAVE_ADDRESS_LCD) using the I2C1 interface, with a timeout of
100ms.
 Now include i2c-lcd.h in core >> inc folder.

 Now include i2c-lcd.c in core >> src folder.

 Include below files in core >> inc folder.

 Include below files in core >> src folder.

EXPLANATION:
The code begins with including the necessary header files for the project, which includes the main header
file, standard input/output library, string library, a custom library for interfacing with the ESP8266 module,
and the I2C LCD library.
After this, some macros are defined to specify the clock and prescalar values of the timer
used to measure the RPM. Then, some global variables are declared to store the values of the captured
input capture (IC) values, the calculated speed and RPM values, and a buffer to store the RPM value for
sending to the ESP8266 module.
Next, a callback function for the input capture interrupt is defined. This function is called
when the timer measures a pulse from the IR sensor. The function reads the values of the input capture
register and calculates the frequency and RPM of the motor. Finally, the calculated RPM value is stored in
the buffer.
In the main function, the peripherals are initialized, including the GPIO, timer, UART, and I2C
peripherals. Then, the timer is started, and the input capture interrupt is enabled. After a delay of 1
second, the LCD is initialized, and the ESP8266 module is initialized with the SSID and password of the Wi-Fi
network to which it will connect.
In an infinite loop, the RPM value is displayed on the LCD by converting the value to ASCII
characters and sending them to the LCD. And also sends to ESP8266 module.

FORMULA TO CALCULATE RPM:


To calculate the speed of motor, we need following data.
1. IC_Val1
2. IC_Val2
3. Difference
4. refClock
5. Frequency
6. RPM
7. PPR (pulse per revolution)

IC_Val1 is captured at first raising edge of pulse generated by sensor, and IC_Val2 is captured at second
raising edge of pulse.
By using “Difference”, frequency is calculated by TIMCLOCK(HSE Timer clock) and PRESCALAR.
 refClock(TIM2 clock frequency) = TIMCLOCK / PRESCALAR
 frequency = refClock/Difference
RPM calculated using frequency, 60 = time in seconds per 1minute, PPR =1(uses one interrupt per 1
revolution)
 RPM = (60 * frequency) / PPR

DATA LOGGING USING ESP8266 IN THINKSPEAK:


CREATING THINKSPEAK CHANNEL:
We need to setup the Thing speak for receiving data.
 Create an account on Thingspeak.com and Go to channels, and create NEW CHANNEL.
 Give name to these field charts, set remain as default and Click on save. Final setup looks as shown
below.
 As API key is generated it will be added in code at ESP_Send_Multi function.
OUTPUT:
Validation with existing Tachometer
S.No. RPM Measurement Tachometer Measurement
1. 1024 1056
2. 2256 2275
3. 3123 3130
4. 4509 4515
5. 5090 5111
CIRCUIT CONNECTIONS:

SPEED DISPLAYED ON LCD

OUTPUT AT IR SENSOR IN LOGIC ANALYZER:


DATA LOGGING OUTPUT IN THIKSPEAK SERVER

You might also like