How to use an Arduino Gyroscope sensor

In this section, you will learn about the Arduino gyroscope sensor. The gyroscope sensor measures rotational velocity or rate of change of the angular position over time, along the X, Y and Z axis. The guide provides you some basic information about the gyroscope sensor and its wiring protocol. Then you will be able to see how you can work with the gyroscope sensor from your computer using Ozeki 10 demonstrated with videos. So, let's start right now.

What is a gyroscope sensor?

The gyroscope measures rotational velocity or rate of change of the angular position over time, along the X, Y and Z axis. The outputs of the gyroscope are in degrees per second, so in order to get the angular position, we just need to integrate the angular velocity. Briefly, it can measure gravitational acceleration along the 3 axes and using some trigonometry math we can calculate the angle at which the sensor is positioned

How does an Arduino gyroscope sensor work?

The accelerometer measures the acceleration along one direction, while the gyroscope measures the angular acceleration on one axis. The analogic pins are not set on INPUT because it's their default setting. The values read by the analogic pins will be sent to the serial port. Open the Serial Monitor, move the sensor and try to see how the values change. Accelerometers can be used for fun projects, for example, to realize a game controller.

How to use an Arduino Gyroscope sensor?

To operate with a gyroscope sensor, you need to connect four wires to your Arduino. You need wires to be connected to the ground (Gnd) from the gyroscope's Gnd pin and a second wire from the VCC pin of the gyroscope to the 5v pin of the Arduino. Then, you need another two wires to be connected to two analog inputs of the Arduino (Figure 1). The first one of these wires goes from the SCL pin of the gyroscope, and the second wire goes from the gyroscope's SDA pin.

Arduino gyroscope wiring diagram

wiring diagram of arduino gyroscope
Figure 1 - Wiring diagram of Arduino Gyroscope

How to use an Arduino Gyroscope sensor in Ozeki

MPU6050 connections are used for transferring accelerometer, gyroscope, angle and temperature data from the MPU6050 chip to your Ozeki software. You can select what to do next with the gathered information. For example you can forward it to another connection or analyze it in real-time before storing it in an SQL database. To use the Gyroscope sensor in Ozeki, you first need to download Ozeki Robot Developer. Ozeki Robot Developer will install the Arduino libraries needed to use this sensor efficiently.

Download Ozeki Robot Developer

download button

After Ozeki Robot developer is installed, you need to upload the Gyroscope sensor control code to your Arduino. You can find the code and download instructions on the following pages. The upload process includes two steps: first you need to format the EEPROM of the arduino, then you need to upload the control code. The procedure is very simple, it only takes a few seconds.

Upload the Gyroscope sensor code to Arduino Uno
Upload the Gyroscope sensor code to Arduino Mega 2560
Upload the Gyroscope sensor code to Arduino Nano
Upload the Gyroscope sensor code to Raspberry Pi

The arduino sensors and Ozeki will communicate over the USB port using the Ozeki Gyroscope sensor protocol. This protocol makes it possible for you to use the sensor directly on your PC. You will be able to control this sensor through the web based user interface or you will be able to communicate with it using Ozeki Chat. You can read more about chat control on the following page.

How to communicate with the Gyroscope sensor using chat

It is important to understand chat control, because when you build a robot, the way you wish to control this sensor is by sending and receiving messages. If you open the Ozeki Robot Developer app, you will see, who you can write a C#.Net program to work with this sensor.

Connection steps

  1. Wire the Gyroscope to your Arduino
  2. Connect the Arduino to the PC
  3. Check the COM ports to make sure your Arduino is connected
  4. Upload the example code to the microcontroller
  5. Open https://localhost:9515 in the browser to use Ozeki 10
  6. Click on the connection of the Gyroscope sensor
  7. Configure the sensor by using 'Autoconfigure'
  8. Click on 'Get gyroscope details' to test your sensor

System overview

The system we suggest consists of a gyroscope sensor, that is wired to the analog port of your Arduino. The Arduino will be responsible for reading data from this device in real-time. The brain of the system will be running on a PC (Figure 2). On the PC, Ozeki 10 will be able to manage the communication. You can easily run Ozeki 10 using a webbrowser

system config of gyroscope
Figure 2 - System configuration of Gyroscope connecting to PC using Arduino

Prerequisites

  • MPU6050 (accelerometer and gyroscope)
  • Ozeki 10 installed on your computer
  • Programmable board (Arduino Mega/Nano/Uno or Raspberry Pi)
  • USB cable is needed between Arduino Mega/Nano/Uno and your computer

Step 1 - Wire the gyroscope to your Arduino

You can see how to wire the accelerometer and gyroscoper to any of the following boards:

After wiring, please plug the board to your computer!

Step 2 - Upload code to the microcontroller

(Here is the code to upload)

Step 3 - Start Ozeki 10 to try the gyroscope

Step 4 - Configure your gyroscope in Ozeki 10

In order to configure your gyroscope sensor (attached to your Arduino) in Ozeki 10, that is installed on your computer, you need to open the graphical user interface (GUI) of Ozeki 10. You can open the GUI by entering the URL of the computer into your webbrowser. For example, if our PC has an IP address of 192.168.1.5, we would enter http://192.168.1.5:9513 into our webbrowser.

Step 5 - Understand the gyroscope sensor protocol

The Gyroscope Sensor can communicate with Ozeki through the following protocol.

References:
http://www.arduinostarterskit.com
https://howtomechatronics.com
https://create.arduino.cc

More information