This circuit is designed to interface an Arduino Nano with various peripherals including an NRF24L01 wireless transceiver module, a pushbutton, a potentiometer, a dual-axis joystick module, a toggle switch, a power supply consisting of two 18650 batteries, an AMS1117 3.3V voltage regulator, and a buzzer. The circuit is intended for wireless communication and control applications, with input devices for user interaction and a buzzer for audio feedback.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#define OLED_RESET -1
Adafruit_SH1106 display(OLED_RESET);
float vol = 0;
int input = 0;
int vdividerPin = A7;
const uint64_t pipeOut = 0xE8E8F0F0E1LL;
RF24 radio(10, 9); // select CE and CSN pins
struct MyData {
byte throttle;
byte yaw;
byte pitch;
byte roll;
byte AUX1;
byte AUX2;
};
MyData data;
unsigned long oledUpdateTime = 0;
const unsigned long oledUpdateInterval = 100;
void resetData()
{
data.throttle = 0;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;
data.AUX1 = 0;
data.AUX2 = 0;
}
void setup()
{
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipeOut);
resetData();
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(20,5);
display.println("Arduino Drone");
display.setCursor(15,19);
display.println("Transmitter By");
display.setCursor(0,33);
display.println("--> UnKnown <--");
display.setCursor(0,47);
display.println(">UnKnown & UnKnown<");
display.display();
delay(10000);
display.clearDisplay();
pinMode(vdividerPin, INPUT);
Serial.begin(9600);
pinMode(5, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
}
int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse)
{
val = constrain(val, lower, upper);
if ( val < middle )
val = map(val, lower, middle, 0, 128);
else
val = map(val, middle, upper, 128, 255);
return ( reverse ? 255 - val : val );
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - oledUpdateTime >= oledUpdateInterval) {
updateOLED();
oledUpdateTime = currentMillis;
}
data.throttle = mapJoystickValues( analogRead(A3), 13, 524, 1015, true );
data.yaw = mapJoystickValues( analogRead(A1), 50, 505, 1020, true );
data.pitch = mapJoystickValues( analogRead(A2), 12, 544, 1021, true );
data.roll = mapJoystickValues( analogRead(A6), 34, 522, 1020, true );
data.AUX1 = digitalRead(5);
data.AUX2 = digitalRead(3);
radio.write(&data, sizeof(MyData));
}
void updateOLED() {
input = analogRead(vdividerPin);
vol = (input * 10.0) / 1024.0;
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,5);
display.println("Voltage: ");
display.setCursor(0,30);
display.print(vol);
display.print(" V");
display.setTextSize(1);
display.setCursor(0,55);
display.print("-> BY UnKnown <-");
display.display();
delay(100);
}
The code for the second instance of the Arduino Nano is identical to the first instance. It is designed to work in tandem with the first instance for communication purposes. The code is omitted here for brevity, but it can be found in the provided input code section for the second microcontroller instance ID.
The provided code includes setup and loop functions that initialize the hardware components, read input values from the analog and digital pins, map these values to a data structure, and send the data wirelessly using the NRF24L01 module. The code also includes an OLED display update function to provide visual feedback of the system's voltage level.