
Arduino Components
- Encoders
Wiring And Basic Tutorial for Mobiflight & Prosim using Ardunio Mega
Rotary encoders are the devices that convert rotary shaft motion to a digital output. They have no limits and allow repeated turning both clockwise and anti-clockwise. The simple units usually have 5 pins. Two of those are grounds, two for left and right and a final pin for the switch.
KY-040 encoders have a PCB attached to the encoder which have dedicated de-bounce hardware. But these require a 5V power supply.
Again, these components are used all over the Sim.
wire colour
Actual aircraft wire is predominately white. Red and Blue are also used.
I like to use different colours for different devices.
Here, in these examples. I have used blue for switches, Black for ground.
Red for +5V, yellow for LED's and grey for Servo's etc.
wire colour
Actual aircraft wire is predominately white. Red and Blue are also used.
I like to use different colours for different devices.
Here, in these examples. I have used blue for switches, Black for ground.
Red for +5V, yellow for LED's and grey for Servo's etc.
wire colour
Actual aircraft wire is predominately white. Red and Blue are also used.
I like to use different colours for different devices.
Here, in these examples. I have used blue for switches, Black for ground.
Red for +5V, yellow for LED's and grey for Servo's etc.
Encoders - KY-040

I started with KY-040 boards. They contain a de-bounce circuit which helps the Arduino provide concise measurement and prevent spurious readings.
The amount of detents vary between different suppliers, but are very easy to count.
Mounting these units can be achieved by either the locking nut on the center shaft or by mounting via the two screw holes in the PCB.
Encoders - Single

I have now moved away from the KY-040 boards, this is due because of the extra wiring required. You can also buy much better encoders that have a completly differnt feel. I like ones that are smooth and have a bit of friction.
These standard single component encoders only require 3 wires to operate them, 4 if you add the internal switch.
This removes the requirement for additional power supply to the unit. The de-bounce is done by the software in MobiFlight.
These components have a smaller footprint and can be easily fitted in most panels without having to worry about the PCB of the KY-040 Interfering with other components.
One side of the encoder has 3 pins: Left/GND/Right
The other side of the encoder has 2 pins: GND/SW
Encoders - KY-040 WIRING

In this example, the pictures show a KY-040 encoder with PCB. This is simple to wire up with 4 or 5 wires depending on if you need the push switch connected. In these pictures i have missed the switch/button out.
Ky-040 boards differ from single component encoders by requiring a 5v power supply. This can be achieved using an external power supply or by using the 5v out line of the Arduino as shown.
If an external power supply is used, you must connect the grounds together.


Encoders - Single Component Wiring

The single encoder can be used with out the debounce circuitry. Mobiflight is ever evolving and has the ability to be able to connect encoders directly.
This time 3 or 4 wires are required depending if the switch/button is required. The ground must also be daisy chained across to the other side.


Encoders - Multiple Devices

To add mutliple KY-040's, you must daisy chain the power (5v) and the GND. All the other lines/pins require dedicated pin allotment on the Arduino.
To add multiple encoders (single units) together, only the ground need to be
Daisy Chained Grounds
There are only 3 or 4 grounds on the Arduino Mega to connect all your devices too.
Sometimes its easier to connect all the grounds in daisy chain configuration. Linking devices to one and another using a single ground back the Arduino Mega.
Another way would be to used a break out board with a common ground connected line.
But by daisy chaining grounds, the wiring loom can reduced drastically.


To add multiple encoders (single units) together, only the ground need to be daisy chained. If you use the switch, you must also daisy chain the ground over to the other side of the switch as shown below.
All other pins from the encoders will need there own dedicated pins on the Ardunio.


