Homemade wheel encoder

Basically I just printed out one of these (laser printer recommended):…And attached it to a wheel (double sided tape recommended). Then I hooked up one of these (a 2$ IR sensor: QRB1134):…And attached it to the motor pointing towards the wheel. I’ve been testing it a bit with a few lines of Ardu


This is a companion discussion topic for the original entry at https://community.robotshop.com/blog/show/homemade-wheel-encoder

Looks great, now your robot
Looks great, now your robot is getting ready for closed loop speed control and mapping!

post code and a schematic on
post code and a schematic on how you hooked it up please :slight_smile:

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

It is an encoder. It counts
It is an encoder. It counts every time it transitions from black to white and white to black. If you know that you have 16 transitions and your wheel has a 6 inch circumference then you know that every 16 encoder ticks you drove 6 inches. VERY useful if you want your robot to map a room or drive a certain distance.

Done
Just posted schematic and code used :wink:

Ya bet ya
Step by step my ideas are becoming reality :slight_smile:

Looks good but when you
Looks good but when you reset clicks to 1 you are outputting the clicks variable when you want turns. Minor thing to fix and really only affects debugging :wink: Good job I will use this when I make my XMOS and Arduino tutorials using encoders to give me a leg up on doing the code.

D’OH!
Sorry! It’s because I changed the variable names from counter1 and counter2 into something more descriptive just before I posted the code. It has been corrected…

I understand

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 :slight_smile:

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

Oh and…

You may wanna use interrupts for this sorta thing. I looked into it and found out that this can only be done with pin 2 and 3. Unfortunately my homemade motor shield allready uses pin 3 for motor PWM, so I thought I would try it this way to avoid resoldering my motor shield…

Just thought I’d let you know :wink:

PS: Very much looking forward to your X-mos tutorial…

It is going to be a while it
It is going to be a while it will be one of the last turorials and the easy ones wont start for a couple weeks. I want to finish my dagu contest bot first

Actually, any pin can be

Actually, any pin can be used as an interrupt – just not using the “attachInterrupt” function. The newer AVRs support “pin-change” interrupts on any pin. You have to end up delving a bit deeper into understanding the AVR architecture, but there’s some sample code in a tutorial I wrote over at TRC: http://forums.trossenrobotics.com/tutorials/how-to-diy-128/an-introduction-to-interrupts-3248/

-Fergs

Need Assistance…
–I understand the schematic above but don’t quite follow how you have this hooked up–<o:p></o:p>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…<o:p></o:p>


////Don’t use this code it is from another web site. I’m using it as an example… <o:p></o:p>Connect analog pin 0 to G via a 0.1uF capacitor<o:p></o:p>Connect the white wire (collector) from the sensor to pin 0, 10K resistor to V<o:p></o:p>Connect the blue wire(emitter) to G<o:p></o:p>Connect the green wire(cathode) to G<o:p></o:p>Connect the orange wire(anode) to V via a 220ohms resistor<o:p></o:p>

///End of example.

<o:p></o:p><o:p>

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.

</o:p>
As you can see this example is using analog. It looks like you are using a mix of analog and digital.<o:p></o:p>I would deeply appreciate it if you could type up something like this as an example so I can use your code example.

<o:p></o:p>Sorry, as I’m quite new to this…<o:p></o:p>

 

Search this site for QRD1114

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

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 :wink:

You don’t risk of burning

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.

With a 12V dc motor @ 100

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

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

sensor’s readings was ~200(on white)

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