View Full Version : optocoupler meets air pressure

05-24-2005, 10:24 PM
Ok, so actually this question is just an extension of the "pump contolled airflow" post. I mentioned before that I was going to try to read airflow by putting a DC fan in the path of the air and read the voltage that would resultˇfrom ˇthe spinning of the fan. So I got my selfˇ several DC fans, fired up the compressed air, hooked up the voltometer, and got a reading of nearly zilch. So here's plan B: I took apart the dc fan, and am now just using the fan and the bearings that where hooked to it. I also took apart a trackball, and got from it the IR interupter disk (it's just a metal disk with holes around the outside perimeter) and the optocoupler arrangement, which consists of an optical transistor and emitter pair. I hooked this up to the fan, so that when air is flowing, the fan spins, the interupt disk interupts the transitor signal, and the device out puts from zero, to five volts. usually, when the fan is spinning as fast as it can, the transistor is outputting around two volts- I suppose because the disk is allowing an equal amount of offs and ons to trigger through the disk. What I really need here, is the speed of the fan to result in at least three input states going to the stamp (slow, medium ,& fast, lets call them.) I know I need the analog out put signal here to be converted to digital before it reaches the stamp, but I was wondering if the input signal could be achieved by use of comparators? Here's what I'm thinking: three comparators read the voltage difference between say vdd, and the out put of the optocoupler- if the voltage reaches 1.5V, than the first comparator triggers a signal to pin x, if it reaches 2V, then that comparator sends a signal to pin y, and 5 volts goes to pin z. Could I use this configuration in conjuntion with the PULSIN command to read the speed of the fan? Would I even need the PULSIN command? Is this ridiculously complicated for what I'm trying to do here? I've never used an AD converter before, so I'm fuzzy on the methods I would use to achieve my goal with one.

05-24-2005, 10:33 PM
Oh, i almost forgot- to make things more complicated: sometimes the disk stops spinning, and the voltage sits @ 5- even when nothings moving. Poo.

Paul Baker
05-25-2005, 01:17 AM
I dont think it is nessesary for you to drop into the analog domain, the signal produced by the IR interruptor is digital PWM (fixed duty cycle, variable frequency). The reason your getting an analog value is your multimeter is averaging the value measured on the signal. Since the signal is digital, just process it as a digital signal. To get a value you would either use COUNT, which would have the effect of averaging the pulses over COUNT's timeout period, or use PULSIN to measure the pulse width of the signal to produce an instantaneous speed calculation. If you are using the PULSIN command, you should figure out the duty cycle of the fan blades output signal since it isnt likely going to be 50% (large fan blades would interrupt a larger portion of the signal resulting in <50% duty cycle, whereas thin blades would interrupt less of the signal resulting >50% duty cycle), then use this to compute the actual speed of the fan blade. If any of this isn't clear to you, let me know and I will try to explain it more clearly.

