Arduino Mega 2560 Gyroscope Control Code

MPU6050s are configurable accelerometers and gyroscopes. So you are capable to measure acceleration, rotation speed and temperature. The gravity is added to the acceleration. From these data the current angle of MPU6050 is calculated in degrees. You can set sensor ranges too. Bigger ranges imply less quility in measurements while smaller ranges makes the quility better. You can store a high variety of measured data to instantly react or later analyze them.

arduino mega with mpu sensor
Figure 1 - Arduino Mega 2560 with MPU6050

Required hardware

  • Arduino Mega 2560
  • MPU6050

Source code to install on controller


Before you upload this code to your Arduino, please format the EEPROM...
#include <OzIDManager.h>
#include <OzGyroscopeSensor.h>

OzIDManager* manager;
OzGyroscopeSensor* mpu6050;

void setup()
{
  Serial.begin(115200);

  manager = new OzIDManager;
  manager->_sendACK = true;
  manager->_checksum = true;

  OzCommunication::setIDManager(manager);

  mpu6050 = new OzGyroscopeSensor(); 

  int x=1;
  manager->sendLinkSetup();
  manager->PrintWelcomeLine(mpu6050, x++, "MyGyroscope");
}

void loop()
{
	OzCommunication::communicate();
	mpu6050->ownLoop();
}

More information