Remote car with servos not working (pls help!)

Hello I was wandering if anyone could help me with a remote control car that I was making. I used pieces from other codes and when I got to testing it didn't work. Pls help.

Here is the code for the controller:

#include <ServoTimer2.h>

#include <SPI.h>

#include <RHReliableDatagram.h>

#include <RH_NRF24.h>

// Define the Joystick Connections
int joyY(0);
int joyX(1);

/*
  int joyposY = 512; //to use with the actual joystick
  int joyposX = 512;
*/

int valY;
int valX;

// Define addresses for radio channels
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

// Create an instance of the radio driver
RH_NRF24 RadioDriver;

// Sets the radio driver to NRF24 and the client address to 1
RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);

// Define the Message Buffer
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

ServoTimer2 myservo1;
ServoTimer2 myservo2;

//******************************************************************************

void setup() {

  // Setup Serial Monitor
  Serial.begin(9600);

  // Initialize RadioManager with defaults - 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!RadioManager.init())
    Serial.println("init failed");

  myservo1.attach(3);
  myservo2.attach(4);

}

//******************************************************************************

void loop() {

  if (valX < 460) // turn left
  {
    valY = analogRead(joyY);
    valY = map(valY, 0, 1023, 0, 180);
    valX = analogRead(joyX);
    valX = map(valX, 0, 1023, 0, 90);
    myservo1.write(valY - 2 * valX); // servo 1 slows
    myservo2.write(180 - valY);
    delay(15);
  }
  else if (valX > 564) // turn right
  {
    valY = analogRead(joyY);
    valY = map(valY, 0, 1023, 0, 180);
    valX = analogRead(joyX);
    valX = map(valX, 0, 1023, 0, 90);
    myservo1.write(valY);
    myservo2.write((180 - valY) - 2 * valX); // servo 2 slows
    delay(15);
  }

}

//******************************************************************************

And here is the car code:

#include <ServoTimer2.h>

#include <SPI.h>

#include <RHReliableDatagram.h>

#include <RH_NRF24.h>

// Define the Joystick Connections
int joyY(0);
int joyX(1);

/*
  int joyposY = 512; //to use with the actual joystick
  int joyposX = 512;
*/

int valY;
int valX;

// Define addresses for radio channels
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

// Create an instance of the radio driver
RH_NRF24 RadioDriver;

// Sets the radio driver to NRF24 and the client address to 1
RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);

// Define the Message Buffer
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

ServoTimer2 myservo1;
ServoTimer2 myservo2;

//******************************************************************************

void setup() {

  // Setup Serial Monitor
  Serial.begin(9600);

  // Initialize RadioManager with defaults - 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!RadioManager.init())
    Serial.println("init failed");

  myservo1.attach(3);
  myservo2.attach(4);

}

//******************************************************************************

void loop() {

  if (valX < 460) // turn left
  {
    valY = analogRead(joyY);
    valY = map(valY, 0, 1023, 0, 180);
    valX = analogRead(joyX);
    valX = map(valX, 0, 1023, 0, 90);
    myservo1.write(valY - 2 * valX); // servo 1 slows
    myservo2.write(180 - valY);
    delay(15);
  }
  else if (valX > 564) // turn right
  {
    valY = analogRead(joyY);
    valY = map(valY, 0, 1023, 0, 180);
    valX = analogRead(joyX);
    valX = map(valX, 0, 1023, 0, 90);
    myservo1.write(valY);
    myservo2.write((180 - valY) - 2 * valX); // servo 2 slows
    delay(15);
  }

}

//******************************************************************************

Pls help I have been trying to get it ti work for ages and I have got no results. I am using two nRF24LO1s , two DSO4-NFC servos , and two arduino nanos. I have the joystick to control it swapped out with two 10K potentiometers until it arrives.

Thank you!

Jethro Crooke

Why has the controller got servos?

the car has the servos

The code for the controller has servo code, but no radio code.

the controller has the code for the car on it and it controls the car(or at least that's what I saw on a video on YouTube)

could you tell me what to do for the radio code

sorry I'm a bit hopeless when it come to transmitting and receiving

No, because I don't understand what you're doing.

What are the pots being read in the car code?

I am trying to make a remote control car controlled by a joystick. the turning mechanism will be one of the two servos slowing down.

I am not sure what you mean

do you mean what type?

Maybe watch the video again?

ill try that and see if I can see any code that I missed out

I look at this:

And here is the car code:
.

void loop() {
.
.
.
  if (valX < 460) // turn left
  {
    valY = analogRead(joyY);
    valY = map(valY, 0, 1023, 0, 180);
    valX = analogRead(joyX);
    valX = map(valX, 0, 1023, 0, 90);
[/quote]

they are the X and Y axis of the joystick

I think the question is "why does the car have a joystick?"

(It's akin to my earlier question "Why does the controller have servos?")

I don't know all I did was change the dc motor codes to servo code

God night. Time to take on other questions.

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