Paul Baker
05-25-2005, 01:34 AM
Forget the talk about duty cycle in the above post, it is set by your interruptor disk, which should be nearly 50% duty cycle. (You could still measure it and adjust the value if it turns out to not be 50%, but your only trying to measure relative speeds so it isn't nessesary anyways).

Upon further thought, trying to measure the analog value won't work as you expect it would, to illustrate, here are two waveforms of the fan spinning at two different speeds:

_ _ _ _ _ _ _| |_| |_| |_| |_| |_| |_| |_
___ ___ ___ ___
| |___| |___| |___| |

As you can see the top waveform corresponds to a fan spinning twice as fast as the bottom waveform, but if you were to compute the average value of each of the two signals (over a long enough averaging window) they would be the sameˇsame since both are at 5V half the time and 0V half the time.

05-25-2005, 01:35 AM
Paul, thank's for the insight! I really only get about half of what your saying, though. I'm relieved to hear you say that my signal is digital- I've been fiddling with comparator's all day, with no luck. What I'm really caught up on, is that the signal isnt just going from 0 to 5 in steps. If the interupter disk is taken away from the opto, the signal stays at 5v. Sooo... if I want the STAMP to read high, when the fan is spinning at top speed, I think I may need to look into some other method of sensing the speed of the fan. Otherwise, if the disk stops when the "hole" is in front of the IR LED, then the STAMP will think that the fan is running at top speed. I'm sorry that I'm going in circles here, I just trying to figure out the best way to do this thing, and I keep hitting snags. Thanks very much for your help though. I think if I read enough posts, I'll eventualy stumble on to something that might work!

Paul Baker
05-25-2005, 02:11 AM
Ok we are on enough of the same page now that I think this can be ironed out quickly.

The value obtained through PULSIN has a 1/x relationship with the speed of the fan, since PULSIN is measuring the period of waveform and frequency = 1/period. So the lower the value returned by PULSIN, the faster the fan is spinning with one exception: the value of 0 returned by PULSIN means the fan is not spinning at all (the PULSIN waits until the timeout happens looking for the pulse to change, but this doesn't happen because the fan isn't spinning). You could calculate 1/(PULSIN value) to give a value in frequency, but this inst nessesary because you can just map the value to the appropriate speed range value.

If you desire a 4 state value (High, Medium, Low, Stop), calculate the lowest possible value returned by PULSIN (this occurs when the fan is spinning its fastest). Lets just say 255 is the lowest number produced by pulsin, this means the range of values produced by the system will be 0 or 256-65535, 0 returned means the fan is stopped, if a non-zero number is returned by PULSIN (say x) then the speed value Low=1, Medium = 2, High = 3, perform the following calculation: Integer((65535-x)/(3*255))+1. This subdivides the range of X into three seperate areas: Low = 43775-65535, Medium = 22015-43775, High = 255-22015. The value 3 in the equation is the number of regions, increase it if you want more than 3 regions of speed. The 255 value in the equation is the minimum value returned through PULSIN. Ask for clarification if any of this is unclear.

<EDIT> wait the equation above isn't correct, let me work on it some more </EDIT>

Ok heres the corrected equation:

Speed range = R - Integer((R*(x-MinV)/(MaxV-MinV))

Where R is the number of regions (R=3, for the above example)

X is the value returned by PULSIN

MaxV is the maximum valueˇreturned by PULSINˇ(65,535)

MinV is one less than the minimum value returned by PULSIN (254 for our example (255-1))

Integer() is truncation of the value (2.6 becomes 2)

The returned value of 0 by PULSIN is a special case (ie test for it then just output a Stop condition, don't plug 0 into the above equation, it will produce the wrong result)

Post Edited (Paul Baker) : 5/24/2005 9:23:46 PM GMT

05-25-2005, 02:43 AM
Wow! Youre freak'n smart! Seriously. Words cannot explain how gratful I am for your help. I hate math. I am going to take your PULSIN info, and your post,and my little fan, and go to some quiet place to think about it, for a very, very long time. You should sit back and bask in the glow of greatness. Seriously. THANK YOU THANK YOU THANK YOU. I will keep you updated as the project prgresses. THANK you.

05-25-2005, 02:49 AM
any chance those dc servo's have diodes in them?

I don't see why you wouldn't get some voltage on them if they are spinning up!


"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

05-25-2005, 02:54 AM
actually Steve, as I smashed apart one of them (half anger, half curiosity) I did notice more components than I though would be necessary for a DC motor.

Paul Baker
05-25-2005, 03:02 AM
No problem, glad to help. I altered the minimum hypothetical MinV value above from 256 to 255 to fit with the rest of the post (I assumed the MinV was 256 originally then used 255 in the calculations, this is just a minor detail).

How did your reedswitch/hall effect sensor blocks project turn out?

05-25-2005, 03:16 AM
actually it's funny you should mention that, as I hold a hall effect sensor in my hand right now...decided to fiddle around on break. the projec thas been put off for awhile, ever sense my boss strode in here to tell me to make a pump activated project. STAMP is at the center of my little world. If you think I am struggling, you should see my boss. He bought the STAMP works book, and board and everything, did the first project, then permanetly dumped it all in my lap. Of course, Im happy to learn it all. If I could go back to school it would be electronics instead of art school. If only I could turn back the hands of time.

Paul Baker
05-25-2005, 04:31 AM
Interactives said...
If I could go back to school it would be electronics instead of art school. If only I could turn back the hands of time.
One of my favorite sayings is "You're never to old to learn and never too young to teach". With perseverance nearly anyone could pickup how to program the stamp, the hardware can be more difficult, but thats what we are here for.

kelvin james
05-25-2005, 01:11 PM
Here is a way you could check airflow by a variable voltage. Just think of a vent damper or a choke on a carbeurator, they are a spring loaded butterfly valve that are normally closed, but when the force of air is blown against it, it will open a certain amount depending on the force of the air. Now all that has to be done is to measure the degree of movement from the shaft holding the damper. And that could be done pretty easy with a pot, or an encoder, or accelerometer, whatever. You would have to do your own calibration for the amount of movement, and the mechanical rigging of the valve, but should not be that hard. Or you could remove the mass air flow sensor out of your boss's car, and use that. http://forums.parallax.com/images/smilies/smile.gif


05-25-2005, 06:49 PM
Sure they are not a form of stepper motor ?
Wouldn't take much electronics wise to make the controls for it, then you wouldn't have to worry about the hassel of brushes.

05-25-2005, 08:36 PM
One semester of Basic DC at your local community college would do wonders.
Interactives said...
ˇIf I could go back to school it would be electronics instead of art school. If only I could turn back the hands of time.

トヨタは すばらし です!!

Gary D.
05-26-2005, 05:08 AM
Sounds like you would have been a "Shoe In" if you studied Electronics. Its never to late to learn.

There are 10 kinds of people....

Those who know binary and those who Don't.