Help with RPM code

Hi Arduino Forum members,

looking for some help with this code for rpm Arduino Playground - 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:
rpm = 30*1000/(millis() - timeold)*rpmcount; to 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.

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.

Caadi:

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?

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.

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

MarkT:
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.

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

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

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.

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

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 Tutorial: How to design a transistor circuit that controls low-power devices - YouTube

scottyjr:
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?

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?

Caadi:
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).

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.

Krupski:
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?

Any clues?

Did you check to see what the voltage at that point is in each state?

Caadi:
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?

THAT diagram is correct (finally!) :slight_smile:

Have you looked at the signal with an oscilloscope? Maybe you are getting 120 hz "interference" from fluorescent lighting.

i have a same problems, did this problem had been solved? thanks