RC Car Control Over Cloud

Hi Sparkers,

I made the very first prototype of my internet controlled Car. Because Im lack of knowledge in electronics, it was a little bit hard to find out how to reverse dc motor direction. Luckly I have heard about motor controllers before and after juggling with transistors I have ended up with L293D today.

Here is a video of my first demo:

It’s a mess of cables!

Firmware code:

    /* A Spark function to parse the commands */
    int rcCarControl(String command);
    
/* Globals -------------------------------------------------------------------*/
int leftMotor    = A6;
int rightMotor   = A7;
int forwardMotor   = D6;
int backwardMotor  = D7;


void setup()
{
  //Register Spark function
  Spark.function("rccar", rcCarControl);

  pinMode(forwardMotor, OUTPUT);
  pinMode(backwardMotor, OUTPUT);
  pinMode(leftMotor, OUTPUT);
  pinMode(rightMotor, OUTPUT);

}

void loop()
{
  // Nothing to do here
}

//Using a bit to store commands
// 1 : LEFT, 5 : FORWARD and LEFT
// 0000 0001, 0000 0101
 const byte LEFT = 1;
 const byte RIGHT = 2;
 const byte FORWARD = 4;
 const byte BACKWARD = 8;
 
 
int rcCarControl(String command)
{
    
    byte cmd = command.toInt();
    
    if(cmd == 0){
        digitalWrite(forwardMotor,LOW);
        digitalWrite(backwardMotor,LOW);
        
        digitalWrite(leftMotor,LOW);
        digitalWrite(rightMotor,LOW);
        
        return 1;
    }
    
    //eg: cmd = 0110 -> 0110 & 0100 = 0100 -> true
    if((cmd & FORWARD) == FORWARD)
    {
        digitalWrite(backwardMotor,LOW);
        digitalWrite(forwardMotor,HIGH);
    } 
    else if((cmd & BACKWARD) == BACKWARD)
    {
        digitalWrite(forwardMotor,LOW);
        digitalWrite(backwardMotor,HIGH);
    }
    else{
        digitalWrite(forwardMotor,LOW);
        digitalWrite(backwardMotor,LOW);
    }
    
    if((cmd & LEFT) == LEFT)
    {
        digitalWrite(rightMotor,LOW);
        digitalWrite(leftMotor,HIGH);
    } 
    else if((cmd & RIGHT) == RIGHT)
    {
        digitalWrite(leftMotor,LOW);
        digitalWrite(rightMotor,HIGH);
    }
    else
    {
        digitalWrite(leftMotor,LOW);
        digitalWrite(rightMotor,LOW);
    }
    


    
        return 1;
    }
2 Likes

Nice! What car body are you using?

Thanks @Dave.

It’s a really cheap rc car. 1:16 scale. Costs about 10 dollars. I couldnt find any information on the internet.

Great project!
Could you post the code that you are running on the PC to control the car? I am new to network programming and sockets in particular.

Ok, I’m seing now that the example in this thread is not the one using socket. But you mention this project here: enter link description here And that it later got changed to using socket. I thoulght it would be better to post the questions in the original thread.

Is the PC acting as a server or a client in this example?

Hello, @triuman could you share a wiring diagram?
Thanks

1 Like