This repository contains the code to control a robot using an MPU6050 sensor and DC motors. The robot can move forward and turn based on the sensor data.
1.ino
: Main Arduino sketch that initializes the MPU6050 sensor and controls the robot's movements.MPU6050.ino
: Additional Arduino sketch for MPU6050 sensor initialization and control.
- Connect the MPU6050 sensor to the Arduino.
- Connect the left motor to port 1 and the right motor to port 2 of the motor driver.
- Upload the
1.ino
orMPU6050.ino
sketch to the Arduino.
Initializes the MPU6050 sensor and sets up the serial communication.
Moves the robot forward by a specified distance in meters.
Turns the robot by a specified angle in degrees. Positive values for right turns and negative values for left turns.
Stops both motors.
Main loop that controls the robot's movements.
void loop() {
moveForward(1.0); // Move forward 1 meter
turnRobot(90); // Turn 90 degrees right
delay(1000); // Wait for 1 second
moveForward(1.0); // Move forward 1 meter
delay(1000); // Wait for 1 second
turnRobot(-90); // Turn 90 degrees left
moveForward(1.0); // Move forward 1 meter
delay(10000); // Wait for 10 seconds
}
- Adafruit MPU6050 Library
- Adafruit Sensor Library
- Adafruit Motor Shield Library