Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Servo Position Control with Python and micro:bit

Servo Position Control with Python and micro:bit

Solutions

Questions

  1. Answer: Servos on larger machines are most likely bigger in size, more powerful, and more durable because they are used to drive heavier machines. This would require sturdier and more powerful equipment.
  2. Answer: The servo is connected to supply voltage, ground, and the control signal.
  3. Answer: -10 degrees and 190 degrees
  4. Answer: There is a built-in motion limiter.  

Exercises

  1. Answer: 77
  2. Answer: 128
  3. Answer: pin16.write_analog()
  4. Answer: It sets up the servo signal so the micro:bit is ready to set P16 high and low for portions of the 20 ms period.
  5. Solution:  
tHIGH = value x 20 ms / 1024
          = 77 x 20 ms / 1024   
          ≈ 1.504 ms   
          ( close to 1.5 ms)

Projects

1. Solution:

# servo_bounce_between_1

from microbit import *

pin16.set_analog_period(20)

while True:
    pin16.write_analog(26)      # 0 degrees
    sleep(4000)    
    pin16.write_analog(34)    # 15 degrees  
    sleep(4000)    

 

2. Solution:

from microbit import *

pin16.set_analog_period(20)

print("Enter values in 51 to 102 range...")

while True:
    text = input("Enter value >")
    y = int(text)
    if y < 103 and y > 50:
        pin16.write_analog(y)
        x = (y - 25.6) / 0.5699
        print("servo degrees:", x)

 

3. Solution:

# terminal_controlled_servo_error

from microbit import *

pin16.set_analog_period(20)

print("Enter values in 26 to 128 range...")

while True:
    text = input("Enter value >")
    y = int(text)
    if y < 129 and y > 25:
        pin16.write_analog(y)
        x = (y - 25.6) / 0.5699
        print("servo degrees:", x)
    else:
        print("Error, out of range")    

 


Printer-friendly version
Review and Practice
Prev
Pushbutton Servo Control
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress