Simple Sensors To Calculate RPM

Ever wonder how to calculate revolutions per minute using a microcontroller? This project shows you how by purposing an IR emitter and detector and a computer fan. As the fan blades spin they disrupt the beam of infrared light between the emitter and the receiver. This results in a waveform on the receiver’s circuit which can be easily used to trigger interrupts in any microcontroller. In this case a PIC 18F452 monitors the detector’s signals for a rising edge. By measuring time data between interrupts the period can be established and RPM calculated. You can see a video of the test rig after the break.

So what can you use this for? It’s the method that most spinning POV displays use to stabilize the display. You won’t be limited to an IR sensor, but can use a hall effect sensor in the same basic fashion.

I am a UC Berkeley mechanical engineering student. We have a senior class on measurement and data distributions in which we have a final project that is exactly this. When I saw this post, I thought it might be from one of my classmates, but alas, it’s not.

@JC — Yeah, there would be some aliasing at some point in time, depending upon how fast the CPU is being clocked and the code running upon it. However, if it was necessary, it would be possible to detect the aliasing and adjust the output as necessary, although it won’t really be acurate (I mean, it’s aliasing…). A second sensor at a different rate might help in that scenario as well.

If the motor was turning too fast for the processor to monitor on the fly, I would simply attach a pin change interrupt to the IR sensor and just have a counter being incremented every time an edge is detected.

I would then have a timer generating an interrupt every few hundred milli seconds (or whatever) and in that interrupt calculate how many edges have occurred during that time period.

This would definitely be the way forward if you are multitasking as it uses minimal CPU time during the interrupt service routine.

Yes, Aaron. An IR emitter is perfectly seen by an IR sensor at night. Even beter than in the day because daylihgt contains a lot IR “noise”. You could mount the snsor and emitter next to each other and attach a small piece of white paper to the wheel. Tha way you won’t have a wave-form, but clear peaks in the signal.

@ smoker_dave: That method is very nice, but might be less precise because only whole edges can be passed. Calculating the RPM every time the interrupt occurs would be more accurate, but somewhat time-comsuming. The way I would choose would be to calculate the microseconds between every edge. That way you can know a more exact speed. Maybe something in between the methods would be the best for all.

@JC-
No, not dissing. PLC’s are wonderful as they are industrial machines that basically have their own operating system to run customized code. Its basically an industrial arduino that runs ladder logic instead of code. No biggy, I’ve worked on PLC’s, I’ve worked on micros. Each have their own purpose

@Aaron I would check first if IR light doesn’t bother the hamster, perhaps check with a TV remote and see how does it behave. Most rodents have night vision, so I don’t know if having an IR sensor pointing at them may disrupt their habits.