PDA

Orijinalini görmek için tıklayınız : 39. 2 eksen hareket izleyen robot



bolubeyi
10.Ağustos.2015, 17:29
Bu dersimizde 2 eksen hareket izleyen robot yapacağız.

Gerekli malzemeler:
Arduino uno
2 adet servo motor
Pan tilt mekanik aksamı
İvme sensörü
6 adet led
Bakırlı pertinaks
Baskı devre çıkarma araçları
Güç kaynağı
Bağlantı kabloları

Öncelikle servolarımızı pan tilt aksamına monte ediyoruz. Daha sonra fritzing çiziminde gösterildiği şekilde devremizi kurup arduino kodlarımızı arduinoya yükleyeceğiz.Üstteki servoya 6adet led bağladım. Farklı metaryaller bağlanabilir. Ledlere ait ares çizimi konu ekinde mevcuttur.

26fkfod5lac

https://temrinlerim.org/images/arduino61.jpg

https://temrinlerim.org/images/arduino60.jpg

https://temrinlerim.org/images/arduino59.jpg

https://temrinlerim.org/images/arduino58.jpg

https://temrinlerim.org/images/arduino57.jpg

Fritzing çizimi:
https://temrinlerim.org/images/2eksen-robot.png

Arduino kodlarımız:
Kodlara ait arduino dosyası konu ekinde mevcuttur.

/*
2EKSEN HAREKET İZLEYEN ROBOT
*/

#include <Servo.h>
#include<Wire.h>
const int MPU=0x68; // I2C address of the MPU-6050
int AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

Servo myservo1; // create servo object to control a servo
Servo myservo2;
int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2=1;
int val1; // variable to read the value from the analog pin
int val2;
void setup()
{
Wire.begin(); //seri haberleşme
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
myservo1.attach(9);
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
}

void loop()
{
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);

val1 =AcX; // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, -16000, 16000, 180, 0); // scale it to use it with the servo (value between 0 and 180)
val2 = AcY; // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, -16000, 16000, 0, 180);
myservo1.write(val1); // sets the servo position according to the scaled value
myservo2.write(val2);
delay(100); // waits for the servo to get there
}

İhtiyaç olması halinde konuya ait dosyaları temrinlerim.org (https://temrinlerim.org/index.php?topic=221.0) sitesindeki orjinal konudan indirebilirsiniz.

WeBMasteR
10.Ağustos.2015, 18:47
Eline sağlık hocam. Teşekkürler.