Let's Make Robots!

Homemade wheel encoder

Basically I just printed out one of these (laser printer recommended):

encoder_40_s.gif

...And attached it to a wheel (double sided tape recommended).

Then I hooked up one of these (a 2$ IR sensor: QRB1134):

qrb.jpg

...And attached it to the motor pointing towards the wheel.

I've been testing it a bit with a few lines of Arduino code and damnit it works :D I'm now able to measure how much the wheel is rotating and therefore calculate how far a robot is moving. I just love it when these cheap lowtech solutions work.

Here are some photos (sorry about the bad quality):

encoder2_s.jpg

encoder1_s.jpg

 

UPDATE: 

Here is the schematic I used to hook up the QRB1134 sensor:

qrbsetup.jpg

I used a 0.1uF ceramic cap. Don't know if that's what was intended? It does have a + indicating a polarized cap, but I dunno? Man I wish people would write the kind of cap you're supposed to use, but apparently that's obvious to everyone but me :/ If anyone has a suggestion of what to use I'm open?

Here is the Arduino code I used for testing:

#define IOP 14
#define PWM 3

int val_new;
int val_old;
int clicks = 0;
int turns = 0;

void setup() {
    Serial.begin(115200);
    pinMode(IOP, INPUT);
    val_new = digitalRead(IOP);
    val_old = val_new;
}

void loop() {
    analogWrite(PWM, 80);
    val_new = digitalRead(IOP);
   
    if(val_new != val_old) {
        if(clicks == 40) {
            clicks = 1;
            turns++;
            Serial.print("TURNS: ");
            Serial.println(turns);  
        }
        else clicks++;
       
        Serial.print("CLICKS: ");
        Serial.println(clicks);

        val_old = val_new;
    }
}

Basically I just add 1 to the variable click every time the color in front of the sensor changes. When I reach 40 clicks I reset the variable click and add 1 to the variable turns. And off course I'm logging everthing through serial for testing. That's it :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Sorry for replying after ages(last comment in 2010 :p).... but I am a newbie here, juz got here recently! I had also the same problem. Then on googling I found your writing. My sensor's readings was ~200(on white) and ~50(on black). A reading of 200 is almost .978 V. So I thought why not add it to the base of a transistor(2N3904, I used) directly and drive it as NOT gate. And it worked! I was getting a HIGH on black and LOW on black.

P.S.: This is my first post. Still learning how to post and reply to questions. :)

I am an amateur robotics enthusiasts. I wanted to know if a QRD1114 can be used instead of the QRB1134? As i have QRD1114 component available and QRB1134 is not available. What changes do i need to make in the circuit schematics. I intend to make a wheel encoder and progressing a little forward, be able to control the speed of the dc motor using PWM.

I feel weird asking this: How do u decide these values for ur components? Any good links so that i could learn and experiment more (my electronics knowledge sucks!).

With a 12V dc motor @ 100 rpm.. I am unable to distinguish the black and white patches of the wheel. I am using a QRD1114 as the opto-switch. Any suggestions? (one would be to reduce the speed and check, will do that, any other suggestions?)

I suggest you start a separate forum post. Provide pictures, schematics, details of what you have tested, etc. This will help us help you.

Search this site for QRD1114 and you will find several circuits for optical encoders based on these devices. The exact values for the components can be a bit tricky, as I am finding. It is highly dependent on your physical set up. Varying the resistor value on the IR LED will give you more or less IR light to be reflected. Depending on your how the QRD1114 is placed, the ambient light, and other physical factors, you may want more or less IR light.

Check out the pages that have been posted. Play with the reflective and absorbent material for your encoder, keep trying until you get the results you can count on. I'm working on this at the moment myself.

Experimentations would be good if i had a lot of QRD1114s for burning. This components is so scarcely found in india that it took two weeks for me to procure 4 pieces. So i am just worried that i may end up burning all of them before seeing some action.

But i will remember your advice and try to keep it safe and educative ;)

You don't risk of burning them if you always keep a series resistor for the LED and a pull up resistor. The values of these resistors depend greatly on your setup. I would suggest to print a stripped disk then hook wires to the sensor and plug it in a breadboard. then test different values for the series resistor (between 50 ohms and 1k, lower values will make the LED shine brighter) and the pull up resistor (from 4.7k to 15k). What you want is to have a 0...0.8V for a LOW value and over 3.5V for a HIGH value. Start with the standard resistors, measure the voltages, then lower the series resistor little by little until you reach 100 ohms. If the LOW voltage is still high, lower the pull up resistor until you get a good LOW voltage and check the HIGH voltage so it doesn't drop under 3.5V.

--I understand the schematic above but don’t quite follow how you have this hooked up--

I came across another site that had the same schematic as you have listed above. The site also had some instruction like what I have listed below, Please read...

 

////Don't use this code it is from another web site. I'm using it as an example... 

Connect analog pin 0 to G via a 0.1uF capacitor

Connect the white wire (collector) from the sensor to pin 0, 10K resistor to V

Connect the blue wire(emitter) to G

Connect the green wire(cathode) to G

Connect the orange wire(anode) to V via a 220ohms resistor

///End of example.

Looking at the above code he has the white wire on line 0. I believe you have it connected to analog line 3. but what i don't understand is how you are reading digital line 14. 

As you can see this example is using analog. It looks like you are using a mix of analog and digital.

I would deeply appreciate it if you could type up something like this as an example so I can use your code example.

Sorry, as I’m quite new to this…

 

Forgive me my ignorance but could you tell me what this "one of these" things is ?

I understand your confusion. People just call it an "encoder" which is an awful term for it, since everything that transforms information of any kind into another format is an "encoder". The term "wheel encoder" I just invented because I don't know what to call it. It doesn't qualify as a "quadrature encoder" because it has only one IR sensor, and a "rotary encoder" is (to my knowledge) synonimous with "quadrature encoder". So I'm not sure what kind of encoder I just made :)

However it works like jklug80 says: The wheel is divided into 40 steps (in my case) and the IR sensor allows me to detect whenever the wheel has turned another step. I then know that the wheel has turned 360 / 40 = 9 degrees. Asuming that both wheels of the robot are turning with the same speed, and knowing the diameter of the wheel, I can then calculate how far the robots has moved using the geometric formula: c = PI * d (c: the full circle and d: diameter).