Pages: [1] 2   Go Down
Author Topic: Help with RPM code  (Read 3287 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Arduino Forum members,

looking for some help with this code for rpm http://arduino.cc/playground/Main/ReadingRPM

Instead of using an hall effect sensor, I have in place a photo-interrupter that gives a high logic when blocked.
Since I am only gettings 1 pulse per revolution I have changed the line:
Code:
rpm = 30*1000/(millis() - timeold)*rpmcount;
  to
Code:
rpm = 60*1000/(millis() - timeold)*rpmcount;

The arduino uno  I'm using is R3 and have the output from the photo-interrupter connected to pin2.
photo-interrupter name: KTIR0611S

connected as in picture below.


Motor am using is a 80mm 12V pc fan, running on 9Vdc. Not sure about how fast such a motor should go.

Here is some of the kind of values am getting.
Quote
31984
59580
59580
31984
31984
53212
25876
4448
53212
15072
53212
42508
5096
28400
54312
29584
32592
32592
21068
36900
53212
15072
15072
9724
36900
25876
15072
21068
9724
36900
15072
25876
29584
9724
53212
4448
21068
27856
59568
48144
25876
25876
64136
25876
48144
48144
29584
29584
56300
29584
29584
56300
1460
29584
2908
41848
17520
21068
21068
48144
32592
48144
48144
48144
44336
56300
17520
32592
59568
21068
59568
32592
59568
36900
64136
64136
64136
64136
9724
9724
25876
25876
64136
9724
36900
9724
59568
59568
48144
44336



Hope some one can help me.

Thanks.


Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 799
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset





You are going to wreck your 2N2222 that way! There's no resistor to limit the current from the opto to the base-emitter junction!

Why not just get rid of the 2N2222 and put the emitter of the opto to ground and the collector to the 10K resistor?
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

tiny mistake on picture fixed


The reason I did not get the output from the photo-transistor directly is because the output voltage and current are too low to register as high logic and could not even light a red led.  If the current coming into the base of the 2n2222a is that low I hardly doubt it would wreck the transistor.

Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12092
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like the opto coupler is either broken or wired the wrong way round - you're giving it a good 30mA or so of drive - have you checked that each side of the opto coupler is connected the right way round?

And those values aren't very meaningful without _all_ the code - or some idea of what you are expecting (whats generating the pulses?  how many per revolution?)
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like the opto coupler is either broken or wired the wrong way round - you're giving it a good 30mA or so of drive - have you checked that each side of the opto coupler is connected the right way round?

And those values aren't very meaningful without _all_ the code - or some idea of what you are expecting (whats generating the pulses?  how many per revolution?)

it says it all in the post, 12V dc motor from pc fan running at 9V set up to block the photo-interrupter every revolution. Not sure how fast it is suppose to spin but the values am getting are way too random. I am sure the photo-interrupter works because the arduino detects when it is blocked.  The code am using is from the readingRPM page from arduino playground.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

50-60K is cranking seems a bit to fast how fast does it update the rpm on the monitor?
Logged

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why is a transistor needed? Couldn't the 10K resistor be in series with the photo-interrupter collector to 5V line and the emitter of the photo-interrupter tied to ground; the signal being read at the resistor-collector junction? - Scotty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The photo transistor outputs about 7mA without the 10kohm resitor. I assume with the resistor connected in series it would output even less.

I remember testing it like so but the arduino did not detect a change on the pin.  


What current is required for the arduino digital inputs? Can't seem to find that on the site.
Logged

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Found this:
Properties of Pins Configured as INPUT
Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs with pinMode(). Pins configured as inputs are said to be in a high-impedance state. One way of explaining this is that input pins make extremely small demands on the circuit that they are sampling, say equivalent to a series resistor of 100 megohm in front of the pin. This means that it takes very little current to move the input pin from one state to another, and can make the pins useful for such tasks as implementing a capacitive touch sensor, reading an LED as a photodiode, or reading an analog sensor with a scheme such as RCTime.

on the Arduino site under Learning/Foundations/Microcontrollers/Digital Pins.

- Scotty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I could be wrong but I remember hearing or reading somewhere that it will sense as little as 1ua or .0001 amps. Is your RPM input pin a Digitalread or Analogread?

If ya have the time take a look at this video
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Found this:
Properties of Pins Configured as INPUT
Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs with pinMode(). Pins configured as inputs are said to be in a high-impedance state. One way of explaining this is that input pins make extremely small demands on the circuit that they are sampling, say equivalent to a series resistor of 100 megohm in front of the pin. This means that it takes very little current to move the input pin from one state to another, and can make the pins useful for such tasks as implementing a capacitive touch sensor, reading an LED as a photodiode, or reading an analog sensor with a scheme such as RCTime.

on the Arduino site under Learning/Foundations/Microcontrollers/Digital Pins.

- Scotty

Yes I read this but what value is very little current?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok I figured that my photo-interrupter might be faulty. So I build my own IR transmitter receiver circuit. I am getting the same problem, the output is too high. I tested to see the rpm with the hall effect output from the fan and it gave me about 2400 rpm. 

What is the problem with using IR sensor and source for speed monitoring?

Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 799
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

tiny mistake on picture fixed


The reason I did not get the output from the photo-transistor directly is because the output voltage and current are too low to register as high logic and could not even light a red led.  If the current coming into the base of the 2n2222a is that low I hardly doubt it would wreck the transistor.



It's still wrong! The opto (if it saturates) will send all the current it can into the base-emitter junction of your 2N2222. As to which one will fry first... your guess is as good as mine.

Put about a 470 ohm resistor between the emitter of the opto and the base of the 2N2222. That will limit the base current to about 10 milliamps max (probably a bit less due to the base-emitter drops of both devices).
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 799
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Let me ask you this: Does your fan have 3 wires? A lot of computer muffin fans have 3 wires... power, ground and a TACH OUTPUT! (open collector).

Check it out.
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Let me ask you this: Does your fan have 3 wires? A lot of computer muffin fans have 3 wires... power, ground and a TACH OUTPUT! (open collector).

Check it out.

Yes I did get one of the 3 wire fans yesterday to test the code and it worked fine, got about 2400rpm.  I also built a new IR rpm sensor instead of using the photo-interrupter, It still gave me wrong numbers.

Here is the circuit I used:


I have seen other people make these circuits so why is not working for me. What is wrong?
Logged

Pages: [1] 2   Go Up
Jump to: