Controlling a Two-axis Robot Arm With a Gyro Sensor

by Student Rover Challenge Korea in Circuits > Arduino

52 Views, 1 Favorites, 0 Comments

Controlling a Two-axis Robot Arm With a Gyro Sensor

화면 캡처 2024-06-09 120226.png

This is a project that operates the joints of a robot arm using the IMU sensor MPU6050.

Coding

#include<Servo.h>
#include<Wire.h>

const int MPU=0x68; // Address of i2c of MPU6050
int AcX,AcY;

void get6050();//Variable execution

Servo servox;//Set servo name
Servo servoy;//Set servo name
int xpos;//The integer (int) is the basic data type for storing numbers.
int ypos;//The integer (int) is the basic data type for storing numbers.

void setup()
{
Wire.begin(); // Start i2c communication
Wire.beginTransmission(MPU); //BeginTransmission (address) Prepare Data for a specific address after the end of the transmission
Wire.write(0x6B); // Start with register 0x68
Wire.write(0); // set to ZERO, MPU6050 준비

Wire.endTransmission(true); //Start transmitting data for a specific address, stop when true
Serial.begin(9600);//Designate serial communication as 9600
servoy.attach(10);// Designation of servo motor pins
servox.attach(11);// Designation of servo motor pins
servoy.write(70);// Specify start value
servox.write(70);// Specify start value
}

void loop()
{
get6050();//Variable execution
xpos=map(AcX,-16383,16383,0,180);//Mapping value
ypos=map(AcY,-16383,16383,0,180);//Mapping value
servoy.write(xpos);//Move by the value xpos
servox.write(ypos);//Move by the value of ypos
Serial.print("xpos=");Serial.print(xpos);Serial.print("/ypos=");Serial.println(ypos);

}

void get6050(){
Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false); // restart when false
Wire.requestFrom(MPU,14,true); //14 Data requests from address, 4 requests here
AcX=Wire.read()<<8|Wire.read(); // 0x3B(ACCEL_Xout_H) and 0x3C(ACCEL_Xout_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D(ACCEL_Yout_H) and 0x3E(ACCEL_Yout_L)
}

Mapping refers to the process of copying data from a source location to a target location, and at the same time converting data from one type of data format to another.

origin:https://blog.naver.com/etsea/220450986219

Serial monitor: 9600.

A Circuit Diagram

| Parts | Connections |

| --- | --- |

| breadboard | Arduino, gyro sensor, servo motor |

| Arduino | Breadboard, servo motor, gyro sensor |

| gyro sensor | Arduino, (pin A4, A5), bread plate |

| servo motor | cordo gyro sensor, aduino, bread plate |

Production

tjq=서보.png

Make the servo motor moveable in theAfter making the hardware in an L-shape, stick the wooden chopsticks to the L-shape hardware by sharpening them X and Y axes

Connecting to Servo Motor

화면 캡처 2024-06-09 120029.png

After making the hardware in an L-shape, stick the wooden chopsticks to the L-shape hardware by sharpening them

Setting Up

Set the value of the servo motor to 90 degrees, put the servo horn according to the value, put the pedestal on the servo horn, set the value of the servo motor 2 to 90, put it on the pedestal, and put the L-shaped hardware on it