Arduino motor speed meter. Tachometer based on Arduino. Detailed list of items


A tachometer is a device that is used to measure the number of revolutions of an object in a given time interval. Typically the value is expressed in revolutions per minute or rpm. Previously, tachometers were purely mechanical devices in which rotation was transmitted to the tachometer through a mechanical connection (cable or shaft), the number of revolutions per minute was determined using a gear train and displayed on a dial scale. Since the advent of modern electronics, tachometers have changed a lot. This article describes a non-contact digital tachometer based on Arduino. The speed of the motor can also be controlled using a similar circuit. The number of revolutions per minute and other information is displayed on a 16×2 LCD display. The electrical circuit of Arduino based digital tachometer is shown below.

Electrical diagram

RPM sensor
An infrared phototransistor and an infrared LED form the sensor. An infrared phototransistor is a type of phototransistor that only responds to infrared waves. Using an infrared phototransistor avoids the influence of other light interference from the environment. The phototransistor and the infrared LED are arranged in parallel. Resistor R2 limits the current through the infrared diode. The reflective guide tape is glued to the rotating object (shaft, disk or fan) in line with the sensor. I used a cooling fan with a supply voltage of 9V/100mA. The gap between the sensor and the reflective guide strip should not exceed 1 cm. When the reflective guide strip passes in front of the sensor, the infrared waves are reflected back to the phototransistor. The phototransistor conducts more at a given moment and as a result, the voltage across R3 (68K resistor) rises rapidly. The result will be a signal whose shape is shown below at the emitter of the phototransistor. The number of revolutions per minute can be determined by calculating the number of upward pulses in a given time interval.

Calculation of revolutions per minute
Arduino is used to calculate the RPM value and display this value on the LCD. The emitter of the phototransistor is connected to the Interrupt 0 pin (digital pin 2) of the Arduino. The Arduino interrupt is configured to be triggered by a rising edge. As a result, an interrupt is processed for each upward pulse in the emitter waveform. The number of interrupts received at a given time is calculated by incrementing the variable, using the interrupt service program. The time elapsed during a computation cycle is determined using the millis() function. The millis() function returns the number of milliseconds that have passed since the Arduino board was turned on. Calling the millis() function before and after the computation cycle and calculating their difference gives the time elapsed during the computation cycle. The value (number of interrupts/times per millisecond) * 60000 will determine the number of revolutions per minute (RPM).

Motor speed control
A device for controlling the speed of the motor using a potentiometer is also included in the circuit. Transistor Q1 is used to control the motor. Its base is connected to PWM pin 9 of the Arduino via current-limiting resistor R1. The R4 speed control potentiometer motor is connected to the analog pin A0 of the Arduino. The voltage at this pin is converted to a value between 0 and 1023 using the anlogRead function. This value is then divided by four to fall into the range from 0 to 255. This value is then written to PWM pin 9 using the anlogWrite function. The result is a square wave at pin 9 whose duty cycle is proportional to the value written using the analogWrite function. For example, if the value is 255, the duty cycle will be 100%, and if the value is 127, the duty cycle will be about 50%. D1 is a freewheeling diode and C1 is a noise suppression capacitor (decoupler). The RPM and duty cycle are displayed on the LCD screen using the standard LiquidCrystal library. Read this article: Interface LCD display for Arduino. The complete code for the Arduino based digital tachometer is shown below.

