C++Code SnippetComponentsLanguage FeatureLearn C++

How To Make Use Of The Gyroscope Sensor in C++?

What is the gyroscope sensor? How can I use the gyroscope sensor in a C++ app? How can I measure the rotation of a mobile device? Let’s answer these questions.

What is the gyroscope sensor?

Gyroscope sensors, also known as Gyro Sensors, are sensors that measure rotational motion and changes in orientation of a device such as a cell phone or tablet.

There are many different types of gyro sensors: Gyrostat, Micro Electromechanical Systems (MEMS) Gyroscope, Hemispherical Resonator Gyroscope (HRG), Vibrating Structure Gyroscope (VSG) or Coriolis Vibratory Gyroscope (CVG), Dynamically Tuned Gyroscope (DTG), Ring Laser Gyroscope (RLG), Fiber Optic Gyroscope, London Moment Gyroscope. All these types and more details can be found in Wikipedia here

In the last decade, in addition to being used in compasses, aircraft and computer pointing devices, gyro sensors have been introduced into consumer electronics. The popularity of gyroscope started with the first application of the gyroscope in consumer electronics when they were included for the first time in iPhone devices. This was very quickly followed with sensors being used and widely available in nearly all mobile device and IoT brands. Now, most mobile devices have these sensors and can be used to obtain data in application developments.

Vibration gyro sensors are very popular and have found their way into camera-shake detection systems for compact video and still cameras, motion sensing for video games, and vehicle electronic stability control (anti-skid) systems, among other things.

How can I use gyro sensors in C++ Builder?

  1. Create a new Multi-Device C++ Builder FireMonkey application.
  2. Define TCustomOrientationSensor (*FSensor), TSensorArray (FSensors); TSensorManager (*FSensorManager) in the private sections of the form header as below,

3. In the form creation or at the beginning of using the device we should attempt to get and activate the sensor manager and try to get an orientation sensor as below. For example:

Now we can check sensors in a loop and find we can set this sensor as FSensor as below,

As you can see, if no sensor find we exit from the procedure. Let’s continue to add some code inside this procedure;

as a result, the finished procedure will be as below,

Now we can sense data from this sensor in a timer in its intervals as below,

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?