The circuit consists of two Arduino UNO microcontrollers, each interfaced with an NRF24L01 radio module. Additionally, the circuit includes two push switches, four red LEDs, and two servos. The purpose of the circuit is to demonstrate wireless communication between the two Arduinos using the NRF24L01 modules, where one Arduino acts as a transmitter and the other as a receiver. The transmitter Arduino sends signals upon button presses, which are received by the receiver Arduino to control servos and LEDs.
/*RF24 radio module:
CE: Pin 9
CSN: Pin 10
Servos:
Servo1: Pin 3
Servo2: Pin 5
LEDs:
LED1: Pin 6
LED2: Pin 7
* This Arduino Sketch receives signals from an NRF24L01 module.
* If the received signal is 'A', it turns Servo1 from 0 to 90 degrees and back to 0.
* If the received signal is 'B', it turns Servo2 from 0 to 90 degrees and back to 0.
* Additionally, if the received signal is 'A', it turns on LED1.
* If the received signal is 'B', it turns on LED2.
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(9, 10); // CE, CSN pins
const byte address[6] = "00001";
Servo servo1;
Servo servo2;
const int led1Pin = 6; // LED1 connected to pin 6
const int led2Pin = 7; // LED2 connected to pin 7
void setup() {
servo1.attach(3); // Attach Servo1 to pin 3
servo2.attach(5); // Attach Servo2 to pin 5
pinMode(led1Pin, OUTPUT); // Set LED1 pin as output
pinMode(led2Pin, OUTPUT); // Set LED2 pin as output
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
if (text[0] == 'A') {
servo1.write(90);
digitalWrite(led1Pin, HIGH); // Turn on LED1
delay(1000);
servo1.write(0);
digitalWrite(led1Pin, LOW); // Turn off LED1
} else if (text[0] == 'B') {
servo2.write(90);
digitalWrite(led2Pin, HIGH); // Turn on LED2
delay(1000);
servo2.write(0);
digitalWrite(led2Pin, LOW); // Turn off LED2
}
}
}
/*
* This Arduino Sketch transmits signals using an NRF24L01 module.
* If button B1 is pressed, it sends the signal 'A' and turns on LED L1.
* If button B2 is pressed, it sends the signal 'B' and turns on LED L2.
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN pins
const byte address[6] = "00001";
const int button1Pin = 2; // B1 connected to pin 2
const int button2Pin = 3; // B2 connected to pin 3
const int led1Pin = 4; // L1 connected to pin 4
const int led2Pin = 5; // L2 connected to pin 5
void setup() {
pinMode(button1Pin, INPUT_PULLUP); // Set B1 pin as input with pull-up
pinMode(button2Pin, INPUT_PULLUP); // Set B2 pin as input with pull-up
pinMode(led1Pin, OUTPUT); // Set L1 pin as output
pinMode(led2Pin, OUTPUT); // Set L2 pin as output
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
if (digitalRead(button1Pin) == LOW) {
const char text[] = "A";
radio.write(&text, sizeof(text));
digitalWrite(led1Pin, HIGH); // Turn on L1
delay(500); // Debounce delay
digitalWrite(led1Pin, LOW); // Turn off L1
}
if (digitalRead(button2Pin) == LOW) {
const char text[] = "B";
radio.write(&text, sizeof(text));
digitalWrite(led2Pin, HIGH); // Turn on L2
delay(500); // Debounce delay
digitalWrite(led2Pin, LOW); // Turn off L2
}
}