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
  • Cybersecurity: Radio Tilt Control

Cybersecurity: Radio Tilt Control

Z-Axis: Which Way Is Up?

Did you remember that the micro:bit module’s accelerometer also has a z-axis? 

Like the hyp calculation from the previous activity, the accelerometer’s z sensing axis can give your script information about the overall level of tilt. 

The main advantage of using the z-axis is that it can also tell your script whether the accelerometer is facing up or down.  In fact, the hyp calculation is normally only used with two-axis (x-y) accelerometers.  Since the micro:bit has a three-axis (x-y-z) accelerometer, scripts can use a combination of atan2(y, x) and z-axis measurements and calculations to get both rotation and tilt level. 

In other words, the script can know exactly how the micro:bit is oriented in space.  

Example script: test-z-axis-tilt

  • Enter, name, and save test-z-axis-tilt.  
  • Click the Send to micro:bit button.
# test-z-axis-tilt

from microbit import *

sleep(1000)

while True:

    z = accelerometer.get_z()
    
    print("z =", z)

    sleep(750)
  • Check the results in the serial monitor, and experiment with various levels of tilt and rotation.
  • Try holding the micro:bit level with its LEDs facing the floor.  Were you able to get a z-axis measurement in the neighborhood of 1024?
  • Next, try holding the micro:bit vertical.  Is the z-axis measurement close to zero?
  • Last, try holding the micro:bit level, but with the LEDs facing up.  Verify that the z-axis measurement is in the 1024 neighborhood.

 


Printer-friendly version
How It Works
Prev
How it Works: Z axis
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress