0% found this document useful (0 votes)
171 views

Using A Rotary Encoder On The Microbit

A rotary encoder can be used as a volume control or to measure distance travelled. It works by detecting pulses produced when a light beam is broken by slots in a rotating disc. Both the direction and distance of rotation can be measured by detecting which pulse (A or B) occurs first and counting the number of pulses. The micro:bit can be wired up to detect pulses from a rotary encoder and use them to increment or decrement a counter variable depending on the direction of rotation.

Uploaded by

Ted Sun
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views

Using A Rotary Encoder On The Microbit

A rotary encoder can be used as a volume control or to measure distance travelled. It works by detecting pulses produced when a light beam is broken by slots in a rotating disc. Both the direction and distance of rotation can be measured by detecting which pulse (A or B) occurs first and counting the number of pulses. The micro:bit can be wired up to detect pulses from a rotary encoder and use them to increment or decrement a counter variable depending on the direction of rotation.

Uploaded by

Ted Sun
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Enter Data Using a Rotary Knob Device (Rotary Encoder)

Used in Digital Radios


as a Volume Control.
Wire Up the Micro:bit
Used in Robot Vacuum as shown.
Cleaners to measure The Wire’s Colour Isn’t
Distance Travelled. Important.

Both Direction and Distance Travelled can be Measured


using this device:
Distance:
• Count the number of Pulses. 1 Pulse is :

Light passes through the Slots Direction:


in the Disc to produce a Pulse • If Pulse A occurs Before Pulse B or Visa Versa.
as it Breaks the Light Beam.

Turning Clockwise

Turning Anti-Clockwise
Enter Data Using a Rotary Knob Device (Rotary Encoder)
Create Wait Here until
All This the First Edge of
Pulse A occurs.
Code

Initialise the
Micro:bit’s
Pins used and
the variable
Counter.

Detect when Pulse B Occurs to determine If the Knob’s Switch is


which Direction the Knob is Rotating. Pressed then Reset the
variable Counter to 5.

Observe:
• The display only Counts Up or Down Cor-
rectly if the Knob is Rotated Very Slowly.
Reason:
• The Show Number takes a Long Time to
execute, so the Micro:bit may Miss Some
Wait until Pulse A
of the Pulses.
has completed.
Solution:
• Use the Serial Write Number as opposed
to Show Number to display the numbers i.e. Wait for it to
on the PC ‘s Screen instead. go Low Again

You might also like