Jonathan Loong
Published © GPL3+

DIY RC Car

Arduino-powered DIY remote control car!

IntermediateWork in progress10 hours1,110
DIY RC Car

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Lipo 2S 2200mAh
×1
Toggle Switch, (On)-Off-(On)
Toggle Switch, (On)-Off-(On)
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Resistor 220 ohm
Resistor 220 ohm
×2
915MHz 3DR Telemetry Radio
×2
Jumper wires (generic)
Jumper wires (generic)
×1
King Kong 5V/3A BEC
×1
DC-DC Step Down Converter
×1
Truggy RC 4WD Car Chassis
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires

Story

Read more

Schematics

RC Car Block Diagram

System diagram for RC car showing power converters and signal/IO and connections to drivetrain

Code

RC Car Receiver Code

Arduino
This code takes in the telemetry from the car-side radio and parses it into usable throttle and steer values for actuation.
// Hardware Serial to receive XBOX input from 915 MHz telemetry link and
// actuate steering and throttle servos

// Adapted from https://forum.arduino.cc/t/serial-input-basics-updated/382007/3

#include <Servo.h> 
#include <SoftwareSerial.h>

const int numChars = 32;
char receiveArray[numChars];
char tempArray[numChars];
int char_ctr = 0;
char stopMarker = '#'; //stop byte is # symbol

//parsed input from XBOX
int currSteer = 0;
int currThrottle = 0;

boolean newData = false;

// Defining hardware pins
#define MOTOR_PWM 3   //Motor for propulsion 
#define SERVO_PWM 5   //Servo for steering. (to calibrate) 

#define PWM_TOP 1200
#define PWM_BOT 1000
#define PWM_MID 1500
#define LED 2

Servo driveMotor;
Servo steerServo;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  pinMode(LED,OUTPUT);
  analogWrite(LED,140);

  driveMotor.writeMicroseconds(PWM_BOT);
  steerServo.writeMicroseconds(PWM_MID);

  driveMotor.attach(MOTOR_PWM);
  steerServo.attach(SERVO_PWM);
  delay(1000);
}

void parseData() {      // split the data into its parts in CSV format

    char * strtokIndx; // this is used by strtok() as an index

    strtokIndx = strtok(tempArray, ",");
    currThrottle = atoi(strtokIndx);   

    strtokIndx = strtok(NULL, ",");
    currSteer = atoi(strtokIndx);     

}

void actuateRC() {
    //Serial.print("Throttle ");
    //Serial.print(currThrottle);
    //Serial.print(",Steering ");
    //Serial.println(currSteer);
    
    // actuate servos from input
    if (currThrottle >= PWM_TOP) currThrottle = PWM_TOP; //set max threshold to prevent motor burnout
    steerServo.writeMicroseconds(currSteer);
    driveMotor.writeMicroseconds(currThrottle);

}

void loop()
{
  
  ///*
  while (Serial.available() > 0 && newData == false)
  {
    char rc = Serial.read();
    //Serial.println(rc);

    if (rc != stopMarker)
    {
      receiveArray[char_ctr] = rc;
      char_ctr++;
      if (char_ctr >= numChars) char_ctr = numChars - 1;
    }
    // at stopMarker
    else 
    {
      receiveArray[char_ctr] = '\0'; //null terminate string
      char_ctr = 0;
      newData = true;
    }        
  }

  if (newData == true) {
        strcpy(tempArray, receiveArray);
            // this temporary copy is necessary to protect the original data
            //   because strtok() used in parseData() replaces the commas with \0
        parseData();
        actuateRC();
        newData = false;
    }
  //*/

//  if (rcSerial.available() > 0)
//    Serial.println(rcSerial.read());
    
  delay(50);
}

Credits

Jonathan Loong
2 projects • 3 followers
Mechatronics Engineer | UAV Enthusiast
Contact

Comments

Please log in or sign up to comment.