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



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:

  • Arduino IDE

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

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.


For Speed Sensor(LM393) module:


For Motor Shield L293D:


Code Breakdown:

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.

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

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)


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.





Tags : comparatorinfraredL293dlm393motor driveroptocouplertachometer

Leave a Response