Motor Speed Tester Using Arduino & IR Sensor

93,657

54

30

About: Hi, I am Mechanical Engineer. But loves Electronic mini projects too. Also like to do creative things. Whenever free, I will always be learning something. Had posted these projects when I was Engineering Stu...

Hey !!!

Is it difficult to measure rpm of motor ???

I don't think so. Here is one simple solution.

Only one IR sensor and Arduino in your kit can do so.

It is very useful for DIY creators & robot makers and is very easy to make. It requires only 5 minutes for set up.

This assembly works well and can measures rpm much accurately upto 5%. I had tested it till 10000rpm.

And Yes, this can be used for any type of motor Big or Small (industrial too)

What you can do with this?

  • Measure rpm / check rpm of motor
  • measure speed of robot m/s (step 4)
  • Maintain constant speed(rpm) of DC motor (step 5)

How to use

  1. Stick aluminium foil piece as reference point anywhere on shaft or on its attachment
  2. Start the motor
  3. Place IR sensor infront of the reference point.

That's it.

Step 1: We Require

Basic Requirement

  1. Arduino
  2. IR sensor
  3. Aluminium foil

LCD if you have

  1. LCD Display
  2. 10K potentiometer or I2C module(will reduce pins)

For controlling speed

  1. Motor Driver
  2. 10K potentiometer

A rigid stand if you have/can make (recommended)

Step 2: How It WORKS ??

So what is the logic behind this ??

It works on basic principle of an encoder and it works much similar to encoder

When a shaft/body rotates, same point on it repetatively comes to original position after one revolution.

But for that it requires some time.

By measuring time (in second) between these two positions ie. completeing one revolution, we get time (second) required to complete one revolution.

Simply taking reciprocal of this value we get rps (revolution per second) of motor.

Multiplying it by 60 will give rpm

Simple haa ! ! !

RPM does not depend on Distance between centre of shaft and reference point.

Now to measure the time difference IR sensor is used. Aluminium foil is used set a reference point. Also it reflects light thus enhances sensitivity of IR. sensor gives HIGH output, when aluminium foil comes infront of the sensor. micros() command is used to measure time which is 10^-6 of second which can measure time lapse at high speed accurately.

Step 3: Preparation & Code

Basic min. requirement

If you want to measure rpm but don't have display.

No problem. You can measure on Arduino's Serial Monitor on PC.

Simply connect data pin of IR sensor to Arduino's pin 2 and connect +5 & ground pin accordingly.

Upload code and test on Serial Monitor

LCD Display

The assembly looks like mess. But it's really simple. Connecting LCD display requires too much wires and connections.

So if you have I2C connector for LCD then I highly recommend to use it. It requires only 2 Arduino pins.

Code

The code uses unsigned long to store time. The code is written so that only when input from IR sensor changes from LOW to HIGH, it will proceed ie. calculate time difference. So it will be triggered only when leading edge of aluminium foil comes in front of the sensor. So there are less chances of false triggering. Each time one revolution is completed, arduino measures time required and it's corresponding rpm which is then displayed on LCD screen. LCD will refresh its value every 0.1 second.

LCD PIN CONNECTIONS

  1. VSS = Ground
  2. VCC = +5V
  3. VEE = Centre pin of Potentiometer
  4. RS = Pin 8
  5. RW = Ground
  6. E = Pin 9
  7. DB0 = N/C
  8. DB1 = N/C
  9. DB2 = N/C
  10. DB3 = N/C
  11. DB4 = Pin 4
  12. DB5 = Pin 5
  13. DB6 = Pin 6
  14. DB7 = Pin 7
  15. LED+ = +5V
  16. LED- = Ground

Step 4: Update 1 : How to Measure Speed (m/s or Km/hr) of Robot

If you are mounting this on a robot and want to know speed of your robot then follow this -

A very basic principle.

Speed = Perimeter of wheel * speed of wheel

But perimeter is Pi times the Diameter of wheel

So Speed = PI*D * speed of wheel

Speed(m/s) = Pi * D(in meter) * rps

Speed(km/hr) = Pi*D(in kilo meter) * rpm * 60


Add this in code

const int D = _____ ; // Diameter in cm (include at the top)

speed = 3.14159*(D/100)*(rpm/60) // speed in m/s

speed = 3.15159*(D/100000)*(rpm*60) // speed in km/hr

Step 5: Update 2 : Controlling Rpm of DC Motor

Now we know the rpm of the motor.

So it's not difficult to manage speed of the motor.

For this purpose we require a motor driver. EN (enable) pin on driver is used to vary speed of motor using PWM (pulse width management). So simply connect pwm pin (pin 11 used in code) to the EN pin on driver. Also set the pin on driver to HIGH which drives the motor.

Same thing can be done by using fast acting NPN transisor. Use resitors to limit current.

Potentiometer knob is used to set the rpm required.

TEST

I tested this code and assembly. Every thing is working well.

Code needed to be slightly fixed because rpm of motor fluctuates wrt set point (speed is not smooth).

But you can try it, it works well. If you have any solution then it will be great.

Advantage of using IR sensor for maintaining conatsnt speed of DC motor

