HOME > > SENSING AND CONTROL MAIN PAGE > > SENSORS    

Sensing and Control for hobbyists and schools: Shaft Encoders

If you have a weather vane, you will need a shaft encoder. Shaft encoders tell you how far around a shaft has been turned. In practice, other techniques are normally used for volume controls, but they could also be "read" using a shaft encoder. Further down this page, I will also discuss measuring the speed of a shaft's rotation.

One approach.. not a very good one, on several counts,... but you may encounter it, is to stick the shaft to a potentiometer. Turning the shaft turns the potentiometer, so the resistance it is showing implies the position of the shaft, i.e. how far from "home" it has been rotated.

The note on optoisolators (optocouplers) which used, (for no logical reason!), to be on this page have been moved.

Measuring Position

One of two good approaches, well suited to weather vanes:

Attach two transparent discs to the shaft, at right angles to it. Divide one into two halves, the other into four quarters. Paint half of the 2 part disc black, and alternate quarters of the other. Mount a slotted opto detector to look at each disc. Call the detectors "A" and "B". (A slotted opto detector consists of two small posts. On one you have an LED shining light towards the light detector mounted on the other.)

With the above, as you rotate the shaft, at one point both detectors will find the gap between the posts blocked; at another A is blocked, B isn't; at another B is blocked and A isn't; the last possibility is that both detectors find nothing blocking the light. With two discs the rotation of the shaft can be resolved to 90 degrees.

If you add another disc, you can double the resolution. If you do decide on three (or more) disc system, be sure to learn about "Gray codes". By using them, you design problems out of your device. Only one bit changes between any two positions of the shaft. If this is not the case, false readings can arise as one bit changes slightly before a different one changes. (To incorporate what I assume was something discovered by a Mr. Gray only requires that you place the opaque sectors in a pattern that might not have occurred to you.) Use Google to search on "gray code" tutorial and you can find out more. I liked yagni.com/graycode/

For a four disc encoder, the Gray code numbers are: 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000

A variation on the above:

If you want to avoid the hassle of the discs and using slotted opto detectors, and you can find some satisfactory reflective detectors, you can use a different geometry the same way. A reflective detector is like the slotted detector, but instead of shining the light across a gap, it shines out from the device. If something shiny is in front of the detector, the light is bounced back to the sensor, and the thing is "seen".

First, you somehow increase the diameter of part of the shaft to about 2cm. It also needs to be sufficiently shiny that the reflective detectors will "see" the shaft. This section needs to be as high as three of your detectors if you want to resolve the shaft position to 45 degrees.

Instead of sectors of the discs being made opaque, you merely make similar portions of the shaft non-reflective.

I have woefully short-changed gray code schemes here. They are very cool, and very useful. I'd know those things for years... but it was only 11/21 that I discovered that you can have a six (or less, or more) bit gray code in a SINGLE BAND of "ons" and "offs"! You'll need six detectors, but that's the same as you would need if the bands of ons and offs were "spread", one band per bit.

It is almost more than I can get my head around, but just for the beauty in "arcane-ness" of it, I heartily commend "HolyBaf"'s Absolute Position Encoder With Single Track Gray Code Instructable to you!

What you need is there. I'm afraid I have to add that when I tried to download the .pdf 11/21 very nasty strange things happened. Be sure you have a good anti-malware suite in place and up to date if you try to download the .pdf. (Let me know how you get on, if you do? Contact details below, and please mention this page's URI if you write... (SheSof/)sc2se.htm


===
Another approach... not well suited to weather vanes, but the basis of most ball mice, and many volume controls. A good way to interface a rotary control which will be used to tell your system to turn something up or down.

If you are not so much interested in the absolute position of a shaft, but you are interested in picking up and measuring rotation forwards or backwards, you can get high resolution quite easily from the following approach. You can get the mechanical elements by cannibalizing an old ball-type mouse.

The basic idea is quite simple: You attach to the shaft one disc, similar to the ones used in the previous approach to shaft encoding. However, this disc has many bands of clear and opaque material.

