BREAKING NEWS

23 October 2015

Optical encoder with arduino

Now a days, optical role encoders/rotary encoders are widely used even in hobby robotics. commonplace programs of position encoders are:


  • DC motor function / velocity manipulate
  • Servo-mechanism position / speed manage
  • computer printer
  • Numerically managed machinery
  • RPM sensors in robotics

Photo-Interrupter

the front end of an everyday optical function encoder, used for those responsibilities, is a slotted picture Interrupter /Opto-Interrupter module with an IR LED & a image Transistor/Diode set up dealing with each different enclosed in plastic frame. whilst light emitted via the IR LED is blocked due to the alternating slots of the encoder disc (additionally referred to as index disc), conduction degree of the photo transistor/diode changes. this alteration can be detected through a discrete hardware or by a microcontroller. In quick, a photo-interrupter is composed of an infrared emitter on one facet and an infrared detector on the other via emitting a beam of infrared mild from one facet to the opposite, the photo-interrupter can come across when an object passes between them, breaking the beam.


Encoder/Index Disc

As we need to create pulses, an encoder disc/index disc is very necessary here. An easy way to make it is with a thin transparent acrylic, thin transparent adhesive transparency sheet and a laser printer. Take a drawing software and draw the black stripes as shown in the picture. Print it to the transparency sheet and fix it on the round-shaped thin transparent acrylic. As an alternative, you can make the disc from black acrylic and cut out the white spaces.

An vital be aware: physical width of stripes and areas is a maximum vital component. have a look at the datasheet of the picture-interrupter to find its slit width. it is higher to set minimal witdh of the stripes (and additionally of the spaces) two instances (x2) the slit width of the photograph-interrupter. for example, if the slit width is 1mm, the width of the stripes and spaces have to be 2 mm. If the RPM of the disc is 60, then we've 1 disc flip/2nd. If the disc has 36 stripes then the heart beat frequency is 36Hz, which can effortlessly be dealt with by using the image-interrupter.

The Hardware


To get started, just create a small test circuit as shown here with a photo- interrupter and an Arduino. This allows you to experiment and make sure all things works as per your expectation. The 10K resistor (R2) is a pull-up resistor. Value of the first resistor (R1) depends on the photo-interrupter you use. In this set-up, the onboard LED (at D13) of the Arduino board is usually in off mode, and when the beam broken the LED goes on. Auxillary output available from D12 of the Arduino can be used to monitor the encoded signal on an oscilloscope, for example.






Test Procedure

Bring the photo-interrupter connected with the hardware to your encoder disc and do the test. Connect the D12 output to an oscilloscope and run your encoder disc by hand, or by using a low rpm dc motor. If you don’t have an oscilloscope, watch the onboard LED (D13) to note the pulse output. In this case, try to turn the disc slowly by hand to see the pulse activity directly.



This is the very basic code you need. We have the hardware and the basic software up and running. Now you can upgrade it to whatever you want it to do.



Improving The Code
There are two basic ways to read a microcontroller’s digital input; Polling, and Interrupt. With polling, the system reads the input all the time inside a loop (as used in this sketch). Main drawback of this polling method is that it is difficult to do other things while polling. The controller does the only job of reading the input and processing the data. But, when using interrupts the system can do any other job without any mishaps. When an input pulse arrives, the system stops it’s job, jumps to the interrupt routine and then returns to the job before. So, working with interrupts is what better when its comes to this type of encoding tasks. In a forthcoming article you can see many more about this idea!







Share this:

Post a Comment

 
Back To Top
Distributed By Blogger Templates | Designed By OddThemes