Potentiometer Examples

All examples use a simple 10k potentiometer.

See the component article on this website about the LED.

Dimming LED

Dim and LED based on the reading/rotation of the potentiometer.

Pot always pin 1

Hardware Required

diagram for blinking LED

from microbit import *

pot = pin1
led = pin0

while True:

This should work a lot better than it does.

The LED flickers each time write_analog() is called. Hopefully someone has a solution.

let potReading = 0

basic.forever(() => {
    potReading = pins.analogReadPin(AnalogPin.P1)
    pins.analogWritePin(AnalogPin.P0, potReading)

RGB Colour Mixing

Mix colours based on the reading from three potentiometers.

Hardware Required

colour mixing diagram circuit

from microbit import *

# potentiometer pins
red_pot = pin0
green_pot = pin1
blue_pot = pin2

# led pins
red_led = pin10
green_led = pin3
blue_led = pin4

while True:
    # get colors from pots
    # returned values range from 0 - 1023
    red = red_pot.analog_read()
    green = green_pot.analog_read()
    blue = blue_pot.analog_read()

    # write colours to LEDs

Share On
Facebook Twitter Google Plus

Published: December 23, 2016 Updated: December 23, 2016

Potentiometer Examples

Examples of using a Potentiometer with the microbit.

Jez Dean