Pages: 1 [2] 3   Go Down
Author Topic: RPM calclater  (Read 2955 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26296
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

"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.

Delhi, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
~
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
}
Logged

Regards
Shubham Garg

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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());
}
« Last Edit: July 18, 2011, 05:57:15 am by robtillaart » Logged

Rob Tillaart

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26296
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

« Last Edit: July 18, 2011, 05:49:35 am by AWOL » Logged

"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.

Delhi, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
~
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@
Code:
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
Logged

Regards
Shubham Garg

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 18, 2011, 05:57:32 am by robtillaart » Logged

Rob Tillaart

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

Delhi, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
~
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

COde: with PINMODE
Code:
#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:
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

Logged

Regards
Shubham Garg

Delhi, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
~
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@robtillaart

Code:
#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:
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
Logged

Regards
Shubham Garg

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
« Last Edit: July 18, 2011, 07:16:34 am by robtillaart » Logged

Rob Tillaart

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

Delhi, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
~
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

my arduino IDE doen't respond when i run this code..smiley-sad  smiley-confuse
and it should be
Quote
Serial.print(digitalRead(IRPIN)) ;
However if I change baud rate to 9600 i get the desired result
« Last Edit: July 18, 2011, 06:30:58 am by gshubham96 » Logged

Regards
Shubham Garg

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 18, 2011, 07:18:25 am by robtillaart » Logged

Rob Tillaart

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

Delhi, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
~
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
« Last Edit: July 18, 2011, 11:31:47 am by gshubham96 » Logged

Regards
Shubham Garg

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

Rob Tillaart

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

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good idea!
Logged

Rob Tillaart

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

Pages: 1 [2] 3   Go Up
Jump to: