Professional Documents
Culture Documents
Optical Encoder For Motor Control Tutorial
Optical Encoder For Motor Control Tutorial
January 2013
Undergraduate Program
Instructor: Chaiyaporn Silawatchananai, Matthew N. Dailey
Optical Encoders
An optical encoder is a sensor that is used to monitor the direction of rotation, position or velocity of a
rotary or linear operating mechanism. This device typically consists of four elements: a light source, a light
sensor, an optical disc and signal conditioning circuitry.
The light source is usually a light-emitted diode (LED) that transmits infrared light. The light sensor is
a phototransistor that is more sensitive to infrared energy than to visible light. The optical disc is connected
to the shaft being measured so that they rotate together. Usually, the disc is made of plastic, glass or metal.
It has opaque and translucent regions. The disc is placed between the light source and sensor as shown
in Figure 1. Optical encoders are classified as either incremental or absolute. This tutorial will focus on
incremental encoder.
Component required
1. Arduino UNO R3
2. Breadboard
3. Resistor (330ohm) and (10kohm)
4. Reflective Optical Sensor TCRT50001
5. DC Motor
6. Digital Oscilloscope
7. DC power supply
val;
encoder0PinA = 2;
encoder0PinB = 4;
encoder0Pos = 0;
encoder0PinALast = LOW;
n = LOW;
void setup() {
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
Serial.begin (9600);
}
void loop() {
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}
Serial.print (encoder0Pos);
Serial.print ("/");
}
encoder0PinALast = n;
}
Description
References
http://thedenneys.org/pub/robot/encoders/.
http://www.societyofrobots.com/sensors_encoder.shtml
http://playground.arduino.cc/Main/RotaryEncoders
http://www.robotshop.com/ca/PDF/vishay-TCRT5000L-infrared-reflector-specs.pdf
Industrial Control Electronics: Devices, Systems & Application by - Terry Bartelt.