TRANSMITTER CODE:-
#include<nRF24L01.h>
#include<RF24.h>
#include<SPI.h>
RF24 radio(9, 10);//CE,CSN
const byte address[6] = "000001";
int BUTTON1 = 5;
int BUTTON2 = 6;
int BUTTON3 = 7;
int BUTTON4 = 8;
int SWITCH1 = 4;
int SWITCH2 = 3;
int SWITCH3 = 2;
int SWITCH4 = 1;
int POTA = A0;
int POTB = A1;
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.stopListening();
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(BUTTON2, INPUT_PULLUP);
pinMode(BUTTON3, INPUT_PULLUP);
pinMode(BUTTON4, INPUT_PULLUP);
pinMode(SWITCH1, INPUT_PULLUP);
pinMode(SWITCH2, INPUT_PULLUP);
pinMode(SWITCH3, INPUT_PULLUP);
pinMode(SWITCH4, INPUT_PULLUP);
pinMode(POTA, INPUT);
pinMode(POTB, INPUT);
}
void loop() {
int ROBOT[10];
//DC ROBOT
ROBOT[0] = digitalRead(BUTTON1);
ROBOT[1] = digitalRead(BUTTON2);
ROBOT[2] = digitalRead(BUTTON3);
ROBOT[3] = digitalRead(BUTTON4);
//LEDS
ROBOT[4] = digitalRead(SWITCH1);
ROBOT[5] = digitalRead(SWITCH2);
ROBOT[6] = digitalRead(SWITCH3);
ROBOT[7] = digitalRead(SWITCH4);
// POTENTIOMETERS
ROBOT[8] = analogRead(POTA);
ROBOT[9] = analogRead(POTB);
radio.write(&ROBOT,sizeof(ROBOT));
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
#define LED1 A0
#define LED2 A1
RF24 radio(9, 10);//CE,CSN
const byte address[6] = "000001";
void setup() {
radio.begin();
radio.openReadingPipe(0, address);
radio.startListening();
pinMode(LMT1, OUTPUT);
pinMode(LMT2, OUTPUT);
pinMode(RMT1, OUTPUT);
pinMode(RMT2, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop() {
if(radio.available()){
ROBOT();
}
}
void ROBOT(){
delay(100);
digitalWrite(LMT1, LOW);
digitalWrite(LMT2, LOW);
digitalWrite(RMT1, LOW);
digitalWrite(RMT2, LOW);
int ROBOT[10];
radio.read(&ROBOT,sizeof(ROBOT));
int BUTTON1 = ROBOT[0];
int BUTTON2 = ROBOT[1];
int BUTTON3 = ROBOT[2];
int BUTTON4 = ROBOT[3];
int SWITCH1 = ROBOT[4];
int SWITCH2 = ROBOT[5];
int SWITCH3 = ROBOT[6];
int SWITCH4 = ROBOT[7];
int POTA = map(ROBOT[8], 0, 1023, 0, 255);
int POTB = map(ROBOT[9], 0, 1023, 0, 255);
//LEFT_FRONT_MOVE
if(BUTTON1 == 0){
digitalWrite(LMT1, HIGH);
digitalWrite(LMT2, LOW);
}
//LEFT_BACK_MOVE
if(BUTTON2 == 0){
digitalWrite(LMT1, LOW);
digitalWrite(LMT2, HIGH);
}
//RIGHT_FRONT_MOVE
if(BUTTON3 == 0){
digitalWrite(RMT1, HIGH);
digitalWrite(RMT2, LOW);
}
//RIGHT_BACK_MOVE
if(BUTTON4 == 0){
digitalWrite(RMT1, LOW);
digitalWrite(RMT2, HIGH);
}
//LED1 => A0
if(SWITCH1 == 1){
digitalWrite(LED1, HIGH);
}
if(SWITCH1 == 0){
digitalWrite(LED1, LOW);
}
//LED2 => A1
if(SWITCH2 == 1){
digitalWrite(LED2, HIGH);
}
if(SWITCH2 == 0){
digitalWrite(LED2, LOW);
}
}
0 Comments
Please do not Enter any Spam Link in the Comment Box
Emoji