Pages

Monday, September 9, 2013

This is the third tutorial in our 37 in 1 Sensor Kit series. Normal volume controls and potentiometers have stops at each end of the scale. A rotary encoder is a bit different. There are no stops, it's continuous 360 degree motion, and sends a signal to the controller for each "step" (you can feel the notches or detents). This works well for dialing in a temperature, speed, volume, or even making menu choices. This sketch will output a digit for each stop, so you only need to make that digit value (2,3,4, etc) equal something in your sketch. For instance, set 140 on the encoder to keep a water heater at the correct temperature, or dial in 3600 to set a motor speed. Pushing down on the shaft is a reset button that resets the encoder value to zero. Rotating the shaft clockwise increments the index by one per step, rotating counter clockwise decrements the index. There are 20 steps in one full revolution, and this sketch can count over 65000 steps before starting from zero again. Because this sketch uses interrupts instead of a loop, it responds quickly and there's no missed pulses.