Skip to content
Parallax Learn (Stage)

Parallax Learn (Stage)

This is the staging site. Please see https://learn.parallax.com for the official site.

  • 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 Tutorial Series
          • Cybersecurity: Radio Data tutorialCybersecurity Tutorial Series
          • cyber:bot Tutorial Series
          • Boe-Bot Tutorial SeriesBoe-Bot Tutorial Series
          • Arduino Shield-Bot Tutorial Series
          • ActivityBot with C TutorialsActivityBot with C Tutorials
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot with BlocklyProp Tutorial Series
          • Scribbler 3 Tutorial SeriesScribbler 3 Tutorial Series
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education Tutorial Series
          • Propeller C-Language BasicsPropeller C Basics and Projects
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit C Tutorial Series
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit BlocklyProp Tutorials
          • Badge WX Tutorial SeriesBadge WX Tutorial Series
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics and Projects
          • 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
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Radio Tilt Control

Cybersecurity: Radio Tilt Control

Try This: Get Familiar Z-Axis Angle Measurements

The previous page Did You Know? This Way Up explained how to use arccos to calculate the angle between the micro:bit’s z sensing axis and gravity. 

When the LED display is facing straight down, so is the z sensing axis.  So the angle between z and gravity is zero. 

As the angle between the z-axis and gravity increases, so does the measurement.  When the LED display (and z-axis) is facing straight up, it’s angle is 180°.  Again, rotating past 180°, the angle decreases, like the last example where it’s back down to 135° again.

 

Example script: z_axis_degree_of_tilt_try_this

  • Enter, name, and save z_axis_degree_of_tilt_try_this.  
  • Click the Send to micro:bit button.
# z_axis_degree_of_tilt_try_this

from microbit import *
import math

sleep(1000)

while True:
    z = accelerometer.get_z()
    
    if z > 1024:
        z = 1024
    elif z < -1024:
        z = -1024
        
    z_angle = round( math.degrees( math.acos( z/1024) ) )

    print("z =", z, ", z_angle =", z_angle)
    print()
    
    sleep(750)
  • Check the results in the serial monitor, and experiment with various levels of tilt and rotation.

  • Fill in the table with your measured z_angle values.
z z_angle Direction LEDs are facing
1024 0 Straight down
728 45 Half way between straight down and sideways
    Sideways
-728 135 Half way between sideways and straight up
-1024 180 Straight up
    Half way past straight up on way to sideways
    Tilted toward you by 45°
    Tilted away from you by 45°
    GND corner tilted down by 45°
    0 corner tilted down by 45°

 


Printer-friendly version
How it Works: Z axis
Prev
Your Turn: All Together Now
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn (Stage) • Built with GeneratePress