Suppose somehow load is increased on the motor. Which will reduce the RPM of motor. By checking real time rpm, arduino will sense that rpm has been reduced. Accordingly arduino will send signal to increase power supplied to the motor in order to compensate the reduced RPM. Similar thing will happen if load is reduced. Thus a constant RPM will be managed in any condition.

Step 6: Tips and Troubleshooting

1) rpm does not remains stable / not accurate

Change sensitivity of IR sensor by turning knob. Use stand

2) Shows wrong RPM

Reset arduino because code uses micros() which overflows fast. if this not works change sensitivity

I will recommend you to use stand to hold IR sensor

Try this simple and useful RPM tester which is easy to make.

Give your feedback and suggestions.

Thanks :)

Automation Contest 2016

Participated in the
Automation Contest 2016

Share

    Recommendations

    • Beauty Tips Contest

      Beauty Tips Contest
    • Planter Challenge

      Planter Challenge
    • Sensors Contest

      Sensors Contest

    30 Discussions

    0
    None
    sharaijaz

    6 weeks ago on Step 6

    Speed is not getting zero when motor stops, it hold last captured value

    0
    None
    harshas31

    Question 2 months ago

    hello bro , can you share how to measure distance covered by the wheel?

    0
    None
    GiorgiQ

    Question 2 months ago

    Hello
    I prepared your project. Very good idea
    I need 220v engine management 1KV 24000 RPM, accordingly I have developed a powerful regulator with the help of BTA16-600CW
    I have a problem,

    What is the problem?

    Thanks in advance

    0
    None
    SergeyM39

    Question 5 months ago on Step 6

    well thank you very much, i succesfully made it, and i've a question/request pls make the PID tutorial by using IR Sensor (in this tutorial) for the feedback plsss really need it

    2 answers
    0
    None
    Rahul - SSergeyM39

    Answer 4 months ago

    I am happy that you successfully made it. And thank you for your feedback, I will try PID tutorial sometime.

    0
    None
    SergeyM39Rahul - S

    Reply 4 months ago

    anyway can you give the code for I2C Module, because i don't see it in this instructables thread sorry

    0
    None
    SavioA1

    Question 5 months ago on Step 5

    i really didint understand where to put the code for checking speed. can u rewrite the whole code for this project along with the speed code u gave.

    0
    None
    ClaudiaS69

    Question 1 year ago

    Hi! I have to do something similar for a school project, but instead of using batteries to power the motor I have to power it from a 7-25V power source and maintain a constant speed when it reaches a certain voltage. Do you think your project idea will work on my project? If yes, what changes should I do in the circuit? Thank you!

    0
    None
    totigo

    1 year ago

    Just uploaded this to my board to verify it. I haven't tried using it with an IR sensor yet, but without plugging anything in I'm reading 3600 RPM +/- 100 on the serial monitor. Any explanation for this? I am rather new to coding so I'm just hoping I could plug and play. The code won't be used for an LCD, rather "rpm" will be used to control something else.

    0
    None
    MithunKumar1

    1 year ago

    if( ( millis()-refresh ) >= 100 )

    i haven't found this refresh variable anywhere(except the above mentioned code and initialization) can you explain the purpose of this code ad the initial value that will be present in this code

    3 replies
    0
    None
    Rahul - SMithunKumar1

    Reply 1 year ago

    Hi MithnKumar, It's very simple.

    millis() is current live time in milli seconds. So the whole program in that loop is executed only if current time 100miliseconds greater than refresh. new refresh value is set for every execution of loop.

    0
    None
    Rahul - SRahul - S

    Reply 1 year ago

    Hey, I just glanced at all programs. I think in 2nd program ie. program without lcd there should be one more statement in the last loop. After Serial.println(rpm); command there should be refresh = millis(); so it will set that time as new refresh value.

    So after every 0.1s there will be serial output. By the way thanks for the comment :)

    0
    None
    SebastianV70

    1 year ago

    Update: VSS must be connected to Arduino GND, otherwise you will see garbled information as you power up the LCD screen.I did the project and works great, toast for you

    0
    None
    RegaW

    2 years ago

    hey Rahul. What type the IR sensor that you are using? And can i request the circuit drawing of this project? Thanks :)

    0
    None
    vikram2.reddy

    2 years ago

    hey rahul .can i get the project report of this?

    0
    None
    ateebhassan000

    2 years ago

    Hi Rahul...!!! I am getting error.....I am using Flying Fish MH Sensor Series. It has two lights one for power on and other for output indicator....I have copied your code and burn it into my Arduino...I am getting error that the indicator light on sensor is turned on..and LCD is showing RPM=0...
    Then I have changed the LCD pin arrangements as LiquidCrystal lcd(12, 11, 5, 4, 3, 2); and dataIn = 7; NOw the sensor indicating light turns off it on when i put my hand in front of the sensor and turns off by removing hand. Now error is that LCD is showing starting RPM =4765 and when i placed rotating motor infront of sensor it is giving random values in thousands. MY LCD no is 1602A

    kindly help me out this.....ateebhassan000@gmail.com