New Project

CONNECT

Servo Control over Bluetooth with Accelerometer

  • Page Views 2908
  • Spread the love
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  

    This project will allow us to Servo Control over Bluetooth with Accelerometer.Bluetooth samples from possible application is shown in the video.

    In addition to our project he will make it more convenient by adding wireless control.

    Materials:

    • Arduino x 2
    • MPU6050 axis accelerometer
    • HC05 vs HC-06 Bluetooth module
    • Servo motor (we’ll use the example application 1.)
    • Electronic Section:

    Transmitter Circuit:

     

    Receiver Circuit:

     

    The receiver and transmitter circuit connections are shown.Accelerometer SCL pin A5 to A4 SD pin will be connected.If you use mega-mega-pins are available in the name of these pins.Attach it to the pole pins.

    Software Part:
    Transmitter Software:

    //Software development By Robimek – 2015
    //software Licensing By Robimek
    //www.robimek.com
    #include "Wire.h"
    #include "I2Cdev.h"
    #include "MPU6050.h"
    MPU6050 mpu;
    int16_t ax, ay, az;
    int16_t gx, gy, gz;
    #include <SoftwareSerial.h>
    #define BT_SERIAL_TX 4
    #define BT_SERIAL_RX 3
    SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);
    int servoValue1;
    int gyro_value = 0;
    void setup()
    {
    Wire.begin();
    mpu.initialize();
    Serial.begin(9600);
    BluetoothSerial.begin(9600);
    }
    void loop()
    {
    mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    gyro_value = map(ax, 0, 17000, 0,9);
    switch(gyro_value){
    
    case 0: BluetoothSerial.print("0");break;
    case 1: BluetoothSerial.print("1");break;
    case 2: BluetoothSerial.print("2");break;
    case 3: BluetoothSerial.print("3");break;
    case 4: BluetoothSerial.print("4");break;
    case 5: BluetoothSerial.print("5");break;
    case 6: BluetoothSerial.print("6");break;
    case 7: BluetoothSerial.print("7");break;
    case 8: BluetoothSerial.print("8");break;
    case 9: BluetoothSerial.print("9");break;
    default: BluetoothSerial.print("0");break;
    }
    
    delay(100);
    }

    Receiver Software:

    //Software development By Robimek – 2015
    //software Licensing By Robimek
    
    //www.robimek.com
    #include <SoftwareSerial.h>
    #define BT_SERIAL_TX 4
    #define BT_SERIAL_RX 3
    SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);
    #include <Servo.h>
    Servo myservo;
    char servo_val = ' ';
    void setup()
    {
    Serial.begin(9600);
    BluetoothSerial.begin(9600);
    myservo.attach(10);
    }
    void loop()
    {
    if (BluetoothSerial.available()>0){
    servo_val = BluetoothSerial.read();
    int servo_deger = servo_val - '0';
    servo_deger=servo_deger*20;
    if(servo_deger>180){servo_deger=180;}
    myservo.write(servo_deger);
    }
    
    }

    After installing the software on your Arduino board to reset the transmitter portion accelerometer does not work otherwise.Because after reset is activated in the setup code of I2C communication protocol.

    If you want to increase the precision of servo motion İvmeölçerl you reduce the data sent and map command increment range multiplication factor in the receiver section allows you more precise control.

    You can see the application of the code in the video below.

    // ADXL345 accelerometer 2 servo motor control
    
    #include <Wire.h>
    
    #include <Servo.h>
    
    Servo myservox;
    
    Servo myservoy;
    
    #define DEVICE (0x53)
    
    #define TO_READ (6)
    
    #define TRIGGER 16 byte buff[TO_READ] ;
    
    int i;
    
    void setup()
    
    { pinMode(TRIGGER,OUTPUT);
    
    digitalWrite(TRIGGER,HIGH);
    
    Wire.begin();
    
    myservox.attach(9);
    
    myservoy.attach(10);
    
    myservox.write(90);
    
    delay(25);
    
    myservoy.write(90);
    
    delay(25);
    
    writeTo(DEVICE, 0x2D, 0);
    
    writeTo(DEVICE, 0x2D, 16);
    
    writeTo(DEVICE, 0x2D, 8);}
    
    void loop()
    
    { int regAddress = 0x32;
    
    int x, y, z; digitalWrite(TRIGGER,LOW);
    
    delay(10); digitalWrite(TRIGGER,HIGH);
    
    readFrom(DEVICE, regAddress, TO_READ, buff);
    
    x=0; y=0; z=0;
    
    for(i=1;i<=5;i++)
    
    { x += (((int)buff[1]) << 8) | buff[0];
    
    y += (((int)buff[3])<< 8) | buff[2];
    
    z += (((int)buff[5]) << 8) | buff[4];
    
    delay(10);
    
    }
    
    x/=5;
    
    y/=5;
    
    z/=5;
    
    if(x<-255)x= -255;
    
    else if (x>255)x=255;
    
    if(y<-255)y= -255;
    
    else if (y>255)y=255;
    
    x=map(x, -255, 255, 0, 180);
    
    y=map(y, -255, 255, 0, 180);
    
    myservox.write(x);
    
    delay(25);
    
    myservoy.write(180-y);
    
    delay(25);
    
    delay(200);}
    
    void writeTo(int device, byte address, byte val)
    
    { Wire.beginTransmission(device);
    
    Wire.write(address); Wire.write(val);
    
    Wire.endTransmission(); }
    
    void readFrom(int device, byte address, int num, byte buff[])
    
    { Wire.beginTransmission(device);
    
    Wire.write(address);
    
    Wire.endTransmission();
    
    Wire.beginTransmission(device);
    
    Wire.requestFrom(device, num);
    
    int i = 0;
    
    while(Wire.available())
    
    {
    
    buff[i] = Wire.read(); i++;
    
    }
    
    Wire.endTransmission();
    
    }

    Share

    What did they say ?

    12 Comment - "Servo Control over Bluetooth with Accelerometer"

    avatar
    Sort:   The Newests | Ancients | Likes
    kim
    Visitor

    why do you need two different model of bluetooth devices? hc-05 and hc-06?

    Minerva
    Visitor
    Minerva

    Calling Romney a liar may be redundant, but that's what the CEOs of Chrysler & GM did about his "moving Jeep to China" whopper yesterday while &qo3t;Mitt&#u9;s" campaign staff was passing out canned food to participants at a "canned food drive" (wink, wink) for them to then hand to "Mitt" behind a table so that it could then be packed into a rental truck while they try to find someone who wants it. I havn't seen anything that phony since Ann Coulter in a dress.

    Shubham Dhiman
    Visitor
    Shubham Dhiman

    hi, i am unable to upload the code , It is error in this line ( #include”I2dev.h” ) Please help me …………………… i am making a project and need help in this….
    Please ………My gmail is shubhamdhiman00.sd@gmail.com

    Daniel
    Visitor
    Daniel

    Hi. How can I add one more servo to have the Y axis?

    SHUBHAM DHIMAN
    Visitor
    SHUBHAM DHIMAN

    hey bro can u help me in making the same project. Only for one servo . pleasebro help me.

    SHUBHAM DHIMAN
    Visitor

    rtgegbrtbhrthrr

    SHUBHAM DHIMAN
    Visitor
    SHUBHAM DHIMAN
    wpDiscuz

    BE A FACEBOOK FAN

    Instagram