Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » DC Motor Control with Arduino MPU6050 Gyro/Accelerometer
Arduino Projects

DC Motor Control with Arduino MPU6050 Gyro/Accelerometer

Mamtaz AlamBy Mamtaz AlamUpdated:November 26, 20232 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
DC Motor Control using MPU6050 Gyro/Accelerometer
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Introduction:

In this project, we are going to learn about DC Motor Control using MPU6050 Gyro/Accelerometer Sensor, L293D Motor Driver IC & Arduino. MPU6050 is an Accelerometer & Gyro sensor combined in a single chip. By moving the sensor in an upward or downward direction, the speed of the motors will increase or decrease. We will simply be interfacing MPU6050 or GY21 sensor with Arduino for controlling 2 motors & displaying the speed on LCD.

By moving the sensor in an upward direction, the speed of the first motor will increase and the speed of another motor will decrease. Similarly, by moving the sensor in a downward direction, the speed of the first motor will increase and the speed of another motor will decrease. We will also be displaying the speed of the motor on the 16*2 LCD.

Before moving ahead, learn about Arduino MPU6050 Interfacing. You may also take a look at another post where Tilt angle can also be measured by combining MPU6050 with Arduino.


Hardware Requirements:

  1. Arduino Uno
  2. MPU6050 (Accelerometer and Gyro sensor)
  3. L293D Motor Driver
  4. 5V DC Motors
  5. 16*2 LCD
  6. Connecting wires
  7. Breadboard

MPU6050 Gyro/Accelerometer Sensor:

Introduction:

DC Motor Speed Control using MPU6050 Gyroscope Sensor & Arduino

The InvenSense MPU-6050 sensor contains a MEMS accelerometer and a MEMS gyro in a single chip. It is very accurate, as it contains 16-bits analog to digital conversion hardware for each channel. Therefor it captures the x, y, and z channel at the same time. The sensor uses the I2C-bus to interface with the Arduino.

The MPU-6050 is not expensive, especially given the fact that it combines both an accelerometer and a gyro.

MPU6050 Pinout:

The MPU-6050 module has 8 pins,
INT: Interrupt digital output pin.
AD0: I2C Slave Address LSB pin. This is the 0th bit in the 7-bit slave address of the device. If connected to VCC then it is read as logic one and slave address changes.
XCL: Auxiliary Serial Clock pin. This pin is used to connect other I2C interface enabled sensors SCL pin to MPU-6050.
XDA: Auxiliary Serial Data pin. This pin is used to connect other I2C interface enabled sensors SDA pin to MPU-6050.
SCL: Serial Clock pin. Connect this pin to the microcontrollers SCL pin.
SDA: Serial Data pin. Connect this pin to the microcontrollers SDA pin.
GND: Ground pin. Connect this pin to a ground connection.
VCC: Power supply pin. Connect this pin to +5V DC supply.

3-Axis Gyroscope:

The MPU6050 consists of a 3-axis Gyroscope with Micro Electro Mechanical System(MEMS) technology. It is used to detect rotational velocity along the X, Y, Z axes as shown in the below figure.
3 Axis Gyroscope

3-Axis Accelerometer:

The MPU6050 consists of a 3-axis Accelerometer with Micro Electro Mechanical (MEMs) technology. It used to detect the angle of tilt or inclination along the X, Y, and Z axes as shown in the below figure.
3 axis acceleromter




DC Motor Control using MPU6050 Gyro/Accelerometer Sensor & Arduino:

Circuit Diagram:

DC Motor Control using MPU6050 Gyro/Accelerometer

Connections:

1. Connection Between Arduino, Motor & L293D
– Pin No. 1, 8, 9, 16 of L293D IC is connected to 5V
– Pin No’s 4, 5, 12, and 13 are the ground pins; connect these to GND (Arduino GND pin).
– Pin No. 2 of L293D IC is connected to Pin No. D2 of Arduino.
– Pin No. 7 of L293D IC is connected to Pin No. D3 of Arduino.
– Pin No. 10 of L293D IC is connected to Pin No. D4 of Arduino.
– Pin No. 15 of L293D IC is connected to Pin No. D5 of Arduino.
– Pin No. 3, 5 of the L293D IC is connected to 2 terminals of motor M1.
– Pin No. 11, 14 of the L293D IC is connected to 2 terminals of motor M2.

2. Connection Between Arduino & MPU6050
– Connect VCC pin of MPU6050 to the 5V pin of Arduino
– Connect GND pin of MPU6050 to the GND of Arduino
– Connect SCL pin of MPU6050 to the A5 of Arduino
– Connect SDA pin of MPU6050 to the A4 of Arduino

