Home > Projects > Motor Projects > DC Motor Speed Control using GY 521 Gyro/Accelerometer and Arduino

DC Motor Speed Control using GY 521 Gyro/Accelerometer and Arduino

Summary of DC Motor Speed Control using GY 521 Gyro/Accelerometer and Arduino


This article details a project to control two DC motor speeds using an Arduino and a GY-521 accelerometer. Tilting the module up or down inversely adjusts the motors' speeds: moving upward increases the first motor's speed while decreasing the second, and vice versa. The system maps sensor acceleration data to PWM values for precise motor control via an L293D driver.

Parts used in the Two Motor Speed Control Project:

  • Arduino
  • L293D Motor driver IC
  • GY-521 Module
  • 2 DC Motors
  • 7-12V battery
  • Breadboard
  • Connecting wires

In this article, we are going to control two motors by using the GY-521 accelerometer module. The speed of the motor will increase or decrease upon moving the GY-521 module up or down. On moving the Gy-521 towards the downside, the speed of the first motor will decrease and the speed of the other motor will increase; while on moving the GY-521 towards the upward side, the speed of the second motor will decrease and the speed of the first motor will increase.

DC Motor Speed Control using GY 521 Gyro Accelerometer and Arduino

Before we begin our tutorial on controlling the motor speed, let’s see how to interface an accelerometer to Arduino.

Components Required

The components required for this project are as follows

  • Arduino
  • L293D Motor driver IC
  • GY-521 Module
  • 2 DC Motors
  • 7-12V battery
  • Breadboard
  • Connecting wires

Circuit Diagram

First of all, make the connections of the L293D with the Arduino as follows

  • Connect the pin 1 of the L293D IC to the 5V of Arduino.
  • Connect the pin 2 of L293D to the digital pin 5 of the Arduino.
  • Connect the pin 3 of the L293D to one end of the motor and connect the other end of the motor to the pin 6 of L293D.
  • The Pins 4, 5 are the ground pins, connect these to the GND of Arduino.
  • Connect the pin 7 of L293D to the digital pin 6 of Arduino.
  • Pins 8 and 16 are the VCC pins, connect these to positive of battery and connect the negative of battery to the Ground.
  • Connect the pin 9 of L293D to the 5V of Arduino.
  • Connect pin 10 of L293D to the pin 9 of Arduino.
  • Connect pin 11 of L293D to the one end of motor and connect the second end of motor to the pin 14 of L293D.
  • Pins 12 and 13 are the ground pins, connect these to the ground.
  • Connect pin 15 of L293D to the pin 10 of Arduino.

If you are using any Arduino other pins for making connections to the L293D motor driver, then ensure that you select PWM enabled pins.

After that, make the connections for the GY-521 module with the Arduino as follows

  • VCC pin of GY-521 to the 5V pin of Arduino
  • GND pin of GY-521 to the GND of Arduino
  • SCL pin of GY-521 to the A5 of Arduino
  • SDA pin of GY-521 to the A4 of Arduino

Working

The structure of the accelerometer sensor has a mass attached to a spring which has fixed outer plates and moves along one direction. So when an acceleration is applied in any of the direction, 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 Speed Control using GY 521 Gyro Accelerometer and Arduino schematics

On moving the GY-521 in the upward or downward direction, the sensor will give us output from -17000 to +17000. We will map this from -125 to +125 and will use this value to rotate the motors. Now, when we move the GY-521 towards up, the output value will go to 125. We will add 125 to this output value and this will be the speed of the first motor. Similarly, when we move GY-521 towards the downside, the output value will go to -125. We will subtract this value from 125 and this will be the speed of the second motor.

Read more: DC Motor Speed Control using GY 521 Gyro/Accelerometer and Arduino

Quick Solutions to Questions related to Two Motor Speed Control Project:

  • How does tilting the GY-521 affect motor speed?
    Moving the module upward increases the first motor's speed and decreases the second, while moving it downward reverses this effect.
  • What components are required for this project?
    The project requires an Arduino, L293D Motor driver IC, GY-521 Module, 2 DC Motors, a 7-12V battery, a breadboard, and connecting wires.
  • Can I use non-PWM pins for the L293D connections?
    No, if using different Arduino pins, you must ensure they are PWM enabled.
  • How is the GY-521 connected to the Arduino?
    Connect VCC to 5V, GND to GND, SCL to A5, and SDA to A4 on the Arduino.
  • What is the output range of the GY-521 when moved vertically?
    The sensor provides an output ranging from -17000 to +17000 when moved upward or downward.
  • How are the sensor values mapped to motor speeds?
    The output is mapped from -125 to +125; adding 125 sets the first motor speed, while subtracting from 125 sets the second motor speed.
  • Which pins on the L293D connect to the battery positive terminal?
    Pins 8 and 16 of the L293D are the VCC pins that connect to the positive side of the battery.
  • Does the accelerometer measure force directly?
    No, it measures changes in capacitance caused by the movement of a mass attached to a spring when acceleration is applied.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top