Arduino UNO Tutorial Rotary Encoder

Posted on Feb 5, 2014

With a rotary encoder we have two square wave outputs (A and B) which are 90 degrees out of phase with each other. The number of pulses or steps generated per complete turn varies. The Sparkfun Rotary Encoder has 12 steps but others may have more or less. The diagram below shows how the phases A and B relate to each other when the encoder is turned

Arduino UNO Tutorial Rotary Encoder
Click here to download the full size of the above Circuit.

clockwise or counter clockwise. Every time the A signal pulse goes from positive to zero, we read the value of the B pulse. We see that when the encoder is turned clockwise the B pulse is always positive. When the encoder is turned counter-clockwise the B pulse is negative. By testing both outputs with a microcontroller we can determine the direction of turn and by counting the number of A pulses how far it has turned. Indeed, we could go one stage further and count the frequency of the pulses to determine how fast it is being turned. We can see that the rotary encoder has a lot of advantages over a potentiometer. We will now use the rotary encoder in the simplest of applications, we will use it to control the brightness of an led by altering a pwm signal. We will use the easiest method to read the encoder, that is the use of a timer interrupt to check on the values. We will use the sparkfun encoder as discussed above. The first thing is to determine how fast we need our timer to operate. If you imagine that at best we could turn the encoder through 180 degrees in 1/10th of a second, that would give us 6 pulses in 1/10th second or 60 pulse per second. In reality its never likely to be this fast. As we need to detect both high and low values this gives us a minimum frequency of 120Hz. Lets go for 200Hz just to be sure. (Note: as these units are mechanical switches, there is the possibility of switch bounce. Using a fairly...

Leave Comment

characters left:

New Circuits



Popular Circuits

Simulated inductor
Off-line flyback regulator
Safety flare
Audio Amplifer Circuit 230W With MOSFET IRFP2409240
5 zone alarm circuit
masthead preamp
simple tv audio video transmitter
Variable on-off times circuit using two 555 timers
CM8870 CMOS Integrated DTMF Receiver
1999 S10 2.2L Fuse Box Quesion. There are two (what appear
Marty I have a 1991 350SDL that has the center vent not
Single-phase torque motor speed control circuit 2