2. Connection Between Arduino & LCD
– Connect 1, 3, 5, 16 pins of LCD to the GND pin of Arduino
– Connect 2, 15 pin of LCD to the 5V pin of Arduino
– Connect Pin No. 4 of LCD to the D13 of Arduino
– Connect Pin No. 6 of LCD to the D12 of Arduino
– Connect Pin No. 11 of LCD to the D11 of Arduino
– Connect Pin No. 12 of LCD to the D10 of Arduino
– Connect Pin No. 13 of LCD to the D9 of Arduino
– Connect Pin No. 14 of LCD to the D8 of Arduino


Program & Source Code:

First, download the header files library from below and add it to the Arduino Library:
1. MPU6050 Library
2. I2Cdev Library

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <Wire.h>
#include <MPU6050.h>
#include<LiquidCrystal.h> // lcd Header
LiquidCrystal lcd(13,12,11,10,9,8); // pins for LCD Connection
 
#define motor1_pin1 2
#define motor1_pin2 3
#define motor2_pin1 4
#define motor2_pin2 5
 
MPU6050 gy_521;
 
int16_t ax, ay, az;
int16_t gx, gy, gz;
 
int motor1_speed;
int motor2_speed;
 
void setup ( )
{
Wire.begin( );
 
lcd.begin(16,2); //initializing lcd
Serial.begin(9600); // initializing serial
lcd.print("Initializing.....");
delay(2000);
lcd.clear();
 
Serial.println ("Initializing MPU and testing connections");
gy_521.initialize ( );
Serial.println(gy_521.testConnection( ) ? "Successfully Connected" : "Connection failed");
lcd.print(gy_521.testConnection( ) ? "Connected.............." : "No Connection....");
delay(2000);
lcd.clear();
Serial.print("Reading Values");
lcd.print("Reading Values...");
delay(2000);
lcd.clear();
}
 
void loop ( )
{
gy_521.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
ax = map(ax, -17000, 17000, -125, 125);
 
motor1_speed = 125+ax; //To move first motor
motor2_speed = 125-ax; //To move second motor
 
Serial.print ("Motor1 Speed = ");
lcd.setCursor(0,0);
lcd.print ("MOT1 Speed = ");
Serial.print (motor1_speed, DEC);
lcd.print (motor1_speed, DEC);
 
Serial.print ("Motor2 Speed = ");
lcd.setCursor(0,1);
lcd.print ("MOT2 Speed = ");
Serial.println (motor2_speed, DEC);
lcd.print (motor2_speed, DEC);
delay(300);
analogWrite (motor1_pin2, motor1_speed);
analogWrite (motor2_pin2, motor2_speed);
delay (300);
}



Working Explanation:

In this Project DC Motor Control using MPU6050 Gyro/Accelerometer Sensor & Arduino first we need to understand the operation of MPU6050 & then the working of DC Motor Control using MPU6050 Gyro/Accelerometer

Operation of MPU6050
The structure of the accelerometer and gyro sensor has a mass attached to a spring that has fixed outer plates and moves along one direction. If acceleration is applied in any of the directions, the capacitance between the plates and the mass will change. The accelerometer sensor will measure this change in capacitance which corresponds to an acceleration value.

DC Motor Control using MPU6050 Gyro/Accelerometer

Working of DC Motor Control using MPU6050 Gyro/Accelerometer
Whenever we move the sensor in the upward or downward direction, the sensor gives the output from -17000 to 17000. The motors only require 0 to 255 PWM values to rotate. So, we will map these values from -125 to 125. Now, when we move the MPU6050 towards the upward direction, the output value which we will get is 125. Then we will add 125 to this output value and this will be the speed of the first motor.

When we move the MPU 6050 towards the downward direction, the output value which we will get is -125. We will subtract this from 125 and this will be speed for the second motor.


Video Preview: Working & Explanation

MPU6050 Gyro/Accelerometer Sensor & Arduino for Controlling DC Motor
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIoT Weighing Scale with HX711 Load Cell & ESP8266
Next Article ESP8266 and DS3231 Based Real Time Clock (RTC)

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 2 Comments

2 Comments

  1. chaitanya on March 22, 2019 3:13 PM

    i can’t add MPU6050 Library,I2Cdev Library to arduino ide

    Reply
  2. Vikram on October 6, 2021 7:15 PM

    Error in 129:21

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • Half Wave Rectifier Basics, Circuit, Working & Applications
    Half Wave Rectifier Basics, Circuit, Working & Applications
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.