Hassaan Akbar
Published © MIT

Smartphone Controlled Car with Proportional Speed Control

Arduino based car controlled by smartphone app using virtual joystick.

IntermediateFull instructions provided1,738
Smartphone Controlled Car with Proportional Speed Control

Things used in this project

Software apps and online services

BlueDuino

Story

Read more

Schematics

Motor Driver Circuit

File missing, please reupload.

Code

Reading a Chunk of Data From the App

Plain text
String ReadLine()
{
  String s;
  char c;

  while (1)
  {
    if (Serial.available())
    {
      c = Serial.read();
      if (c == '*')
      {
        continue;
      }
      else if (c == '#')
      {
        return s;
      }
      else
      {
        s += c;
      }
    }
  }
}

Getting Joystick Position

Plain text
void UpdateAxis(int *x, int *y, String chunk)
{
  String s1, s2;
  bool comma;

  if (s.length() != 3) return;

  *x = (int)(byte)s[0] - 127;
  *y = (int)(byte)s[2] - 127;
}

Translate Joystick Coordinates to Motor Speeds

Plain text
void ToDifferentialDrive(int xValue, int yValue)
{
    if (yValue > 0)
  {
    if (xValue < 0)
    {
      left = mag + (HANDLING * xValue);
      right = mag;
    }
    else
    {
      left = mag;
      right = mag - (HANDLING * xValue);
    }
  }
  else
  {
    if (xValue < 0)
    {
      left = -mag;
      right = -mag - xValue;
    }
    else
    {
      left = -mag + xValue;
      right = -mag;
    }
  }
}

Driving Motor

Plain text
void DriveMotor(int motor, int spd, int maxSpeed)
{
  spd = 255 * ((double)spd / maxSpeed);
  
  Serial.print(spd);
  Serial.print(" === \t");
  if (spd > 0)
  {
    analogWrite(motorPins[motor][0], spd);
    digitalWrite(motorPins[motor][1], LOW);
  }
  else
  {
    analogWrite(motorPins[motor][0], (255 + spd));
    digitalWrite(motorPins[motor][1], HIGH);
  }
}

Github

Credits

Hassaan Akbar

Hassaan Akbar

1 project • 0 followers
Geek

Comments