Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine.

Magnetic Rotary Shaft Encoder

This project, a magnetic rotary shaft encoder from 1981, shows how to use two hall effect sensors plus a magnet to create an accurate continuously rotating switch that can be used for many purposes, the most obvious being to replace the audio potentiometer with this "noise-free" magnetically encoded switch.

This replaces the traditional "potentiometer" design in an audio volume control system and also replaces the traditional "opto encoder" you would come up with for rotary endcoding of a potentioneter control when designing for high end audio systems i.e. a system where you do not want any noise caused by "real" potentiomter degradation.

This system as with an optical encoder is totally noise free and instead of optics and a hole patterened encoding plate it uses two hall effect sensors and a magnet which results in a very elegant design.

Executive Summary of the Magnetic Rotary Shaft Encoder

A manually-operated rotary switch apparatus utilizes a rotatable magnet for establishing the dual-polarity outputs of each of a pair of magnetic field sensors, oriented substantially perpendicular to each other. The dual-polarity voltages are processed to approximate the arc tangent of the angle of the knob-rotatable magnetic member, with respect to a reference orientation, to provide digital data output related to the switch position of the manually-rotatable knob.

Background of the Magnetic Rotary Shaft Encoder

The present design relates to rotary switch apparatus and, more particularly, to a novel solid-state rotary switch utilizing sensing of the perpendicular field components of a rotatable magnetic member.

Mechanical rotary switches are well-known. Typical multi-position rotary switches of the unsealed type are easily contaminated. Contamination may be avoided, and reliability significantly improved, if the mechanical rotary switch is of a totally sealed construction. However, such totally-sealed mechanical rotary switches are typically both bulky and expensive.

Either type of mechanical-contact rotary switch also requires many assembly operations, as multiple metal, plastic and/or ceramic parts are required for the construction thereof. The labor content and/or number of different machine-assembly operations is therefore quite high.

Optically-encoded rotary switches have been built to overcome some of the disadvantages of the mechanical-contact rotary switch, but also require a relatively large number of parts, including several pairs of individual light-emitting diode sources and photosensor detectors. The several parts of an optoelectronics rotary switch require careful assembly alignment for proper operation of the encoding switch unit.

It is therefore highly desirable to provide a rotary switch which is not only of low cost, but also of high reliability. It is desirable that the number of moving parts be reduced to a bare minimum and that automatic construction, including component insertion techniques already in existence, be utilizable to minimize switch assembly cost.


Summary of the Magnetic Rotary Shaft Encoder

In accordance with the design, a solid-state rotary switch utilizes a magnetic member contained in a rotatable knob, with the magnet mounted above a pair of magnetic field sensors having the sensor axes established substantially perpendicular to each other. The sensors provide a pair of output voltages of magnitude related to the arc tangent of the angle formed by the magnetic member axis, with respect to a reference line.

The substantially-perpendicular-field-component voltages are converted into a digital signal indicative of that one of a plurality of positions of the magnetic member, with respect to the reference position, to provide digital switch position output data.

In one presently preferred embodiment, an array of comparators and exclusive-OR gates are utilized with a diode matrix to provide binary-coded position data, typically resolving the magnetic member to one of 16 preselected rotational positions.

Accordingly, it is an object of the present design to provide a novel solid-state rotary switch apparatus having a single moving part.

This and other objects of the present design will become apparent upon consideration of the following detailed description when read in conjunction with the drawings.

Description of the Magnetic Rotary Shaft Encoder

Referring now to FIGS. 1 and 1a, my novel solid-state rotary switch apparatus 10 utilizes a magnetic member 11, such as an elongated bar permanent magnet and the like, positioned above a pair of magnetic field sensing means 12a and 12b having their respective magnetic field-sensing axes 12a' and 12b' aligned in substantially perpendicular directions to one another.

Illustratively, sensors 12a and 12b are Hall-effect sensors, each having a pair of terminals 12a-1, 12a-2 and 12b-1, 12b-2 for allowing flow of an excitation current I therethrough, and having an additional pair of terminals 12a-3, 12a-4 and 12b-3, 12b-4, across which appear a voltage proportional to the strength of the magnetic field, of member 11, along the magnetic-sensing-axis of the particular sensor, multiplied by the sensor excitation current I.

The same excitation current is caused to flow through both sensors 12a and 12b, from a current source 14, connected to a source of operating potential Vs. Since the same excitation current is utilized in both Hall-effect sensors, and as the sensors are relatively small and placed close together relative to the impinging magnetic field, the angle θ of the magnetic member 10, relative to a reference line, herein the horizontal H axis, is very closely approximated by the arc tangent of the vertical signal magnitude Vv (appearing between sensor output leads 12 b-3 and 12b-4) divided by the horizontal sensor output voltage magnitude Vh (appearing between horizontal sensor output terminals 12a-3 and 12a-4).

