Connecting the Keyestudios Analog Rotation Sensor to the Microbit

Tinkerer: Lory Livezey

The Keyestudios Analog Rotary Sensor can be used as a dial for any project where you want to vary the level of intensity of light or sound. The sensor will send a value between 0 and 1024 as the dial is turned from the left-most position to the right-most position. In this tutorial, we'll hook the sensor up to the BBC Microbit.

Previous Step

  Keyestudios 37 Sensor Kit with the Microbit

What you will need

(or longer)
(or similar)
(or a monitor/keyboard/mouse plugged directly into the Pi)


Plug the Microbit into the Breakout

Without a breakout board for the Microbit, you can use alligator clips or as they say, crockodile clips over in the UK. I prefer to use a breakout because you have more flexibility when you want to use all the other pins that are available. In this tutorial, i'm using 3 different breakouts to give you an idea of just how similar they are.

Hook Up the Sensor

The sensor is clearly marked, so hookup is fairly straight-forward. If you're using a breakout, you'll need 3 wires -- color doesn't matter, but I'm using black, red and blue.

  • Black to (-)
  • Red to (+)
  • Blue to (S)

Plug the Microbit into the Computer

In some tutorials, i'm plugging the Microbit into a Raspberry Pi. This one, i'm using a Windows PC. I do this for variety so you can see the different methods. Once you plug it in, the Microbit should show up as a drive in Windows Explorer or Finder on the Mac.

Open MakeCode

Open the browser to

Copy/Paste the Code or Build the Blocks

Either copy/paste the following code into the window after selecting Javascript...

basic.forever(() => {

Or build the blocks like so:

Make Code Blocks

Their location:

Basic > Show Icon
LED > More > Set Brightness
Pins > Analog Read Pin 0

Give the sketch a name (or not) and click Download.

Open your Downloads directory and drag the file (it will have a hex extension) over to the drive that was created when you plugged in the Microbit.

On the Rasbperry Pi, it's located here:

Media > Pi > Microbit

Once the Microbit reboots, you should be able to control the brightness of the Heart by turning the Rotary Sensor Dial!

Since other breakout boards will be similar, I demonstrate here how to hook it up to two other breakouts:

  • The Keyestudio Breakout is a simple breakout with a single row of pins. Simply use the same pins as we did before:

  • The Keyestudios Sensor Breakout has a ground and power pin corresponding to each pin. This acts as a sort of breadboard that allows you to run power and ground to several different sensors at once.

You have successfully programmed the Microbit to work with the Analog Rotary Sensor. Subscribe to our channel if you'd like to be notified when we post a subsequent video about how to use it in other projects.

Be sure to subscribe to our channel!