How do I measure the speed of a DC motot using LM393 IR speed sensor?
Please give me an arduino code that measures the speed of the DC motor using LM393 IR speed sensor and display the result in LCD.
Take a look at this search lots of examples to mess with
[Tachometer site:http://forum.arduino.cc](http://"Tachometer site:http://forum.arduino.cc")
I have looked in to this link but there is no correct solution
The LM393 is not a speed sensor. It can be used for that task, but only with further electronic and mechanical parts. What you need is a Rotary Encoder.
Dineshkannan:
I have looked in to this link but there is no correct solution
What have you created? That we can help you with?
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4,5,6,7);
// read the hall effect sensor on pin 2
const int hallPin=2;
const int shiftLed=3;
const unsigned long sampleTime=1000;
const int maxRPM = 10200;
void setup()
{
pinMode(hallPin,INPUT);
pinMode(shiftLed,OUTPUT);
Serial.begin(9600);
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("initializing");
delay(1000);
lcd.clear();
}
void loop()
{
delay(100);
int rpm=getRPM();
lcd.clear();
displayRPM(rpm);
displayBar(rpm);
}
int getRPM()
{
// sample for sampleTime in millisecs
int kount=0;
boolean kflag=LOW;
unsigned long currentTime=0;
unsigned long startTime=millis();
while (currentTime<=sampleTime)
{
if (digitalRead(hallPin)==HIGH)
{
kflag=HIGH;
}
if (digitalRead(hallPin)==LOW && kflag==HIGH)
{
kount++;
kflag=LOW;
}
currentTime=millis()-startTime;
}
int kount2rpm = int(60000./float(sampleTime))*kount;
return kount2rpm;
}
void displayRPM(int rpm)
{
lcd.clear();
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print(rpm,DEC);
if((rpm)==60) //change value to own choice
{
digitalWrite(shiftLed,HIGH);
}
else if((rpm)==120) //change value to own choice
{
digitalWrite(shiftLed,HIGH);
}
else if((rpm)==180) //Change value to own choice
{
digitalWrite(shiftLed,HIGH);
}
else
{
digitalWrite(shiftLed,LOW);
}
lcd.setCursor(7,0);
lcd.print("RPM");
}
void displayBar(int rpm)
{
int numOfBars=map(rpm,0,maxRPM,0,15);
lcd.setCursor(0,1);
if (rpm!=0)
{
for (int i=0; i<=numOfBars; i++)
{
lcd.setCursor(i,1);
lcd.write(1023);
}}}[/color]
Here's someone's code that has tachometer and LCD display
This should work perfectly with what you've given us to work with.
zhomeslice:
What have you created? That we can help you with?// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4,5,6,7);
// read the hall effect sensor on pin 2
const int hallPin=2;
const int shiftLed=3;
const unsigned long sampleTime=1000;
const int maxRPM = 10200;
void setup()
{
pinMode(hallPin,INPUT);
pinMode(shiftLed,OUTPUT);
Serial.begin(9600);
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("initializing");
delay(1000);
lcd.clear();
}
void loop()
{
delay(100);
int rpm=getRPM();
lcd.clear();
displayRPM(rpm);
displayBar(rpm);
}
int getRPM()
{
// sample for sampleTime in millisecs
int kount=0;
boolean kflag=LOW;
unsigned long currentTime=0;
unsigned long startTime=millis();
while (currentTime<=sampleTime)
{
if (digitalRead(hallPin)==HIGH)
{
kflag=HIGH;
}
if (digitalRead(hallPin)==LOW && kflag==HIGH)
{
kount++;
kflag=LOW;
}
currentTime=millis()-startTime;
}
int kount2rpm = int(60000./float(sampleTime))*kount;
return kount2rpm;
}
void displayRPM(int rpm)
{
lcd.clear();
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print(rpm,DEC);
if((rpm)==60) //change value to own choice
{
digitalWrite(shiftLed,HIGH);
}
else if((rpm)==120) //change value to own choice
{
digitalWrite(shiftLed,HIGH);
}
else if((rpm)==180) //Change value to own choice
{
digitalWrite(shiftLed,HIGH);
}
else
{
digitalWrite(shiftLed,LOW);
}
lcd.setCursor(7,0);
lcd.print("RPM");
}
void displayBar(int rpm)
{
int numOfBars=map(rpm,0,maxRPM,0,15);
lcd.setCursor(0,1);
if (rpm!=0)
{
for (int i=0; i<=numOfBars; i++)
{
lcd.setCursor(i,1);
lcd.write(1023);
}}}[/color]
Here's someone's code that has tachometer and LCD display This should work perfectly with what you've given us to work with.
Sorry, can give the source (?)