Go Down

Topic: RPM calclater (Read 3326 times) previous topic - next topic

AWOL

Quote
I did changed the baudrate to 9600 and

Don't you want the baud rate to be as high as possible, so that you don't miss too many pulses when you're printing results?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

gshubham96

Quote
Don't you want the baud rate to be as high as possible, so that you don't miss too many pulses when you're printing results?

i'll change the baud rate, that's not the prob here, the thing is why it is showing RPM = o everytime and i also removed "count = 0"
here is the final code
Code: [Select]
#define IRPIN 5

unsigned int count;  // can only be positive
unsigned long current_time;
int prevState;  //  LOW = BLACK, HIGH = WHITE
int newState;

void setup()
{
  Serial.begin(115200) ;
  Serial.println("Start RPM 01") ;
}

void loop()
{
   prevState = digitalRead(IRPIN );   // read the reference state
  current_time = millis();

  //count until 1 minute (= 60*1000 ms, 60000mS) has elapsed
  while (millis() - 60000L <= current_time )  // use L for LONG math !!!
  {
    newState = digitalRead(IRPIN);
    if (prevState == HIGH && newState == LOW)  // this is a transition from LOW to HIGH
    {
      count++ ;
    }
    prevState = newState;
  }
  Serial.println();
  Serial.print("RPM: ") ;
  Serial.println(count);
}
Regards
Shubham Garg

robtillaart

#17
Jul 18, 2011, 12:45 pm Last Edit: Jul 18, 2011, 12:57 pm by robtillaart Reason: 1
That is a valid response if the wheel is not moving.

So the question is does the sensor work?

What is the output of this minimal sketch that should detect the pulse..
Code: [Select]

#define IRPIN 5

void setup()
{
 Serial.begin(115200) ;           /////////////////////////  fastest baudrate is needed !!
 Serial.println("Start test RPM sensor  0.1");
  pinMode (IRPIN, INPUT);
}

void loop()
{
 if (digitalRead(IRPIN) == HIGH) Serial.println(millis());
}

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

AWOL

#18
Jul 18, 2011, 12:46 pm Last Edit: Jul 18, 2011, 12:49 pm by AWOL Reason: 1
Well, the obvious answer is that "count" is not being incremented.
Now, I think that pins default to input, but I always like to be sure.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

gshubham96

@
Code: [Select]
Start test RPM sensor  0.1
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
6
6
6
6
7
7
7
7
7

it stops when not detecting
Regards
Shubham Garg

robtillaart

#20
Jul 18, 2011, 12:54 pm Last Edit: Jul 18, 2011, 12:57 pm by robtillaart Reason: 1
Quote
Now, I think that pins default to input, but I always like to be sure.

AaAAARGHH, pinMode missing error  :smiley-red:

I'll update my sketches above ...
Thanks,

done.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

gshubham96

COde: with PINMODE
Code: [Select]
#define IRPIN 5

unsigned int count;  // can only be positive
unsigned long current_time;
int prevState;  //  LOW = BLACK, HIGH = WHITE
int newState;

void setup()
{
  Serial.begin(115200) ;
  Serial.println("Start RPM 01") ;
  pinMode(IRPIN, INPUT);
}

void loop()
{
   prevState = digitalRead(IRPIN );   // read the reference state
  current_time = millis();

  //count until 1 minute (= 60*1000 ms, 60000mS) has elapsed
  while (millis() - 60000UL <= current_time )  // use L for LONG math !!!
  {
    newState = digitalRead(IRPIN);
    if (prevState == HIGH && newState == LOW)  // this is a transition from LOW to HIGH
    {
      count++ ;
    }
    prevState = newState;
  }
  Serial.println();
  Serial.print("RPM= ") ;
  Serial.println(count);
}


Result:
Code: [Select]
RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0



Still nothing

Regards
Shubham Garg

gshubham96

@robtillaart

Code: [Select]
#define IRPIN 5

void setup()
{
  Serial.begin(115200) ;           /////////////////////////  fastest baudrate is needed !!
  Serial.println("Start test RPM sensor  0.1") ;
  pinMode(IRPIN, INPUT);
}

void loop()
{
  if (digitalRead(IRPIN) == HIGH) Serial.println(millis());
}


Result:
Code: [Select]
Start test RPM sensor  0.1
125
125
126
126
128
128
129
129
130
130
131
131
132
132
133
133
134
134
135
135
136
136
Regards
Shubham Garg

robtillaart

#23
Jul 18, 2011, 01:09 pm Last Edit: Jul 18, 2011, 02:16 pm by robtillaart Reason: 1
OK,  PinMOde was very important to get signal working.

seems like 2 rotations per milli = 2000/sec = 120.000/minute ?????

better explanation is that the signal is high continuously...

PLease try this slightly modified sketch, should print 0's and 1's
Code: [Select]

#define IRPIN 5

void setup()
{
 Serial.begin(115200) ;           /////////////////////////  fastest baudrate is needed !!
 Serial.println("Start test RPM sensor  0.2") ;
 pinMode(IRPIN, INPUT);
}

void loop()
{
 Serial.print(digitalRead(IRPIN) );  /// should do 0001100000  or representing low low low high  low low low
}


-- update --
fixed typo see below
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

gshubham96

#24
Jul 18, 2011, 01:28 pm Last Edit: Jul 18, 2011, 01:30 pm by gshubham96 Reason: 1
my arduino IDE doen't respond when i run this code..:(  :~
and it should be
Quote
Serial.print(digitalRead(IRPIN)) ;

However if I change baud rate to 9600 i get the desired result
Regards
Shubham Garg

robtillaart

#25
Jul 18, 2011, 02:15 pm Last Edit: Jul 18, 2011, 02:18 pm by robtillaart Reason: 1
Thanks for pointing out the typo,

Why do you insist on using 9600 baud?
You can change the baudrate in the IDE serial monitor (lower right) to 115200.
The higher the baudrate =>  the less time serial takes for communicating => the more time there is for sampling the sensor.

Quote
However if I change baud rate to 9600 i get the desired result

At what speed does the wheel rotate in  RPM?
and what is the output?

So the sensor is working, time to go back to the bigger sketches;
please run the sketch from post #21 again and post the output.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

gshubham96

#26
Jul 18, 2011, 06:04 pm Last Edit: Jul 18, 2011, 06:31 pm by gshubham96 Reason: 1
Quote
At what speed does the wheel rotate in  RPM?
and what is the output?

60 RPM

Quote
Why do you insist on using 9600 baud?

tried at 115200 baudrate, nothing
Output of post #21
Code: [Select]
RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0

RPM= 0


shall i post pics or vid of my project?
Regards
Shubham Garg

robtillaart


Conclusion: you get no pulses from the hardware .

code #21 checks for a state change, that doesn't occur => RPM = 0

As I quoted earlier "better explanation is that the signal is high continuously..."

So it is time to check the hardware why the signal is continuously HIGH.

- is the wiring OK?
- how is the sensor connected?
- type sensor - datasheet?
- what is the voltage reflected with white.
- and with black.

Rob
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Techone

I read the posts here, I was thinking,  The system need to be check. I agree with you robtillart.

A. Check the sensor with voltage to check if it have a 0 V for LOW and a 5 V for HIGH.
    If not well the system will not work.

B. Check the software. Instead of the sensor, connect a push-on switch. Press switch - HIGH  no press - LOW.
    Do it rapidely - Like you press a button on a video game. The software should display the number of
    "Press the button" per second or per minute. RPM - Turn per minute = Pulse per minute.

Just an idea.

robtillaart

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up