Thus, the switch position angle θ may be found by dividing the vertical signal magnitude by the horizontal signal magnitude and processing the quotient to obtain the arc tangent thereof.

One presently preferred embodiment for converting the magnitude of the analog horizontal and vertical sensor output voltage magnitudes Vh and Vv to digital position indication data utilizes a differential-input, differential-output dual-polarity operational amplifier circuit 16a or 16b, to respectively scale each of the horizontal and vertical sensor output voltages.

Each of the two differential inputs of each amplifier 16 is connected to an associated one of the two outputs of the associated sensor, e.g. the horizontal field voltage amplifier 16a has one input connected to horizontal sensor output 12a-3 and the other input connected to horizontal sensor 12a-4, while vertical sensor voltage amplifier 16b has one input connected to vertical sensor output lead 12b-3 and the other input connected to vertical sensor output 12b-4.

Figure 1a : Is a schematic diagram of a dual-polarity differential input/output amplifier for use in the apparatus of fig. 1; and for the magnetic rotary shaft encoder

Each of amplifiers 16 may be configured as shown in FIG. 1a, wherein a first operational amplifier 18 (such as the standard 741 integrated circuit operational amplifier) has the non-inverting input thereof connected to one input terminal 20a, and the inverting input thereof connected through a first resistance element R1 to a second input terminal 20b.

A feedback resistance R2 is connected between the first operational amplifier input and output, and is of a magnitude selected to obtain, in conjunction with the magnitude of resistance R1, the gain AH or AV of the particular amplifier 16a or 16b.

The first operational amplifier 18 output is connected to a first output terminal 22a of the amplifier 16. The first operational amplifier output is also connected through a resistance element 24 to the inverting input of another operational amplifier 26. A resistance element 28 is connected between the non-inverting input of amplifier 26 and ground potential.

A feedback resistance element 30 is connected between the inverting input and output of amplifier 26 (which may also be of the 741 type). The output of amplifier 26 is connected to a second amplifier circuit output terminal 22b. With both operational amplifiers connected to sources of operating potential of substantially equal amplitudes and opposite polarity (.+-.Vo) and with the resistance magnitude R3 of each of resistances 24, 28 and 30 being equal to the parallel-equivalent resistance of resistance element R2 in parallel with resistance element R1, and with the magnitude of resistance elements R2 and R1 being selected to achieve a desired amplifier gain A, the output voltages at each of output terminals 22a and 22b, with respect to a common ground terminal 32, will be of opposite polarity and of magnitude AV1, where V1 is the input voltage between input terminals 20a and 20b.

Thus, the amplified horizontal sensor output voltage appears between horizontal terminals 16a-1 and 16a-2, with positive polarity and magnitude VH (=AH .times.Vh) and with positive polarity at terminal 16a-1 and negative polarity at terminal 16a-2. Similarly, the amplified vertical sensor output voltage appears with magnitude VV (=AV .times.Vv) and with positive polarity at terminal 16b-1 and negative polarity at terminal 16b-2.

Connected between terminals 16a-1 and 16a-2, and between terminals 16b-1 and 16b-2, is one of a pair of series-connected resistance element chains 32a or 32b. Each chain is substantially identical and symmetrical, having seven resistance elements; the first, fourth, and seventh elements are of equal value and twice the resistance value of the equally-valued second, third, fifth and sixth resistance elements.

Thus, at junction A (connected to terminal 16a-1) a signal of polarity and magnitude +VH appears. The signal at sequential terminals B, C and D are of positive polarity and decreasing magnitude, e.g. the voltage at point B is +0.6 VH, at point C the voltage is +0.4 VH and at terminal D the voltage is +0.2 VH. Similarly, the voltages at terminals E-H are of negative polarity and of increasing magnitudes of the amplified horizontal sensor voltage, e.g. at terminal E the voltage is -0.2 VH, at terminal F the voltage is -0.4 VH, at terminal G the voltage is -0.6 VH and at terminal H (connected to terminal 16a-2) the voltage is -VH. The voltages at terminals I-P are of similar polarity and magnitude percentage, but are of the amplified vertical voltage VV, as the polarities and percentages of the amplified horizontal voltages at terminals A-H.

