MJRoBot (Marcelo Rovai)
Published © GPL3+

Hacking A RC Car To Control It Using An Android Device

Let's disassemble one RC toy car, racking its main parts, replacing the original embedded electronics by an Arduino.

BeginnerFull instructions provided12 hours63,220
Hacking A RC Car To Control It Using An Android Device

Things used in this project

Story

Read more

Schematics

AutoBot electric diagram

Code

Code snippet #1

Plain text
void loop() 
{
  checkBTcmd();  // verify if a comand is received from BT remote control
  receiveCmd ();
  
  if (turnOn) manualCmd ();
  else stopRobot ();
}

Code snippet #2

Plain text
 void checkBTcmd()  
 { 
    if (BT1.available()) 
    { 
      command = BT1.read();
      BT1.flush();
    }
 }
 

Code snippet #3

Plain text
void receiveCmd ()
{
  
  switch (command)
  {
    case 'p': 
      Serial.println("command ==> p"); 
      turnOn = !turnOn;
      command = 0;
      analogWrite(ledStatus, turnOn*128); // Robot ON - Led ON
      beep(outBuz, 1000, 100);
      BT1.print(" COMMAND ON/OFF");
      BT1.println('\n');
      delay(200); //Delay to call attention to mode change
      break;
      
   case 'm': //not used here
      break;
  }   
}

Code snippet #4

Plain text
void manualCmd()
{
  switch (command)
  {
    case 'f': 
      moveStop(); //turn off both motors
      state = command;
      break;

    case 'w':  
      moveForward(); 
      state = command;  
      break;

    case 'd':     
      moveRight();
      break;

   case 'a': 
      moveLeft();
      break;
    
    case 's':  
      moveBackward();
      state = command;
      break;

    case '+': 
      if (state == 'w')
      {
        motorSpeed = motorSpeed + 10;
        if (motorSpeed > MAX_SPEED) 
        { 
          motorSpeed = MAX_SPEED;
        }  
        command = 'w';
      } else {command = state;}
      break;

    case '-': 
 
      if (state == 'w')
      {
        motorSpeed = motorSpeed - 10;
      }     
      if (motorSpeed < MIN_SPEED ) 
      { 
        motorSpeed = MIN_SPEED;
      }
      Serial.println(motorSpeed); 
      command = state;
      break;
  }
}

Code snippet #5

Plain text
void moveForward() // rear motor FW
{ 
  analogWrite(rearMtEne, motorSpeed);
  digitalWrite(rearMtFw, HIGH);
  digitalWrite(rearMtBw, LOW);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, LOW);
  delay(5);
}

Code snippet #6

Plain text
void stopRobot ()
{
  digitalWrite(ledBlue, LOW);
  digitalWrite(ledRed, LOW);
  
  state = 0;
  moveStop(); //turn off both motors
}

Code snippet #7

Plain text
// Motor Drives
const int rearMtFw = 4;     // Rear Motor  - FW
const int rearMtBw = 7;     // Rear Motor  - BW
const int rearMtEne = 6;    // Rear Motor  - enable
const int frontMtLeft = 2;  // Front Motor - turn Left
const int frontMtRight = 3; // Front Motor - turn right 
const int frontMtEne = 5;   // Front Motor enable

Code snippet #8

Plain text
void moveForward() // rear motor FW
{ 
  analogWrite(rearMtEne, motorSpeed);
  digitalWrite(rearMtFw, HIGH);
  digitalWrite(rearMtBw, LOW);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, LOW);
  delay(5);
}

Code snippet #9

Plain text
void moveBackward() // rear motor BW
{ 
  analogWrite(rearMtEne, motorSpeed);
  digitalWrite(rearMtFw, LOW);
  digitalWrite(rearMtBw, HIGH);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, HIGH);
  delay(5);
}

Code snippet #10

Plain text
void moveLeft() // front motor left
{ 
  digitalWrite(frontMtEne, HIGH);
  digitalWrite(frontMtLeft, HIGH);
  digitalWrite(frontMtRight, LOW);
  digitalWrite(ledRed, LOW);
  delay(10);
}

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

void moveRight() // front motor right
{ 
  digitalWrite(frontMtEne, HIGH);
  digitalWrite(frontMtLeft, LOW);
  digitalWrite(frontMtRight, HIGH);
  digitalWrite(ledRed, LOW);
  delay(10);
}

Code snippet #11

Plain text
void stopRobot ()
{
  digitalWrite(ledBlue, LOW);
  digitalWrite(ledRed, LOW);
  
  state = 0;
  moveStop(); //turn off both motors
}

Github

https://github.com/Mjrovai/MJRoBot-AutoBot

Credits

MJRoBot (Marcelo Rovai)

MJRoBot (Marcelo Rovai)

59 projects • 905 followers
Professor, Engineer, MBA, Master in Data Science. Writes about Electronics with a focus on Physical Computing, IoT, ML, TinyML and Robotics.

Comments