You fit not one, but two slotted detectors to "watch" the turning of the disc. Each transition from transparent to opaque implies a slight turn.

The clever thing about using two detectors is that you can tell which way the disc is turning by looking to see which "sees" the transition from clear to transparent first. When the disc rotates clockwise, it will be one, and when counterclockwise, the other. I'm sure Google can find you good descriptions of this with illustrations.

===
And novel approach...

The version 3 Dallas/ AAG wind direction sensor implements an extraordinarily clever way to encode the shaft's position, as I'll outline in a moment. Just before I do, let me mention that earlier versions of the device were much less clever. The shaft had a magnet. There were 8 reed switches. The Version 3 device uses the same magnet and reed switches. However, the early devices were blunt instruments. The system relied on 8 separate chips which were switched on or off by the magnet. One bit of "cleverness" was there, and is still part of the system: When the magnet is half-way between two reed switches, they are both switched on, so 8 switches can resolve 16 positions.

The Version 3 system relies on 4 voltage measuring devices (ADCs) to sense the state of the 8 reed switches. No two adjacent reed switches are on the same ADC. When no magnet is near one of the switches, the ADC it is connected to "sees" 5 volts. When a magnet is near one of the switches, the ADC "sees" either 0 volts or about 2.5 volts. This is how each ADC can "watch" two switches.

Not "important", but maybe interesting: If you think about it, you will notice that this system is using a base 3 number system rather than the common base 2 (binary) system which has made such a difference to what we can do easily, reliably.

Measuring Rotation Speed

.

You can use opto detectors, just as you did in detecting the shaft's degree of rotation.

A better bet is probably to mount a magnet on the shaft and put a reed switch nearby, such that the switch opens and closes once for each time the shaft rotates.

In place of the reed switch, you might use a semiconductor equivalent called a Hall effect switch.

Once you have a turning-shaft-operated switch in place, you merely count switch openings or closings to determine rotation speed. You could, of course, build a system that relied on the computer to look at the state of the switch. This proves to be messy in practice. Under that scenario, you have two choices: You can time how long it is between one opening and the next, or you can count the number of openings in some constant time interval, e.g. openings per second.

A little more work with your soldering iron will more than repay you. You will be able to relieve the computer of a great deal of processing work.

The extra electronics is a "counter". One side is connected to your reed switch, the other is connected to the computer. Inside the counter is electronics that keep track of how many times the switch has been operated, and make that number (count) available on request to the computer. No longer does the computer have to "watch" the switch continuously, for fear of "missing" an opening. I have written a separate page about counters for you.


A company called Posital had and interesting illustration on the following page available at 7/10. It was more interesting back in 2005, if I remember rightly, but is now a pop-up, and "slick" and "glossy". You want message? No, no- medium is the thing these days, isn't it? The link I've given is deep, the company's main page if the previous link doesn't work.

A related matter

If you are making a wind speed or wind direction sensor, or another device which will be a long way from it's monitoring computer, a suggestion:

Between the reed switches, Hall effect devices or opto detectors "looking at" your shaft and the computer, there will be long wires. At the end of the wire near the computer, add an opto-isolator. Most voltage spikes which arise in the long wires will be kept out of your (presumably expensive!) computer.

Optoisolators are simple little devices. They consist of an LED and a photo transistor, embedded within a bit of plastic. They are not "connected", but when the LED is on, the phototransistor conducts.

I've explained them in detail on my "How to use opto-isolators" page.


Click this to search this site without using forms, or just use......
powered by FreeFind
Site search Web search
The search engine merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

Please also note that I have two other sites, and that this search will not include them. They have their own search buttons.
My site at Arunet.



Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? At least (please) send an 'I liked the parallel port use page, and I'm from (country/ state)' email? (No... I don't do spam) Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Other projects....

This is just one of the guides I have published on the net. Please visit any of the following that relate to interests you have....

Delphi Tutorials
Pascal programming tutorials
Electronics for hobbyists and schools
Main Home Page


You can email this page's editor, Tom Boyd. Click here for details.

-- Page ends --