DaddyOh's Blog

Making, Cooking, Living

Measuring DC Motor Speed Using a Optointerrupter

| Comments

Recently I deconstructed an old HP Office All In One printer. In the process I scavanged 3 devices that look like this:

HP Branded Opto Device

Scavenged Opto Device

I’ve seen these before when deconstructing printers and assumed they were some sort of optointerrupter devices. After some research online and I found a device at Digi-Key that looks similar. The photo of the OPTO SENSOR 5MM DARK-ON TRANS looks similar and the scavanged device acts like the name in the sense that the sensor turns on the logic output when the light can’t get to the sensor (e.g., dark).

These devices work by having a infrared LED on one end of the slot and a phototransistor at the other end. There are transistor like devices in the catalogs and there are logic devices as well. Since the current flows when the light is blocked I assumed this was a logic based device and not just a raw optotransistor for the sensor. I am not sure if this is correct, but it doesn’t matter since I was able to get it to work.

I played with the device a little and decided I could build something that could measure the reveloutions per minutes (RPM) of some of my hobby DC motors.

The schematic of how I wired this up is shown below. Since I don’t know the actual device in use, the schematic of the actual optointeruppter should be asumed to be wrong, but close enough.

Schematic

Schematic

I assembled a small jig using Actobotics™ parts from ServoCity and attached a 12-24V hobby motor to the jig. I cut a 70mm disk out of some stiff paper and attached it to the small gear on the motor shaft. The opto device was glued to a piece of hook and loop material that the other half was also glued to the jig.

Front of Jig – Notice Slot In Disk

Front of Jig

The Top of the Jig

Jig Top

I’ve been playing with a ARM based mbed processor lately and figured this would be a great project to try with my NXP LPC1768 (Cortex-M3) mbed microcontroller and mbed application board.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* 
 With a disk that is solid color and a open (transparent slot) in the disk:
 the opto transistor acts like a closed switch when the disk is solid 
 (no light passes).  Therefore we want to count each time the transistor acts
 like it is open.

 License: Apache License, Version 2.0
 http://www.apache.org/licenses/LICENSE-2.0.html
 Copyright: Eric F Palmer, 2014
 Email: eric [at] ericfpalmer [dot] [com]

 */

#include "mbed.h"
#include "C12832_lcd.h"
C12832_LCD lcd; //Graphics LCD

DigitalOut myled1(LED1);
InterruptIn opto(p18);
int startTime;
int endTime;
float delta;
volatile int (ct);
Timer t;

void ISR1()
{
    ++ct;
}

int main()
{
    lcd.cls();
    lcd.locate(0,0);
    lcd.printf("Start");
    wait(1.0);
    ct = 0;
    t.start();
    startTime = t.read_ms();
    opto.fall(&ISR1);
    while(1) {
        endTime = t.read_ms();
        # collect counts for 5 seconds
        if (endTime - startTime > 5000) {
            delta = (endTime - startTime)*1.0;
            lcd.locate(0,0);
            lcd.printf("ct:%i d:%i    \r\n",ct, (int)(delta));
            lcd.printf("RPM %i       ", (int)((ct * 1000.0 / delta)*60.0));
            startTime = t.read_ms();
            ct = 0;
        }
    }
}

You can see the results on the OLED display shown below. With the hobby motor I was able to get the motor to slow down to ~203 RPM at 2.5 volts before it stalled and up to ~3500 RPM at 27.8 Volts.

I’m very happy with how this worked out. I was hopeful to get some sort of measurement but did not know how responsive the actual opto device was going to be. In a word this was “fantastic”.

OLED Display on the mbed Application Board

Display

Scope Trace at ~203 RPM

Scope

I was really hopefuly that the rise and fall times for the opto device were fast enough that I could measure 3500 RPM. You can see from the trace below that at 3500 RPM the device has a fall time of about 45us and a rise time of 320us. So lets assume the total dip time (fall + transparent slot time + rise) is about ~500us at this speed. If this holds up (and the slot time will go down) then this device should be able to measure a motor speed of more than 1000Hz or 1000 Cycles / Sec * 60 Sec/Min or 60,000 RPM. I don’t think I have any motors faster than maybe 5000 RPM. It would cool to test something in the 10,000 RPM to 20,000 RPM range.

Scope Trace at ~3467 RPM

Scope

All in all I’m pretty excited by these results. I hope to code up an Ardunio version and test that soon. I will post the results here for those of you that want to do this with an Arduino.

Now Go Make Something!

Comments