NRF24L01 PART-5 || CONTROLING ROBOT || LED, SERVOS, DC-MOTORS
TRANSMITTER CIRCUIT DIAGRAM:
RECEIVER CIRCUIT DIAGRAM:
COMPONENTS REQUIRED:
1. NANO(2).
2. NRF24L01(2).
3. BATTERIES(2).
4. PUSH BUTTONS(4).
5. POTENTIOMETER(3).
6. SERVOS(3).
7. DC MOTORS(4).
8. MOTOR DRIVER (L298N/L293D).
9. SPDT TOGGEL SWITCH(3).
TRANSMITTER CODE:
#include<nRF24L01.h> #include<RF24.h> #include<SPI.h>
RF24 radio(9, 10);//CE,CSN
const byte address[6] = "000001"; //LIGHTS................................ int FRONT_LED = A0; int BACK_LED = A1;
//MOTORS................................ int LEFT_FRONT_MOVE = 4; int LEFT_BACK_MOVE = 5; int RIGHT_FRONT_MOVE = 6; int RIGHT_BACK_MOVE = 7;
//SERVOS................................ int SERVO = A2;
void setup() { radio.begin(); radio.openWritingPipe(address); radio.stopListening();
//LIGHTS................................ pinMode(FRONT_LED, INPUT); pinMode(BACK_LED, INPUT);
//MOTORS................................ pinMode(LEFT_FRONT_MOVE, INPUT_PULLUP); pinMode(LEFT_BACK_MOVE, INPUT_PULLUP); pinMode(RIGHT_FRONT_MOVE, INPUT_PULLUP); pinMode(RIGHT_BACK_MOVE, INPUT_PULLUP);
//SERVOS................................ pinMode(SERVO, INPUT); }
void loop() { int ROBOT[7];
//LIGHTS................................ ROBOT[0] = digitalRead(FRONT_LED); ROBOT[1] = digitalRead(BACK_LED); //SERVOS................................ ROBOT[2] = digitalRead(SERVO);
//MOTORS................................ ROBOT[3] = digitalRead(LEFT_FRONT_MOVE); ROBOT[4] = digitalRead(LEFT_BACK_MOVE); ROBOT[5] = digitalRead(RIGHT_FRONT_MOVE); ROBOT[6] = digitalRead(RIGHT_BACK_MOVE);
radio.write(&ROBOT,sizeof(ROBOT)); delay(100); }
|
RECEIVER CODE:
#include<nRF24L01.h> #include<RF24.h> #include<SPI.h> #include<Servo.h>
Servo myservo;
//LIGHTS................................ #define FRONT_LED A5 #define BACK_LED A0
//MOTORS................................ #define LMT1 5 #define LMT2 6 #define RMT1 7 #define RMT2 8
RF24 radio(9, 10);//CE,CSN
const byte address[6] = "000001"; void setup() { radio.begin(); radio.openReadingPipe(0, address); radio.startListening();
//LIGHTS................................ pinMode(FRONT_LED, OUTPUT); pinMode(BACK_LED, OUTPUT);
//SERVOS................................ myservo.attach(2);
//MOTORS................................ pinMode(LMT1, OUTPUT); pinMode(LMT2, OUTPUT); pinMode(RMT1, OUTPUT); pinMode(RMT2, OUTPUT); }
void loop() { if(radio.available()){ ROBOT(); } }
void ROBOT(){ delay(100);
//LIGHTS................................ digitalWrite(FRONT_LED, LOW); digitalWrite(BACK_LED, LOW);
//MOTORS................................ digitalWrite(LMT1, LOW); digitalWrite(LMT2, LOW); digitalWrite(RMT1, LOW); digitalWrite(RMT2, LOW);
//SERVOS................................ myservo.write(0);
int ROBOT[7]; radio.read(&ROBOT,sizeof(ROBOT));
//LIGHTS................................ if(ROBOT[0] == 0){ digitalWrite(FRONT_LED, HIGH);//FRONT_LIGHTS } if(ROBOT[1] == 0){ digitalWrite(BACK_LED, HIGH);//BACK_LIGHTS }
//........................................................... //SERVOS................................ if(ROBOT[2] == 0){//SERVO myservo.write(180); }
//........................................................... //MOTORS................................ if(ROBOT[3] == 0){//LEFT_FRONT_MOVE digitalWrite(LMT1, HIGH); digitalWrite(LMT2, LOW); } if(ROBOT[4] == 0){//LEFT_BACK_MOVE digitalWrite(LMT1, LOW); digitalWrite(LMT2, HIGH); }
if(ROBOT[5] == 0){//RIGHT_FRONT_MOVE digitalWrite(RMT1, HIGH); digitalWrite(RMT2, LOW); } if(ROBOT[6] == 0){//RIGHT_BACK_MOVE digitalWrite(RMT1, LOW); digitalWrite(RMT2, HIGH); } }
|
Comments
Post a Comment