Program code
#include LiquidCrystal lcd(12,11,6,5,4,3); int pwm=9; int pot=A0; float value=0; int percent; float rev=0; int rpm; int oldtime=0; int time; void isr() //interrupt service routine ( rev++; ) void setup() ( lcd.begin(16,2); //initialize LCD attachInterrupt(0,isr,RISING); //attaching the interrupt ) void loop() ( delay(1000); detachInterrupt(0); //detaches the interrupt time=millis()-oldtime; //finds the time rpm=(rev/time)*60000; //calculates rpm oldtime=millis(); / /saves the current time rev=0; value=analogRead(pot); //reads the speed control POT value=value/4; analogWrite(pwm,value); //sets the desired speed percent=(value/255)* 100; //finds the duty cycle % lcd.clear(); lcd.setCursor(0,0); lcd.print("___TACHOMETER___"); lcd.setCursor(0,1); lcd.print(rpm); lcd .print(" RPM"); lcd.print(" "); lcd.print(percent); lcd.print("%"); attachInterrupt(0,isr,RISING); )
Notes
The Arduino board can be supplied with a 9V power supply via an external power socket.
The 5V voltage required for some circuit components can be supplied from a 5V source on the Arduino board.
The fan used uses a voltage of 9V/100mA. The 2N2222 transistor can only withstand current up to 800mA. Keep this in mind when choosing a load.
The LCD used is JHD162A.
Potentiometer R5 can be used to adjust the contrast of the LCD display. When it is connected, nothing will be displayed on the display. Adjust R5 until an image appears on the display. The optimal voltage on the potentiometer R5 slider is in the range from 0.4 to 1V.
The infrared phototransistor and infrared diode were removed from the LTH-1550 photo interrupt module.
The side surface of the phototransistor must be covered with electrical tape.
The sensor position is shown in the figure below.

A tachometer assembled using a line sensor is easy to connect. You do not need to make design changes to the part whose rotation speed you want to measure: drill holes, make slots, install additional elements, etc. It is enough to apply a contrasting line on it (black on a light surface or white on a dark one) and bring the line sensor to the surface, you will immediately get an accurate result, the number of revolutions per minute. The sketch does not need to be adjusted, no matter what color the line is.

We will need:

To implement the project we need to install the library:

  • Library iarduino_4LED (for working with a four-digit LED indicator).

You can find out how to install libraries on the Wiki page - Installing libraries in the Arduino IDE.

Video:

Connection diagram:

The LED indicator is connected to any two Arduino pins (both digital and analog), the numbers are indicated in the sketch. The line sensor is connected to any analog input, the number is indicated in the sketch.

In this tutorial, the LED indicator is connected to digital pins 2 and 3, and the line sensor is connected to the analog input A0.

Work algorithm:

  • Information is displayed on the LED indicator only when the line sensor transitions from a light to a dark field.
  • The first line of the loop function checks whether the line sensor is in a dark field, if so, then...
  • We display the number of revolutions per minute on the LED indicator (if millis overflow is not detected) and save the transition time
  • We execute the while loop until the line sensor leaves the dark field. Due to this, the previous operation is performed only 1 time, for the entire time the sensor is in the dark field.
  • If the sensor is in a dark or light field for longer than 6 seconds, then we display the message “STOP” (these lines can be removed if the number of revolutions of your device is below 10 per minute).

Program code:

#include // connect the library to work with a four-digit LED indicator iarduino_4LED dispLED(2,3); // declare an object for working with the functions of the iarduino_4LED library, indicating the indicator pins (CLK, DIO) const uint8_t pinLine = A0; // declare a constant indicating the number of the analog input to which the line sensor is connected uint32_t strLine = 0; // time of transition of the sensor from the light to the dark field void setup())( dispLED.begin(); // initiate the LED indicator ) void loop())( if(analogRead(pinLine)>400)( // if the line sensor readings are greater than 400 (dark field) if(strLine 350)( // wait until the line sensor leaves the dark field if((millis()-strLine)>6000)(dispLED.print("STOP");) // if the sensor is in the dark field for more than 6 seconds, then display the inscription "STOP" on the indicator ) ) if((millis()-strLine)>6000)(dispLED.print("STOP");) // if the sensor is in the light field for more than 6 seconds, then display the inscription " STOP" )

A tachometer is a device that is used to measure the speed of rotation of a mechanical object, such as a wheel. Tachometers are widely used in cars. Among radio amateurs, it has found application in robotics, making it possible to measure the speed of movement of a wheeled robot. Tachometers in general have many uses, including measuring the speed of DC motors to ensure they are operating within specifications.



The tachometer is a fairly simple device in its essence, so you can easily make it yourself using Arduino.


To make a tachometer with your own hands, we will need to convert the rotation speed into a readable form. The only form that Arduino can read is electrical voltage. It is well known that if voltage is applied to a motor, then this motor will begin to rotate, and with it the wheel will rotate (if it is attached to the motor shaft), the speed of which is determined by the amount of voltage supplied. However, the opposite is also true: if we rotate the motor ourselves, we can get voltage at both ends of the terminals of that motor. This voltage can be applied to the Arduino and the Arduino will be able to calculate the rotation speed depending on how much voltage was applied to a given motor.


