Servomotor controlled by Gyro(MPU6050) using Arduino & Transceiver - Wir...


Circuit Diagram:


Required Components:


Arduino uno/nano - 2 Nos
Battery - 2 Nos
Transceiver - 2 Nos
Servo Motor - 2 Nos
Gyro (MPU6050) - 1 Nos


Program Code:

Transmitter Code:

#include <SPI.h>
#include "RF24.h"
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"

MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;

int data[2];

RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(){
Wire.begin();
mpu.initialize();
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}

void loop(){
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
data[0] = map(ax, 10, 17000, 2,178);
data[1] = map(ay, 10, 17000, 2,178);
radio.write(data,sizeof(data));
   {

    Serial.println(data[0]);

    Serial.println(data[1]);
    }
 
}
Receiver Code: 

#include <Servo.h>
#include <SPI.h>
#include "RF24.h"
Servo Servo_motor_x,Servo_motor_y;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int data[2];

void setup()
{
Serial.begin(9600);
Servo_motor_x.attach(5);
Servo_motor_y.attach(6);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}

void loop()
{
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(data, sizeof(data));
Servo_motor_x.write (data[0]);
Servo_motor_y.write (data[1]);

}
  {

    Serial.println(data[0]);

    Serial.println(data[1]);
    }
  }
}


Video:


Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. from where can i download i2cdev library?

    ReplyDelete
  3. Did this code work sir?

    I did the same didn't work for me

    ReplyDelete
    Replies
    1. Some of the code is kind of writing incorrectly.

      Delete
  4. Hello Sir I have tis issue... any solution ?? tqtq

    done = radio.read(data, sizeof(data));


    C:\Users\demee\Documents\Arduino\sketch_Servomotor_MPU6050__Arduino_2\sketch_Servomotor_MPU6050__Arduino_2.ino: In function 'void loop()'

    sketch_Servomotor_MPU6050__Arduino_2:26:37: error: void value not ignored as it ought to be


    ReplyDelete
    Replies
    1. go to C:\Users\yoroc\Documents\Arduino\libraries
      and Delete all librarie nrf24 Then go to this address and install this library

      https://github.com/maniacbug/RF24/archive/refs/heads/master.zip

      Delete

Post a Comment

Popular posts from this blog

Servo motor controlled by Joystick using Arduino & Transceiver - Wireles...

DC motor controlled by Joystick using Arduino & L298N Motor driver - Wireless Connection

DC motor controlled by Gyro MPU 6050 using Arduino & L298N Motor driver - Wired Connection