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

Program Code:

Transmitter Code:

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

int data[2];

RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int potpin1=A1;
int val1;
int potpin2=A2;
int val2;

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

void loop() {{
val1=analogRead(potpin1);
val1=map(val1,0,1023,0,127);
data[0]=val1;
radio.write(data,1);
}
{
val2=analogRead(potpin2);
val2=map(val2,0,1023,128,255);
data[0]=val2;
radio.write(data,1);
}
Serial.println(val1);
Serial.println(val2);
}

Receiver Code:

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

int data[2];

int forward = A1;
int backward = A2;
int left = A3;
int right = A4;

const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(9,10); // CE,CSN:

void setup() {
pinMode (forward,OUTPUT);
pinMode (backward,OUTPUT);
pinMode (left,OUTPUT);
pinMode (right,OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}

void loop() {
if(radio.available()){

  radio.read(data,1);{

    if(data[0]<127&&data[0]>66){
    digitalWrite(forward,LOW);
    digitalWrite(backward,HIGH);}
      if(data[0]<60&&data[0]>1){
    digitalWrite(forward,HIGH);
    digitalWrite(backward,LOW);}
        if(data[0]<65&&data[0]>61){
    digitalWrite(forward,LOW);
    digitalWrite(backward,LOW);}
   
    if(data[0]<255&&data[0]>193){
    digitalWrite(left,LOW);
    digitalWrite(right,HIGH);}
      if(data[0]<186&&data[0]>129){
    digitalWrite(left,HIGH);
    digitalWrite(right,LOW);}
        if(data[0]<192&&data[0]>185){
    digitalWrite(left,LOW);
    digitalWrite(right,LOW);}
   }
  }
}

Video:


Comments

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