Mini tachometer (RPM meter) using Optocoupler Sensor and Motor Shield L293D

Overview:

How important is it to know the speed of a car or moving object? Is it really necessary to know the velocity of a moving object?

In this tutorial we will see how to connect and use an Optocoupler sensor – photo interrupter module by powering the Motor by Motor Shield L293D. We will count the number of times the speed sensor goes from Low to High into a second and then divide that number by 20 (number of holes in the encoder disc) to get the number of revolutions per second.

Hardware Used:

  • 2 – Arduino Uno

  • 1 – Gear Motor
  • 
    
  • 1  – Comparator Speed Sensor Module (LM393)
  • 
    
  • 1 – Motor Shield L293D
  • 
    
  • 1- 6v Battery
  • Wires
  • 
    
    

    You can buy all this Hardware at Createlabz.

    Software Used:

    Library Used:

    Application Description:

     

    Here is a motor speed sensor module, the major goal is to check the rate of an electric motor. The module can be used in association with a microcontroller for motor speed detection, pulse count, position limit, etc. Basically, the microcontroller-compatible motor speed sensor module described is a simple device that yields processed pulse trains when the visual path of its optical sensor is physically interrupted by some sort of slotted wheel or similar mechanism (an optical sensor commonly consists of a light emitting diode that provides the illumination, and a phototransistor that senses the presence or absence of that illumination).

    A Photointerrupter is a transmission-type photosensor, which typically consists of a light emitting elements and light receiving elements aligned facing each other in a single package, that works by detecting light blockage when a target object comes between both elements, acting as an optical switch.

    Motor Shield L293D

     

     

    createlabz.store

    We use this kind of Motor shield because it is convenient to power up and down a motor. By just changing the codes and some easy wiring, we can easily compare the speed of the motor if our project is really functioning. We also used another arduino for this shield because it has another code to be uploaded.

     

    Set-up the Hardware:

    Vcc = 5.5v

    Gnd = Gnd

    DO = D3 of Arduino

    AO = no use

     

    This is the actual wiring of the motor and the shield.

    Code:

    For Speed Sensor(LM393) module:

     

    #include "TimerOne.h"
    unsigned int counter=0;
    
    void docount()  // counts from the speed sensor
    {
      counter++;  // increase +1 the counter value
    } 
    
    void timerIsr()
    {
      Timer1.detachInterrupt();  //stop the timer
      Serial.print("Motor Speed: "); 
      int rotation = (counter * 3);  // divide by number of holes in Disc
      Serial.print(rotation,DEC);  
      Serial.println(" Rotation per Minute"); 
      counter=0;  //  reset counter to zero
      Timer1.attachInterrupt( timerIsr );  //enable the timer
    }
    
    void setup() 
    {
      Serial.begin(9600);
      
      Timer1.initialize(1000000); // set timer for 1sec
      attachInterrupt(0, docount, RISING);  // increase counter when speed sensor pin goes High
      Timer1.attachInterrupt( timerIsr ); // enable the timer
    } 
    
    void loop()
    {
      
    }

     

    For Motor Shield L293D:

     

    #include <AFMotor.h>
    
    AF_DCMotor motor(2);
    
    void setup() {
      Serial.begin(9600);           // set up Serial library at 9600 bps
      Serial.println("Motor test!");
    
      // turn on motor
      motor.setSpeed(200);
     
      motor.run(RELEASE);
    }
    
    void loop() {
      uint8_t i;
      
      Serial.print("tick");
      
      motor.run(FORWARD);
      for (i=0; i<255; i++) {
        motor.setSpeed(i);  
        delay(10);
     }
    }

     

    Code Breakdown:

     

    void docount()  // counts from the speed sensor
    {
      counter++;  // increase +1 the counter value
    }

    This function is do count. Its function in the attachInterrupt is ISR, this function must take no parameters and return nothing. This function is sometimes referred to as an interrupt service routine.

    void timerIsr()
    {
      Timer1.detachInterrupt();  //stop the timer
      Serial.print("Motor Speed: "); 
      int rotation = (counter * 3);  // divide by number of holes in Disc
      Serial.print(rotation,DEC);  
      Serial.println(" Rotation per Minute"); 
      counter=0;  //  reset counter to zero
      Timer1.attachInterrupt( timerIsr );  //enable the timer
    }

    This function was made because this will initiate the measurement of the motor and will be called later in the void set up. Also we use

    int rotation = (counter * 3);

    because when we receive this code the default of this unit of measurement was Rotation per Second and we did use Rotation per Minute so

    Number holes of disc = 20

    Rotation Per Second = counter/number holes of Disc

    Rotation Per Minute = (counter/number holes of Disc)(60 sec)

    Conclusion:

    Of all the projects that I’ve handles, I find this one the most interesting because mini motors are fun to use. There are so many things that you can do on motors, you can use this to make a customize mini powerful and super fast toy car and many more. I hope also you learned something from this tutorial and use this as your reference for your next upcoming projects.

     

    References:

    brainy-bits.com/speed-sensor-with-arduino

    https://www.electroschematics.com/12275/motor-speed-sensor-module-circuit/

    https://sites.google.com/site/myscratchbooks/home/projects/project-11-infrared-speed-sensing-module

     

     

    The post Mini tachometer (RPM meter) using Optocoupler Sensor and Motor Shield L293D appeared first on CreateLabz.

    ComparatorInfraredKnowledgebaseL293dLm393Motor driverOptocouplerTachometer

    Leave a comment

    All comments are moderated before being published