Last updated by at .

iOS Programming Recipe 19: Using Core Motion to Access Gyro and Accelerometer

One of the coolest things smartphones are capable of now is the ability to sense motion and orientation. The iPhone does this with the use of a 3-axis Accelerometers and Gyroscopes. In this tutorial we’re going to create an app that indicates the current G and speed of rotation. Not exactly a pretty app but still instructional.

Assumptions

  • You have a developer account and have provisioned a device. Unfortunately we can’t simulate this stuff without hardware. Follow the Apple documentation here to get set up.
  • Make Sure you head over our Github page and download the source code. NSCookbook Github Recipe 19
  • You have looked over some of the past tutorials and are comfortable with creating outlets and actions from the interface builder

Setting Up the Interface

Our Interface will be pretty simple as we will be displaying 12 values. We’ll show Max and Current Acceleration and Rotation about the X,Y and Z axis’.

Start with a new single view project titled “GyrosAndAccelerometers” and make sure the storyboards are selected.

Once the new project is created, open up the storyboard and drag 25 Labels onto the view. Twelve of these labels will be our outlets that will display the output data for each axis. Rename the labels and add a button as shown in the image below:

[Read more…]

css.php
Privacy Policy