12/21/2024

How To Make Remote Control For Model Car & Boat. DIY 3-Channel RC

Making 3-channel radio control.

Arduino Nano: https://www.banggood.com/custlink/vvGKUFyfT9
Arduino RF NANO: https://www.banggood.com/custlink/v3GELB0paw
NRF24L01 + PA Wireless Modul: https://www.banggood.com/custlink/33GGqGhQbZ
PCB Board: https://www.banggood.com/custlink/3vGmz3yNqC
100uF Capacitor: https://www.banggood.com/custlink/DKDvMvyQUe
2.4mm Pin: https://www.banggood.com/custlink/m3vGqKdnfN
680R Resistor: https://www.banggood.com/custlink/KKmmqOUaLl
5mm LED: https://www.banggood.com/custlink/vmKvMa2lL0
Rocker Switch : https://www.banggood.com/custlink/vDmv2ozlBY
PLA Filament: https://www.banggood.com/custlink/D33daggJ0h
Spring: https://bit.ly/3form0x

STL Files: https://drive.google.com/file/d/1xsQZGecMFXOWbQH1PZuGSjoayJRfRPIG/view?usp=sharing


RECEIVER:

 

Receiver Code For Arduino RF Nano:

//  3 Channel Receiver | 3 Kanal Alıcı
//  PWM output on pins D3, D5, D6 (Çıkış pinleri)

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

int ch_width_1 = 0;
int ch_width_2 = 0;
int ch_width_3 = 0;

Servo ch1;
Servo ch2;
Servo ch3;

struct Signal {
byte throttle;      
byte steering;
byte aux1;

};

Signal data;

const uint64_t pipeIn = 0xE9E8F0F0E1LL;
RF24 radio(10, 9); 

void ResetData()
{
// Define the inicial value of each data input. | Veri girişlerinin başlangıç değerleri
// The middle position for Potenciometers | Potansiyometreler için orta konum
data.steering = 127;   // Center | Merkez
data.throttle = 127;   // Motor Stop | Motor Kapalı
data.aux1 = 0;         // Center | Merkez
}

void setup()
{
  //Set the pins for each PWM signal | Her bir PWM sinyal için pinler belirleniyor.

  ch1.attach(3);
  ch2.attach(5);
  ch3.attach(6);

  //Configure the NRF24 module
  ResetData();
  radio.begin();
  radio.openReadingPipe(1,pipeIn);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening(); //start the radio comunication for receiver | Alıcı olarak sinyal iletişimi başlatılıyor
}

unsigned long lastRecvTime = 0;

void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(Signal));
lastRecvTime = millis();   // receive the data | data alınıyor
}
}
void loop()
{
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
ResetData(); // Signal lost.. Reset data | Sinyal kayıpsa data resetleniyor
}

ch_width_1 = map(data.steering, 0, 255, 1000, 2000);     // pin D3 (PWM signal)
ch_width_2 = map(data.throttle, 0, 255, 800, 2200);     // pin D5 (PWM signal)
ch_width_3 = map(data.aux1, 0, 1, 1000, 2000);           // pin D6 (PWM signal)

   // Write the PWM signal | PWM sinyaller çıkışlara gönderiliyor
ch1.writeMicroseconds(ch_width_1);
ch2.writeMicroseconds(ch_width_2);
ch3.writeMicroseconds(ch_width_3);
}

 

TRANSMITTER:

 

Transmitter Code For Arduino Nano:

// 3 Channel Transmitter | 3 Kanal Verici
  #include <SPI.h>
  #include <nRF24L01.h>
  #include <RF24.h>
  const uint64_t pipeOut = 0xE9E8F0F0E1LL;   // Match key | Eşleşme anahtarı
  RF24 radio(9, 10);                         // Select CE,CSN pin | CE ve CSN pinlerin seçimi
  struct Signal {
  byte throttle;
  byte steering;
  byte aux1;

};
  Signal data;
  void ResetData() 
{
  data.throttle = 127;     // Motor stop | Motor Kapalı (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.steering = 127;    //  Center | Merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.aux1 = 0;          //  (Signal lost position | sinyal kesildiğindeki pozisyon)

}
  void setup()
{
  //Start everything up
  radio.begin();
  radio.openWritingPipe(pipeOut);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.stopListening();             //start the radio comunication for Receiver | Verici olarak sinyal iletişimi başlatılıyor
  ResetData();
 
}
  // Joystick center and it's borders | Joystick merkez ve sınırları
  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()
{
  // Control Stick Calibration | Kumanda Kol Kalibrasyonları
  // Setting may be required for the correct values of the control levers. | Kontrol kollarının doğru değerleri için ayar gerekebilir.
  
  data.steering = mapJoystickValues( analogRead(A0), 200, 460, 650, true );    // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
  data.throttle = mapJoystickValues( analogRead(A1), 200, 440,670, true );    // "true" or "false" for signal direction | "true" veya "false" sinyal yönünü belirler
  data.aux1 = digitalRead(4); 
  radio.write(&data, sizeof(Signal));
}

Basic steps so you can upload the code to Arduino:

1- Download the Arduino IDE from www.arduino.cc.
2- Download the “.h” extension files to your computer in the lines starting with “include ” in the top line of the code. (These files are Library files. You can search by their names on Google and find them easily.)
3- Copy these files to “/Documents/Arduino/Libraries” folder.
4- Run Arduino IDE.
5- Copy the code to Arduino IDE.
6- Save the code.
7- Connect the Arduino to your computer with the USB cable.
8- Select the Arduino type and connection port from the Tools menu.
9- Upload the code to the arduino.

Example libraries file for NRF24L01:  https://github.com/maniacbug/RF24 (Different version library files may be required depending on the Arduino board. It can be found by trying)