Thus, the voltage at terminal I (connected to terminal 16b-1) is +VV while at the voltage at terminal P (connected to terminal 16b-2) is -VV, with the intermediate terminal J-O voltages being respectively equal to +0.6 VV, +0.4 VV, +0.2 VV, -0.2 VV, -0.4 VV and -0.6 VV. It should be understood that the number and magnitude of resistance elements in each of the chains has been selected to provide preselected amplitude signals at terminals A-P for distinguishing 1 of 16 substantially equal angular positions of magnetic member 11; greater or lesser number of resistance elements in each chain, and different relationships of the value of elements in a particular chain, may be utilized in circuitry distinguishing greater or lesser number of angular segments of a circular rotation.

A plurality of comparators 34 are each utilized to discern half of 2π radians of magnetic field rotation, starting at a fixed angle. Thus, in the illustrative 16 switch-position system, 8 comparators, respectively labeled Q, R, S, T, U, X, Y and Z, are utilized.

One input of each comparator receives one of the amplified horizontal sensor analog voltages, from one of terminals A-H, while the other comparator input receives one of the negative-polarity amplified vertical sensor output voltages from associated one of terminals M-P. For example, comparator Q compares -VH to -0.2 VV, by connection of the comparator Q inputs respectively to terminal H and terminal M.

The output of comparator Q is a logic true signal whenever the vertical field magnitude (represented by the magnitude of voltage VV) is more than five times the horizontal field magnitude (as represented by the horizontal voltage VH); the comparator Q output is a logic false signal at any other time.

Thus, the comparator Q output is a logic true signal for a magnetic field angle between 7 π/16 and 23 π/16 in the Cartesian system, and is a logic false signal for all magnetic field angles between 0 and 7 π/16 or between 23 π/16 and 2π.

The connection points, comparison voltages and logic true ranges for each of comparators Q-Z are listed in Table 1.

It will be noted that the state of the logic signal, detecting which half of the circle the magnetic field angle is in, is independent of the excitation current I or the field strength of magnetic member 11. It will also be noted that the output logic true range of data of each comparator changes state at one of the dividing lines between adjacent ones of the 16 possible positions, assuming that the reference line and one of the positions are aligned at an arbitrarily assigned 0° angle reference.

Thus, by selection of the appropriate pair of comparator outputs, that one of the 16 angular rotation positions at which magnetic member 11 is then situated can be obtained.

The conversion of the comparator output signals to a digitally-encoded magnetic member position signal is carried out by means of a plurality of exclusive-OR-gates 36 and a diode matrix 38. In the illustrated example, the 16 possible magnetic member positions may be resolved in an associated four-bit digital output signal.

Therefore, a four-bit-wide digital output bus 40 is utilized, having at least-significant-bit (LSB) bit zero line 40-0, a most-significant-bit (MSB) bit three line 40-3 and intermediate bit 1 and bit 2 lines 40-1 and 40-2. Each of bit output lines 40-0, 40-1 and 40-2 are connected through an associated one of pull-up resistors 42-0, 42-1 and 42-2 to a source of positive-polarity potential (+V) which may be the same operating potential utilized for comparators 44 and gates 36.

The number of comparators 34 is equal to M, where the number of resolvable magnetic member positions p=2 M. Similarly, a total of M exclusive-OR gates 36 may be required. Each of the two-input exclusive-OR gates 1-8 receive two adjacent comparator outputs. Thus, gate 1 receives the Q and Z comparator outputs while gate 2 receives the Z and Y comparator outputs.

Gate 3 receives the X and Y comparator outputs, gate 4 receives the U and X comparator outputs, gate 5 receives the U and T comparator outputs and gate 6 receives the T and S comparator outputs, while gate 7 receives the R and S comparator outputs and gate 8 receives the R and Q outputs. The output of each of gates 36 is connected through appropriate ones of the diodes of array 38, to provide the required four bit encoded output data.

A diode of array 38, when used, has the anode thereof connected to the appropriate one of output lines 40-1 to 40-2 and the cathode connected to the appropriate output of gates 1-8. Thus, in a negative logic system with a logic zero being represented by a bit level of +V and a logic 1 being represented by substantially lesser magnitude voltage, gate 2 provides a high voltage (logic 0) output if the Y and Z comparator outputs are both high, or are both low.

If the Z output is high and the Y output is low (corresponding to an angle between 25 π/16 and 2 π/16) or if the Z output is low and the Y output is high (corresponding to an angle between 9 π/16 and 11 π/16) then gate 2 provides a low output voltage (a logic 1 level).

Similarly, each of the other gate outputs will yield two diametrically-opposed switch position sets of data on lines 40-0, 40-1 and 40-2, as θ traverses through the 16 positions on a circle of rotation. Accordingly, the rotational ambiguity is resolved by connecting the MSB bit 3 line 40-3 to the Q comparator output, which line 40-3 will be at a high (logic 0) state if the angle θ between the magnetic number and the horizontal positive axis is between 7 π/16 radians to the 23 π/16 radians, corresponding to the eight switch setting positions at θ=N π/16, where N equals 8, 10, 12, 14, 16, 18, 20 and 22.

