📊 micro:bit Data and Climate Change
  • Introduction
  • Data
  • Climate Change
  • Our Tools
    • 01- micro:bit
    • 02 - MakeCode
      • A - Events
      • B - Animations
      • C - Counting
      • D - If Hot
    • 03 - Servo Motor
      • Coding your first servo motor on MakeCode
    • 04 - Neopixel
      • Coding your first neopixel on MakeCode
  • Activities
    • Tools and Data Together
      • 01 - micro:bit and Data
      • 02 - Servo Motor and Data
      • 03 - Neopixel and Data
  • Showcase Projects
    • 01 - Air Pollution
      • A - Servo Motor
      • B - Neopixel Grid
    • 02 - Green Energy Forecast
    • 03 - Temperature Change
      • A - Neopixel Grid
      • B - Neopixel Ring
    • 04 - Heavy Precipitation Days
      • A - Neopixel Grid
      • B -Servo Motor
      • C-Neopixel Fairy Lights
    • 05 - Greenhouse Gas Emission
      • A - Neopixel Grid
      • B - Neopixel Fairy Lights
  • 🚀Extra Missions
  • Support Material
    • Data on the Run
    • Data Visualization Examples
    • Data Science of Climate Change by Lucie Luneau
    • Ideas from the Canadian Space Agency - CSA
    • CASC + Science Spotlight
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Our Tools
  2. 03 - Servo Motor

Coding your first servo motor on MakeCode

Previous03 - Servo MotorNext04 - Neopixel

Last updated 2 years ago

Was this helpful?

Photo by on

There is no need to have a servo motor for this activity. We will use the emulator and the servo extension in MakeCode to visualize the result of our code.

Open and follow along or read the goals of this activity and try to do it as a challenge.

Goals

  • Have the micro:bit position the servo motor to 90 degrees at the start of the application.

  • When the user presses the A button, change the angle to 0-degree.

  • When the user presses the B button, change the angle to 180-degree.

  • Reset the angle to 0-degree, when the user presses A and B at the same time.

Our solution

Add the Servo Extension to your MakeCode project
  • To start, we need to enable the Servo extension in MakeCode. To do so, click on Extensions.

  • Add the servo extension from the list

Now you have access to a new group of blocks and the emulator includes a virtual servo motor. They provide different ways of moving the servo.

Initialize servo motor at a 90-degree angle

The following code will initialize the servo motor at a 90-degree angle as soon as the micro:bit gets electricity (when it starts).

Test on the emulator and see how the servo moves its pointer to the expected position.

Press Button A, B and A+B to change positions

All these three actions follow the same pattern. We introduce a block that will trigger action and depending on the button pressed, we change to the desired angle

Button A to 0 degrees

Button B to 180 degrees

Buttons A+B to the initial position (90 degrees)

Test on the emulator and see how the servo moves its pointer to the expected position when you press different buttons.

The next tool we are learning about is called a Neopixel. See you in the next section.

MakeCode
Kilimanjaro STUDIOz
Unsplash