Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Arduino
100 min
Share

Measure the speed of any motor with arduino

A contactless speed sensor is a type of tachometer that is used to measure the speed of a rotating object like a motor without physical contact with it.

Project Video

Overview

In this tutorial, we will learn how to make a speedometer or a speed control system using an IR speed sensor and Arduino.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
IR Speed Sensor
Get Item
TT Motor – plastic gear
Get Item
3×18650 Battery Holder
Get Item
Lithium ion 3.7 V 3800mah rechargeable battery – 18650
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the IR speed sensor and the Arduino, as shown in the image below.


Connections from the IR speed sensor to arduino :



     • VCC  → Arduino 5V pin

    • GND →  Arduino GND pin

   • D0 →  Arduino pin 2




Connections from the motor  to 18650 battery holder:



   • Motor  first wire  →  18650 battery holder negative wire

   • Motor  second wire → 18650 battery holder positive wire

Coding


/*
Voltaat learn (http://learn.voltaat.com)
Link for full tutorial: put the link of the tutorial here

Tutorial: measure the speed of any motor with arduino!

The function of this sketch is to obtain the motor speed values and display it on your computer.


Connections from the IR speed sensor to arduino :

• VCC  → Arduino 5V pin

• GND →  Arduino GND pin

• D0 →  Arduino pin 2


Connections from the motor  to 18650 battery holder:

• Motor  first wire  →  18650 battery holder negative wire

• Motor  second wire → 18650 battery holder positive wire


*/

int encoder = 2;

volatile unsigned int counter;
int rpm;


void setup() {
 //making interrupt every time there is a high pulse coming from the speed sensor
 attachInterrupt(0,countpulse,RISING);
  Serial.begin(9600);
}

void countpulse(){
//Each time it receives a high pulse, the counter increases by 1
       counter++;
}

void loop() {
 static uint32_t previousMillis;
 /*When a time of 1 second has passed, he calculates the number of revolutions during
 that second by dividing the counter value by 20 (which is the value of the number of
 slots in the encoder wheel) and then multiplying it by sixty in order to calculate
 the number of revolutions per minute */
 
 if (millis() - previousMillis >= 1000) {
           rpm = (counter/20)*60;          
           counter = 0;
           previousMillis += 1000;
 }
//It prints the speed on the screen in rpm values

 Serial.print("Speed: ");
 Serial.print(rpm);
 Serial.println(" rps");
 delay(100);
}

   
   

Testing it Out

You should also make sure you have chosen the right baud rate (9600) as specified in the code.
know when your plant needs watering

Now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.

know when your plant needs watering

Now, as shown in the image below, the serial monitor displays the speed of the motor in rpm value.

know when your plant needs watering

Resources

No items found.