Rc car nrf24 I need help

Hello guys, I want help creating a sending and receiving code. I have a sender like this

I want the car to be based 2 DC motors L298N And the servo to direct the car left and right As you may have noticed, on the left side, the joystick only has one direction, which is up Both motors rotate in the same direction forward, But I want when I turn the toggle switch, the direction of the two motors will change. In normal mode, the car moves forward, but after the toggle switch is activated, the car moves backward on command from the joystick. When the joystick is at zero, the vehicle does not move even when the toggle switch is activated.

Not sure what you are asking but without an annotated schematic showing exactly how this is wired including power sources etc I cannot help. Also that is assuming the code is 100% which I doubt so posting that using code tags as outlined in the forum guidelines will help a lot.

1 Like

The usual way such RC-car remote controls work is that in middle-position the motors are off
if you push the stick away from your body drive forward
if you pull the stick closer to your body drive backward

So you don't need a switch for changing the direction.

At least you should google for
arduino nrf24 rc car remote control

to find a similar project

best regards Stefan

1 Like

Thank you, my brother, for the support, but the joystick is in the shape of controlling the drone, and it only moves from zero to the top, and I want to change the direction of the motor’s rotation when a toggleswitch is turned on.
In normal mode, when I lift the control stick from zero, the car moves forward
When it is returned to the zero point, the car's movement stops
But when I turn on the toggleswitch, the car goes in reverse
I want to make the toggle switch like a transmission in a car
Move forward and backward

Thank you, my brother, for the support,

Thank you, my brother, for the support
I will attach pictures

ا have this project but I need add another options

In default mode, when the joystick is lifted up the motor rotates to the right side, but I want to add a feature in the code so that when I activate the toggle switch and lift the joystick again to rotate the motor in the opposite direction,
Left direction. I don't want the motor to start. Once you turn the toggle switch, the joystick will be at zero.
When I turn the switch off, it goes back to the default position as in the original code
So a toggle switch is just a change in the directions of the motor

Transmitter code

// 6 Channel Transmitter | 6 Kanal Verici
  #include <SPI.h>
  #include <nRF24L01.h>
  #include <RF24.h>
  const uint64_t pipeOut = 0xE9E8F0F0E1LL;   //IMPORTANT: The same as in the receiver 0xE9E8F0F0E1LL | Bu adres alıcı ile aynı olmalı
  RF24 radio(9, 10); // select CE,CSN pin | CE ve CSN pinlerin seçimi
  struct Signal {
  byte throttle;
  byte pitch;
  byte roll;
  byte yaw;
  byte aux1;
  byte aux2;
};
  Signal data;
  void ResetData() 
{
  data.throttle = 12;   // Motor stop | Motor Kapalı (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.pitch = 127;    // Center | Merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.roll = 127;     // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.yaw = 127;     // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.aux1 = 127;    // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.aux2 = 127;    // Center | merkez (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_HIGH);
  radio.stopListening(); //start the radio comunication for Transmitter | Verici olarak sinyal iletişimi başlatılıyor
  ResetData();
 
}
  // Joystick center and its 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 doğru değerleri için ayar gerekebilir.
  data.throttle = mapJoystickValues( analogRead(A0), 12, 524, 1020, true );  // "true" or "false" for signal direction | "true" veya "false" sinyal yönünü belirler
  data.roll = mapJoystickValues( analogRead(A3), 12, 524, 1020, true );      // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
  data.pitch = mapJoystickValues( analogRead(A2), 12, 524, 1020, false );     // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
  data.yaw = mapJoystickValues( analogRead(A1), 12, 524, 1020, false );       // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler

  data.aux1 = mapJoystickValues( analogRead(A6), 12, 524, 1020, true );     // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
  data.aux2 = mapJoystickValues( analogRead(A7), 12, 524, 1020, true );     // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
  radio.write(&data, sizeof(Signal));
}

Receiver code

//  6 Channel Receiver | 6 Kanal Alıcı
//  PWM output on pins D2, D3, D4, D5, D6, D7 (Çı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;
int ch_width_4 = 0;
int ch_width_5 = 0;
int ch_width_6 = 0;

Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
Servo ch5;
Servo ch6;

struct Signal {
byte throttle;      
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
};

Signal data;

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

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

void setup()
{
  //Set the pins for each PWM signal | Her bir PWM sinyal için pinler belirleniyor.
  ch1.attach(2);
  ch2.attach(3);
  ch3.attach(4);
  ch4.attach(5);
  ch5.attach(6);
  ch6.attach(7);

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

  pinMode(6,OUTPUT);

}

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_4 = map(data.yaw,      0, 255, 1000, 2000);     // pin D5 (PWM signal)
ch_width_2 = map(data.pitch,    0, 255, 1000, 2000);     // pin D3 (PWM signal)
ch_width_3 = map(data.throttle, 0, 255, 1000, 2000);     // pin D4 (PWM signal)
ch_width_1 = map(data.roll,     0, 255, 1000, 2000);     // pin D2 (PWM signal)

ch_width_5 = map(data.aux1,     0, 255, 1000, 2000);     // pin D6 (PWM signal)
ch_width_6 = map(data.aux2,     0, 255, 1000, 2000);     // pin D7 (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);
ch4.writeMicroseconds(ch_width_4);
ch5.writeMicroseconds(ch_width_5);
ch6.writeMicroseconds(ch_width_6);
}

Your topic does not seem to indicate problems with the IDE and hence has been moved to a more suitable location on the forum.

I can see an attempt at code tags and hence have modified your post. Please use the <CODE/> button, not < and />.

I have merged your cross-posts @hichamdark4b.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I have deleted your other cross-post @hichamdark4b.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

You have to be much more precise in your description:
which joystick?
the left one
or
the right one

what do you mean by

???

What does this mean?

Car turning to left direction?
or
joystick turned to left direction?

You turn the joystick (to what direction??) and the motor shall NOT start?

How should turning the toggle-switch ever make the joystock move to his zero-position and if the toggle-switch would be able to turn the joystick (mechanically) what IS the zero-position for you?

there are so many places where you posted description is unprecise that there is plenty of room for interpretation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.