DC motor controlled by Joystick 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
Joystick - 1 Nos
Transceiver - 2 Nos

Program Code:

Transmitter Code:

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

int x_axis = A1;
int y_axis = A2;
int xvalue;
int yvalue;
int data[2];

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

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

void loop() {{
xvalue=analogRead(x_axis);
xvalue=map(xvalue,0,1023,0,127);
data[0]=xvalue;
radio.write(data,1);
}
{
yvalue=analogRead(y_axis);
yvalue=map(yvalue,0,1023,128,255);
data[0]=yvalue;
radio.write(data,1);
}
Serial.println(xvalue);
Serial.println(yvalue);
}


Receiver Code:

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

const int motorforward = A1;
const int motorbackward = A2;
const int motorleft = A3;
const int motorright = A4;

int data[2];
RF24 radio(9,10); // CE,CSN:
const 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,1);
   if(data[0]>1 && data[0]<51){
    digitalWrite(motorforward,LOW);
    digitalWrite(motorbackward,HIGH);
  }
    if(data[0]>77 && data[0]<128){
    digitalWrite(motorforward,HIGH);
    digitalWrite(motorbackward,LOW);
  }
      if(data[0]>52 && data[0]<76){
    digitalWrite(motorforward,LOW);
    digitalWrite(motorbackward,LOW);
  }


   if(data[0]>129 && data[0]<179){
    digitalWrite(motorleft,HIGH);
    digitalWrite(motorright,LOW);
  }
    if(data[0]>205 && data[0]<255){
    digitalWrite(motorleft,LOW);
    digitalWrite(motorright,HIGH);
  }
     if(data[0]>180 && data[0]<204){
    digitalWrite(motorleft,LOW);
    digitalWrite(motorright,LOW);
  }
 }
}

Video:


Comments

Popular posts from this blog

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

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