Below is a diagram of connecting the elements of a homemade tachometer based on Arduino. The motor here is connected to a resistor and an LED. The resistor is used to prevent excess current which would normally damage the Arduino. The LED is used to indicate that the motor is running and also to prevent current flow back. In order to display the speed in this case, a single-digit seven-segment indicator and a register chip IC7447 are used to control this indicator.



Once the motor starts spinning, positive voltage will be sent to the analog input of the Arduino. The Arduino will convert this voltage into digital code. Since we are using a seven segment display, we can have 10 values, that is, from the value 0 to 9. We can program the Arduino to divide the analog value it receives into 9 divisions, which will give the desired output from 0 to 9. Below is the code for operating a homemade tachometer on Arduino.


intval=0; intbinVal; void setup() ( Serial.begin(9600); // setting up the serial port pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(A2,INPUT ); ) void loop() ( val = analogRead(A2); // read the analog input (voltage from the motor) Serial.println(val); // debug value binVal=val/1024*9; switch(binVal)( case 0: digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); break; case 1: digitalWrite(3,HIGH); digitalWrite(4,LOW); digitalWrite (5,LOW); digitalWrite(6,LOW); break; case 2: digitalWrite(3,LOW); digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); break; case 3 : digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); break; case 4: digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite( 5,HIGH); digitalWrite(6,LOW); break; case 5: digitalWrite(3,HIGH); digitalWrite(4,LOW); digitalWrite(5,HIGH); digitalWrite(6,LOW); break; case 6: digitalWrite(3,LOW);digitalWrite(4,HIGH);digitalWrite(5,HIGH); digitalWrite(6,LOW); break; case 7: digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,LOW); break; case 8: digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,HIGH); break; case 9: digitalWrite(3,HIGH); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,HIGH); break; default: break; ) )

A tachometer is a useful tool for counting the RPM (revolutions per minute) of a wheel or anything that is spinning. The easiest way to make a tachometer is to use an IR transmitter and receiver. When the connection between them is interrupted, you know that something is spinning and you can use the code to calculate the RPM based on the frequency of the communication interruption.

In this article, we will look at how to use an IR transmitter and receiver to make a tachometer using Arduino. The result is displayed on a 16x2 LCD display.

The goal of this project is to create a system with one input and one output. At the input of the device there is a signal that changes from high (+5V) to low (+0V) level when communication is disrupted. According to this signal, Arduino will increment the internal counter value. Then additional processing and calculation are carried out, and when the trigger is interrupted, the calculated RPM will be displayed on the LCD display.

For communication we will use an IR beam from an IR LED connected through a low resistance resistor so that it glows brightly. We will use a phototransistor as a receiver, which “closes” in the absence of light from the IR LED. A computer fan will be placed between the IR transmitter and receiver and turned on. An IR receiver connected via a transistor circuit will generate interrupts. The Arduino LCD interface will be used to output the result, so we can output the final RPM value on the LCD.

Elements:

Bread board

Trimmer resistor 5 kOhm

Jumpers

SIP connectors

2x 2N2222 NPN transistor

Infrared LED

Phototransistor

10 ohm resistor

Resistor 100 kOhm

Resistor 15 kOhm or 16 kOhm

Computer fan

Detailed list of items

All elements used in the project are listed above, but I will describe the functions of the main elements in more detail.

Arduino UNO

This is the Arduino board that we will use to process the pulses from the IR beam interrupt that indicate the presence of a computer fan blade between the receiver and the sensor. The Arduino will use these pulses along with a timer to calculate the RPM of the fan.

LCD 16×2

Once the Arduino has calculated the RPM, this value will be displayed on the display in a user-friendly manner.

Trimmer resistor 5 kOhm

This trimmer will be used to adjust the contrast of the 16x2 LCD. It provides an analog voltage ranging from 0 to +5V, allowing you to adjust the brightness of the LCD display.

Infrared LED and Phototransistor

The phototransistor turns on when powerful IR light hits it. So when the IR LED is lit, it keeps the phototransistor open, but if the IR LED is covered by a fan blade, for example, then the phototransistor is closed.

2N3904 and 2N3906

These transistors are used to convert the signal level in order to provide output pulses from the phototransistor to the Arduino, in which there are no voltages other than +0 and +5V.

Schematic diagram

In the circuit, the communication interface with the LCD display is simplified and has only 2 control lines and 4 data lines.

Features of the scheme

16×2 LCD interface

2 control pins and 4 for data transfer are connected from Arduino to the LCD display. This is what tells the LCD what to do and when to do it.

IR beam break circuit

The IR beam break signal goes to the 2nd digital pin of the Arduino. This interrupts the Arduino, allowing it to count the pulse and allowing the tachometer to receive the data.

Arduino LCD library

For this project we will use the Arduino LCD library. Basically we'll just update the RPM value on the second line to the new one.

To prepare, take a look at the code below, which uses this library to display "Hello, World!" on the LCD. In the tachometer we will use similar code, especially: "lcd.print(millis()/1000);".

Understand the functions of this LCD library in as much detail as possible before moving forward. It's not too complicated and is well documented on the Arduino website.

Calculating RPM using Arduino

Since we are going to calculate the RPM of a computer fan, we must understand that we are using IR beam interruption for the calculation. This is very convenient, but we must take into account that the computer fan has 7 blades. This means 7 interruptions equal 1 revolution.

If we are tracking interrupts, we need to know that every 7th interrupt means that 1 full rotation has just occurred. If we keep track of the time it takes to complete a revolution, we can easily calculate the RPM.

1st revolution time = P * (µS/revolution)

RPM = rpm = 60,000,000 * (µS/min) * (1/P) = (60,000,000 / P) * (rpm)

To calculate RPM we will use the formula given above. The formula is precise, and the accuracy depends on how well the Arduino can keep track of the time between interrupts and count the number of full revolutions.

Circuit assembly

In the photo below you can see all the necessary parts and jumpers as in the diagram.

First, connect +5V and the data/control lines of the LCD display. Then LCD display, contrast potentiometer and power LED.

The circuit break of the IR beam is assembled. Try to keep some distance between the IR LED and the phototransistor. This photo shows the distance between the IR LED and the phototransistor where I will place the computer fan.

Enough hardware talk! Let's start doing the firmware/program to see how the device works!

Software part

There are two main parts of the code, which are shown and detailed below:

Basic LCD refresh cycle

Interrupt time update

The main cycle counts the revolutions and updates of the LCD display. Since the main loop is a giant while(1) loop, it will always be running, the RPM will be counted, and the LCD will be updated several times per second. The function in the interrupt counts the time between IR interrupts, so you can count the RPM in the main loop.

Remember that a computer fan has 7 blades, so this tachometer is designed to work with those fans only. If your fan or other device only produces 4 pulses per revolution, change the code to "(time*4)".

Here is a demo video of how the tachometer works.

The two fans operate at approximately 3000 rpm and 2600 rpm, with an error of about +/-100 rpm.

Review of tachometer on Arduino

The fan generates interrupt pulses, and at the output we see RPM. Although the accuracy is not 100%, but approximately 95%, with the cost of the elements being $10, it makes sense to build this tachometer on Arduino.

So what's now?

Beam break-based systems are useful not only for RPM measurements, but also as other sensors. For example, you want to know whether a door is open or closed. Perhaps you want to know if something was passing under the robot. There are many uses for beam cut, and the circuit used here is so simple that there are many ways to improve and build other amazing devices.

Conclusion

Overall, I consider this project a success... But it's a matter of time and experience.. One way or another, the system works as intended and quite reliably, and we got the expected result. I hope you enjoyed reading this article and learning how to make your own tachometer using Arduino!

Original article in English (translation: Alexander Kasyanov for the site cxem.net)

This describes a digital device that measures the speed of a car and the crankshaft speed of its engine. The indicator is a 1602A type LCD display, it is standard, based on the HD44780 controller.

The designation 1602A actually means that it is on two lines of 16 characters per line. The indicator was purchased on Aliexpress, found by searching for “HD44780” (prices from 81 rubles). As already mentioned, this indicator has two lines. So, in the top line the device shows the speed of the car, and in the bottom line - the engine speed.

Unlike many on-board computers, such as "Orion-BK" and the like, as well as devices with LED seven-segment indicators, this LCD display, when the backlight is on, gives a very clear image, perfectly visible both in the light and at night in the dark , which is especially important for automotive use.

The device circuit is based on a ready-made ARDUINO UNO board, on which the ATMEGA328 microcontroller is located, as well as all its “piping” necessary for its operation, including a USB programmer and a power supply.

The cost of ARDUINO UNO on Aliexpress starts from 200 rubles. A description of the ARDUINO UNO board, as well as the software for it, and the connection to a personal computer is given by the author in L.1, so if anyone doesn’t know what ARDUINO is and “what it’s used with,” be sure to read the article in L. first .1.

The device is connected via power to the output of the car's ignition switch, and receives signals from its Hall sensors, one of which is an ignition sensor, and the second a speed sensor.

Schematic diagram

The device can only work in a car with an injection engine (carburetor cars do not have a speed sensor, and not all have an ignition sensor). The device diagram is shown in Figure 1. In this figure, the ARDUINO UNO board is shown schematically as a “top view”.

Rice. 1. Schematic diagram of a speedometer and tachometer based on Arduino.

To match the ports with sensors, cascades on transistors VT1 and VT2 are used. Since power is supplied to the device from the ignition switch output, it only works when the ignition is on. The speed sensor, as well as the vehicle ignition sensor, are sources of pulses, the frequency of which depends on the rotation of the mechanical parts of the vehicle.

The ignition sensor of a car with a four-cylinder gasoline engine generates two pulses per revolution of the crankshaft. If the engine does not have four cylinders, the pulse repetition rate will be different.

Speed ​​sensors are different, but for the most part, especially for domestic cars, they give 6000 impulses per kilometer. Although there are some that give 2500 impulses per kilometer, perhaps there are others.

Program

The C++ program with detailed comments is given in Table 1. The operation of the program is based on measuring the period of pulses coming from the sensors and subsequent calculation of the speed and rotational speed of the crankshaft.

Table 1. Source code of the program.

To work, use the pulseln function, which measures in microseconds the duration of the positive or negative edge of the input pulse. So, in order to find out the period, you need to add the duration of the positive and negative half-cycles.

where T is the period in seconds, and F is the speed in km/h. Since the period is measured in microseconds the actual formula is:

If the sensor is 2500 pulses per km (Japanese), then the formula will be like this:

Accordingly, given that the period is measured in microseconds:

To measure the crankshaft speed, the formula is used:

where T is the period in seconds, and F is the crankshaft rotation speed in revolutions per minute. Since the period is measured in microseconds, the actual formula is:

Then, the results are displayed in the corresponding lines of the LCD display. The units of measurement are indicated as “km/h” and “ob/tip” (if you don’t like it, you can change it).

If there is no input signal, for example, the ignition is turned on, but the engine is not started or driven, then in the lines where there is no signal there will be the inscription “inf”.

In principle, no setup is required. However, if it is unknown how many pulses per kilometer the speed sensor of a particular car gives, this must first be clarified.

Either you can experimentally adjust the number, which is divided into a period, by checking with the dial speedometer, which is very troublesome, or impossible if the standard speedometer is faulty (which could be the reason for the manufacture of this device).

But it’s better to find out the parameters of the speed sensor. And then calculate the number that is divided by the period in the program. Let's denote this number X, and the number of pulses per kilometer N. Then X can be calculated using the following formula:

X = 3600000000 / N

For example, if the sensor gives, say, 2500 pulses per kilometer:

X= 3600000000 / 2500 = 1440000

Or, if the sensor gives 6000 pulses per kilometer:

X= 3600000000 / 6000 = 600000

Finally

If the device malfunctions, it may be necessary to optimize the operating mode of the input stages on transistors VT1 and VT2, respectively, by selecting the resistances of resistors R3 and R6, as well as the capacitances of capacitors C2 and S3.

Karavkin V. RK-12-16.

Literature:

1. Karavkin V. Christmas tree flasher on ARDUINO as a remedy for the fear of microcontrollers.” RK-11-2016.