LM393 is one of the cheap and most commonly available speed measuring sensor. In this article, we will know the working of LM393 and interface it with Arduino. Tachometer is also a similar device to measure the speed. I already implemented Tachometer with arduino.
Working of Speed sensor
The sensor has a black column structure with a groove, this structure has an IR diode and a photoresistor. IR rays emit by the IR diode and captured by the photoresistor. This makes an invisible path between them, when you place any object between them this path broke and a signal send to the IC. In ower case, we are using an LM393 comparator IC. This IC converts the signal into a voltage output.
LM393 features
- The sensor work 3.3v ~ 5v power supply.
- Sensor output is High when the object is detected in the groove otherwise Low.
- LM393 Comparator onboard to give digital output.
- Good signal and waveform, with a strong driving ability for more than 15mA.
LM393 Pinout
This sensor mainly has 4 pins VCC, GND, DO & A0:-
Pin name | Function |
VCC | The positive 3.3-5 v power supply. |
GND | power negative. |
D0 | TTL switch signal output |
A0 | analog output |
LM393 connection with Arduino
Code
Download timer master library from this link and add to your arduino sketch.
/*
visit
www.electronicsmith.com
*/
#include "timer.h"
Timer timer;
const int LM393 = 2;
int counter = 0;
void setup() {
attachInterrupt(digitalPinToInterrupt(LM393), count, RISING);
Serial.begin(115200);
timer.setInterval(1000);
timer.setCallback(RPM);
timer.start();
}
void count() {
counter++;
}
void RPM() {
Serial.println(counter * 60);
counter = 0;
}
void loop() {
timer.update();
}