NRF24L01 PART-4 || DC MOTORS CONTROL



NRF24L01 PART-4 || DC MOTORS CONTROL


CIRCUIT DIAGRAM:


COMPONENTS REQUIRED:
1. ARDUINO NANO(2).
2. NRF24L01 (2).
3. BUTTONS(4).
4. DC MOTORS(4).
5. MOTOR DRIVER(L298N/L293D).
6. BATTERIES(2).


TRANSMITTER CODE:

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

RF24 radio(9, 10);//CE,CSN
const byte address[6] = "mkinventions100";

int LEFT_FRONT_MOVE = 4;
int LEFT_BACK_MOVE = 5;
int RIGHT_FRONT_MOVE = 6;
int RIGHT_BACK_MOVE = 7;


void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.stopListening();

pinMode(LEFT_FRONT_MOVE, INPUT_PULLUP);
pinMode(LEFT_BACK_MOVE, INPUT_PULLUP);
pinMode(RIGHT_FRONT_MOVE, INPUT_PULLUP);
pinMode(RIGHT_BACK_MOVE, INPUT_PULLUP);
}

void loop() {
int MOTORS[4];
  
  MOTORS[0] = digitalRead(LEFT_FRONT_MOVE);
  MOTORS[1] = digitalRead(LEFT_BACK_MOVE);
  MOTORS[2] = digitalRead(RIGHT_FRONT_MOVE);
  MOTORS[3] = digitalRead(RIGHT_BACK_MOVE);
  
radio.write(&MOTORS,sizeof(MOTORS));
delay(100);

}



RECEIVER CODE:

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

#define LMT1 5
#define LMT2 6
#define RMT1 7
#define RMT2 8

RF24 radio(9, 10);//CE,CSN

const byte address[6] = "mkinventions100";
void setup() {
radio.begin();
radio.openReadingPipe(0, address);
radio.startListening();

pinMode(LMT1, OUTPUT);
pinMode(LMT2, OUTPUT);
pinMode(RMT1, OUTPUT);
pinMode(RMT2, OUTPUT);
}

void loop() {
if(radio.available()){
  
  MOTORS();
}
}


void MOTORS(){
delay(100);
  
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, LOW); 
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, LOW); 
  
  int MOTORS[4];
  radio.read(&MOTORS,sizeof(MOTORS));

   //LEFT_FRONT_MOVE
    if(MOTORS[0] == 0){
    digitalWrite(LMT1, HIGH);
    digitalWrite(LMT2, LOW);
    }
  //LEFT_BACK_MOVE
    if(MOTORS[1] == 0){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, HIGH); 
    }

//RIGHT_FRONT_MOVE
    if(MOTORS[2] == 0){
    digitalWrite(RMT1, HIGH);
    digitalWrite(RMT2, LOW);
    }
    
  //RIGHT_BACK_MOVE
    if(MOTORS[3] == 0){
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, HIGH); 
    }
  }

Post a Comment

0 Comments