Hi,
Im trying to mesure rpm of an motor with arduino and one QRD1114 IR Led.
the QRD1114 connection from Bildr, i use 220ohm and 4.7Kohms:
To making test im using one motor with ardumoto with same speed at 100 using analogWrite. I put one blank mark to make the "pulse".
the first sketch i upload is to count the number of turns during 60s:
#define PwmPinMotorB 11
#define DirectionPinMotorB 13
unsigned long time1=0;
unsigned long time2=0;
int motorOn=0;
int count=0;
void setup(){
Serial.begin(9600);
pinMode(PwmPinMotorB, OUTPUT);
pinMode(DirectionPinMotorB, OUTPUT);
digitalWrite(DirectionPinMotorB, LOW);
}
void loop(){
int valorQRD=analogRead(A0);
Serial.println(valorQRD);
if (valorQRD<100){
count++;
}
if (motorOn==0){
time1=millis();
analogWrite(PwmPinMotorB, 100);
motorOn=1;
}
time2=millis();
if (time2>=time1+60000){
analogWrite(PwmPinMotorB, 0);
Serial.print(count);
Serial.println(" RPM");
motorOn=0;
count=0;
delay(5000);
}
}
he give me 550 turns during each 60s for pwm 100.
Now i know the rpm for this motor with 100 pwm.
I want to mesure the actual rpm, for this i use the code from Arduino Playground:
http://arduino.cc/playground/Learning/Tachometer
Just little modifications to add the ardumoto:
int val;
long last=0;
int stat=LOW;
int stat2;
int contar=0;
#define PwmPinMotorB 11
#define DirectionPinMotorB 13
int sens=100; // this value indicates the limit reading between dark and light,
// it has to be tested as it may change acording on the
// distance the leds are placed.
int nPalas=1; // the number of blades of the propeller
int milisegundos=250; // the time it takes each reading
void setup()
{
pinMode(PwmPinMotorB, OUTPUT);
pinMode(DirectionPinMotorB, OUTPUT);
digitalWrite(DirectionPinMotorB, LOW);
analogWrite(PwmPinMotorB, 100);
Serial.begin(9600);
}
void loop()
{
val=analogRead(0);
if(val<sens)
stat=LOW;
else
stat=HIGH;
//indicate the state of the circuit.
if(stat2!=stat){ //counts when the state change, thats from (dark to light) or
//from (light to dark), remmember that IR light is invisible for us.
contar++;
stat2=stat;
}
if(millis()-last>=milisegundos){
double rps=((double)contar/nPalas)/2.0*1000.0/milisegundos;
double rpm=((double)contar/nPalas)/2.0*60000.0/(milisegundos);
Serial.print((contar/2.0));Serial.print(" RPS ");Serial.print(rps);
Serial.print(" RPM");Serial.print(rpm);Serial.print(" VAL ");Serial.println(val);
contar=0;
last=millis();
}
}
but it´s not the results i expect:
2.50 RPS 10.00 RPM600.00 VAL 766
2.00 RPS 8.00 RPM480.00 VAL 805
2.00 RPS 8.00 RPM480.00 VAL 749
2.00 RPS 8.00 RPM480.00 VAL 827
2.50 RPS 10.00 RPM600.00 VAL 40
2.50 RPS 10.00 RPM600.00 VAL 771
2.00 RPS 8.00 RPM480.00 VAL 729
2.00 RPS 8.00 RPM480.00 VAL 807
3.00 RPS 12.00 RPM720.00 VAL 867
2.00 RPS 8.00 RPM480.00 VAL 925
2.00 RPS 8.00 RPM480.00 VAL 765
2.00 RPS 8.00 RPM480.00 VAL 782
3.00 RPS 12.00 RPM720.00 VAL 832
2.00 RPS 8.00 RPM480.00 VAL 924
2.00 RPS 8.00 RPM480.00 VAL 764
2.00 RPS 8.00 RPM480.00 VAL 809
3.00 RPS 12.00 RPM720.00 VAL 799
2.00 RPS 8.00 RPM480.00 VAL 753
2.00 RPS 8.00 RPM480.00 VAL 826
3.00 RPS 12.00 RPM720.00 VAL 855
2.00 RPS 8.00 RPM480.00 VAL 901
2.00 RPS 8.00 RPM480.00 VAL 761
2.00 RPS 8.00 RPM480.00 VAL 810
3.00 RPS 12.00 RPM720.00 VAL 850
2.00 RPS 8.00 RPM480.00 VAL 922
2.00 RPS 8.00 RPM480.00 VAL 751
2.00 RPS 8.00 RPM480.00 VAL 774
3.00 RPS 12.00 RPM720.00 VAL 901
2.00 RPS 8.00 RPM480.00 VAL 794
2.00 RPS 8.00 RPM480.00 VAL 882
3.00 RPS 12.00 RPM720.00 VAL 784
2.00 RPS 8.00 RPM480.00 VAL 745
2.00 RPS 8.00 RPM480.00 VAL 968
2.00 RPS 8.00 RPM480.00 VAL 743
3.00 RPS 12.00 RPM720.00 VAL 840
2.00 RPS 8.00 RPM480.00 VAL 766
2.00 RPS 8.00 RPM480.00 VAL 822
3.00 RPS 12.00 RPM720.00 VAL 758
2.00 RPS 8.00 RPM480.00 VAL 882
2.00 RPS 8.00 RPM480.00 VAL 788
2.50 RPS 10.00 RPM600.00 VAL 50
2.50 RPS 10.00 RPM600.00 VAL 717
2.00 RPS 8.00 RPM480.00 VAL 784
2.00 RPS 8.00 RPM480.00 VAL 854
3.00 RPS 12.00 RPM720.00 VAL 763
2.00 RPS 8.00 RPM480.00 VAL 857
2.00 RPS 8.00 RPM480.00 VAL 904
2.00 RPS 8.00 RPM480.00 VAL 783
3.00 RPS 12.00 RPM720.00 VAL 806
2.00 RPS 8.00 RPM480.00 VAL 779
2.00 RPS 8.00 RPM480.00 VAL 801
3.00 RPS 12.00 RPM720.00 VAL 834
2.00 RPS 8.00 RPM480.00 VAL 767
2.00 RPS 8.00 RPM480.00 VAL 863
2.50 RPS 10.00 RPM600.00 VAL 44
2.50 RPS 10.00 RPM600.00 VAL 885
2.00 RPS 8.00 RPM480.00 VAL 761
2.00 RPS 8.00 RPM480.00 VAL 943
3.00 RPS 12.00 RPM720.00 VAL 857
2.00 RPS 8.00 RPM480.00 VAL 761
2.00 RPS 8.00 RPM480.00 VAL 895
3.00 RPS 12.00 RPM720.00 VAL 827
2.00 RPS 8.00 RPM480.00 VAL 749
2.00 RPS 8.00 RPM480.00 VAL 852
3.00 RPS 12.00 RPM720.00 VAL 400
2.00 RPS 8.00 RPM480.00 VAL 844
2.00 RPS 8.00 RPM480.00 VAL 916
2.00 RPS 8.00 RPM480.00 VAL 766
3.00 RPS 12.00 RPM720.00 VAL 922
2.00 RPS 8.00 RPM480.00 VAL 776
2.00 RPS 8.00 RPM480.00 VAL 941
3.00 RPS 12.00 RPM720.00 VAL 754
2.00 RPS 8.00 RPM480.00 VAL 741
2.00 RPS 8.00 RPM480.00 VAL 958
2.00 RPS 8.00 RPM480.00 VAL 751
3.00 RPS 12.00 RPM720.00 VAL 776
i have constant speed but rpm change a lot, i know the speed is +/-550rpm by results in my first test but from 480 to 720 it´s a huge difference!
Every time val<100 i have a good value=600 (+/- 550), i know is when the blank mark pass by the IR Led.
Any ideas?
