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


Circuit Diagram:


Required Components:


Arduino uno/nano - 1 Nos
Battery - 1 Nos
DC Motor - 2 Nos
L298N Motor Driver - 1 Nos
Gyro MPU6050 - 1 Nos
Transceiver - 2 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);
                              
uint64_t pipe = 0xE8E8F0F0E1LL;

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

void loop(){
 
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);  //With this function, the acceleration and gyro values of the axis are taken.

  data[0] = map(ax, -17000, 17000, 0, 128); //Send X axis data
  data[1] = map(ay, -17000, 17000, 129, 255);  //Send Y axis data
  radio.write(data, sizeof(data));

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

}

Receiver Code:

#include <SPI.h>     
#include "RF24.h"    

int Motorforward  = A1;  
int Motorbackward = A2;  
int Motorleft     = A3;   
int Motorright    = A4;  

int data[2];

RF24 radio(9,10);

uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(){
  pinMode(Motorforward, OUTPUT);
  pinMode(Motorbackward, OUTPUT);
  pinMode(Motorleft, OUTPUT);
  pinMode(Motorright, OUTPUT);
 
  Serial.begin(9600);
  radio.begin();         
  radio.openReadingPipe(1, pipe);
  radio.startListening();            
  }

void loop(){
  if (radio.available()){
    radio.read(data, sizeof(data));

       if(data[0]>1 && data[0]<60){
    digitalWrite(Motorforward,LOW);
    digitalWrite(Motorbackward,HIGH);
  }
    if(data[0]>69 && data[0]<128){
    digitalWrite(Motorforward,HIGH);
    digitalWrite(Motorbackward,LOW);
  }
      if(data[0]>61 && data[0]<70){
    digitalWrite(Motorforward,LOW);
    digitalWrite(Motorbackward,LOW);
  }


   if(data[1]>129 && data[1]<188){
    digitalWrite(Motorleft,HIGH);
    digitalWrite(Motorright,LOW);
  }
    if(data[1]>198 && data[1]<255){
    digitalWrite(Motorleft,LOW);
    digitalWrite(Motorright,HIGH);
  }
     if(data[1]>189 && data[1]<199){
    digitalWrite(Motorleft,LOW);
    digitalWrite(Motorright,LOW);
  }
  }
}

Video:


Comments

  1. Binance account frozen error? This error might seem difficult but what actually difficult is to fix it which is out of the scope of a user who just has joined or holds less information about the exchange. If you are looking for ways and means to deal with this a bummer all at once, you can always call on Binance customer support number which is always functional. You can have conversation with them related to every type of Binance error and avail out-of-the-box remedies from the professionals in nick of time.

    ReplyDelete
  2. ola! É possivel dezenvolver um projeto desse direto no esp 8266

    ReplyDelete

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