The diodes of matrix 38 establish the 8 positions for each half of the 16 settable positions. It will be noted that the output of gate 1 is not connected to any of the bit zero, 1 or 2 lines 40-0, 40-1 or 40-2, and therefore gate 1 is not absolutely required. Gate 1 is shown for illustration of the symmetry of the decoding logic, and in practical cases, wherein integrated circuitry might be used for providing gates 36, a typical integrated circuit package will contain four exclusive-OR gates, whereby two packages are required to provide the seven necessary gates 2-8, and the eighth gate is available if the use thereof is desired.

The output bit patterns for the 16 settable positions are listed in Table II.

Figure 1 : Is a schematic block diagram of a presently preferred embodiment of the novel solid-state rotary switch apparatus of the present invention for the magnetic rotary shaft encoder

View larger image here.

The 90° offset shown in Table II may be accomodated by subsequent data transformations, or may be accomodated by placing a control knob index 11b at a position rotated 90°, in the proper direction, from axis 11a passing through magnetic number 11 and at the North Pole thereof (see FIG. 1).

Figure 2 : Is a partially-sectioned sideview of a presently preferred physical configuration for the novel solid-state rotary switch apparatus, in accordance with the principles of the present invention for the magnetic rotary shaft encoder

Referring now to FIG. 2, magnetic member 11 may be embedded in an extension portion 50a of a rotary control knob 50, formed of a non-magnetic material, such as plastic and the like. Portion 50a is positioned behind a bushing panel portion 52, while a knob portion 50b is positioned adjacent the opposite surface of panel 52, with a shared portion 52 extending between portions 50a and 50b and passing through an aperture 52a in the panel.

Advantageously, the entire circuitry of FIG. 1 may be integrated onto a single integrated circuit, with the crossed-axes magnetic field sensors 12a and 12b thereof positioned below, and substantially on the axis of rotation 50d of, knob 50. The integrated circuit may be placed in a package 54 of type well-known to the art, with an 8-pin dual-in-line package (DIP) being utilized for the illustrated 16 position switch apparatus.

The integrated circuit package is thus capable of being fabricated in a relatively low cost manner, with a high degree of automation, and can be automatically inserted in a printed circuit board 56 for positioning of the chip below the member 11 axis of rotation, whereby a low-cost and high-reliability solid-state rotary switch apparatus 10' may be provided.

While my present design has been described with respect to a presently preferred embodiment thereof, many modifications and variations will now become apparent to those skilled in the art. It is my intent, therefore, to be limited only by the scope of the appending claim and not by the specific details and instrumentalities described herein.

Click here for more project ideas.

New! Comments

Have your say about what you just read! Leave me a comment in the box below.

Claim Your: Useful

"Arduino Software Guide"

   Right Now...

Jump from the magnetic rotary shaft encoder page to
Best Microcontroller Projects Home Page.

Privacy Policy | Contact | About Me

Site Map | Terms of Use


Visit our Facebook Page:

   Click Here

Recent Articles

  1. Using the MAX6675 or How to easily measure Extreme temperatures

    How to use the MAX6675 and an Arduino to measure temperatures from 0°C to 1024°C with two components: A chip - the MAX6675, and a Sensor: - a type-K thermocouple.

    Read more

  2. How to use the DHT22 (or DHT11) with an Arduino; full code and description. Also including a comparison of the DHT11 vs DHT22.

    The Essential Guide to the DHT22/11 humidity sensor including a library code guide for the Arduino. Learn how to determine Humidity, Dew point and Heat Index.

    Read more

  3. How to Use the MAX7219 to drive an 8x8 LED display Matrix on the Arduino.

    The Essential Guide to the MAX7219; What it is and how you can easily use one in any of your projects.

    Read more

Sign up for MicroZine
''The'' Microcontroller Newsletter

Enter your first Name and primary email address in the form below:

And receive absolutely FREE a full project for:

"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be  Removed 
at any time.  

It will  NOT be 
available indefinitely SO
To avoid 
disappointment  get it:


Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.

To get exclusive access Enter your first name Name and primary email address Now in the form above.:

But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates

Scroll up to the form above and sign up NOW. Don't forget it's FREE and if you don't like it, you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's


- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan


"Awesome site,
very, very easy and nice
to navigate!"

- Matt

Learn Microcontrollers

"Interested in

Sign up for The
Free 7 day guide:


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."

- Dave


"Your site is a great
and perfect work.

- Suresh


"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.

- Anon