RogerGold
Published © CC BY-NC-SA

CARMAGEDDON: The Agile Arduino Car

A simple and easy to assemble car controlled via smartphone using bluetooth technology.

BeginnerShowcase (no instructions)6,922
CARMAGEDDON: The Agile Arduino Car

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Arduino MotorShield Rev3
Arduino MotorShield Rev3
×1
HC-06 Bluetooth Module
×1
4xAA Battery Holder - 2xDC Motors - 2xWheels - Frame - Wires
×1
2xAA Battery Holder
×1
Rechargeable Battery AA
×6
Male/Female Jumper Wires
Male/Female Jumper Wires
Four jumpers needed
×1
Slide Switch
Slide Switch
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Carmageddon's Body.fzz

Code

Carmageddon's Head.ino

C/C++
char command;                  
int const directionA = 12;		   
int const directionB = 13;
int const speedA = 3;		                    //A is the left wheel, B is the right one
int const speedB = 11;
int const brakeA = 9;			   
int const brakeB = 8;
bool flagBackward;

void setup() {
  Serial.begin(9600);          
  pinMode(directionA, OUTPUT);
  pinMode(directionB, OUTPUT);
  pinMode(speedA, OUTPUT);             
  pinMode(speedB, OUTPUT);
  pinMode(brakeA, OUTPUT);
  pinMode(brakeB, OUTPUT);
}

void loop() {

  if (Serial.available() > 0) {             

    command = Serial.read();                 

    switch (command) {
      case ('='):                                //stop command
        flagBackward = false;
        analogWrite(speedA, 0);
        analogWrite(speedB, 0);
        digitalWrite(brakeA, HIGH);
        digitalWrite(brakeB, HIGH);
        break;

      case ('F'):                               //forward command
        flagBackward = false;
        digitalWrite(brakeA, LOW);	   
        digitalWrite(brakeB, LOW);
        digitalWrite(directionA, LOW);	
        digitalWrite(directionB, LOW);
        analogWrite(speedA, 255);
        analogWrite(speedB, 255);
        break;

      case ('B'):                               //backward command
        flagBackward = true;
        digitalWrite(brakeA, LOW);
        digitalWrite(brakeB, LOW);
        digitalWrite(directionA, HIGH);
        digitalWrite(directionB, HIGH);
        analogWrite(speedA, 255);
        analogWrite(speedB, 255);
        break;

      case ('R'):                               //right command
        digitalWrite(brakeA, LOW);
        digitalWrite(brakeB, HIGH);
        if (flagBackward == false) {
          digitalWrite(directionA, LOW);
        } else {
          digitalWrite(directionA, HIGH);
        }
        digitalWrite(directionB, HIGH);
        analogWrite(speedA, 255);
        analogWrite(speedB, 0);
        break;

      case ('L'):                               //left command
        digitalWrite(brakeA, HIGH);
        digitalWrite(brakeB, LOW);
        digitalWrite(directionA, HIGH);
        if (flagBackward == false) {
          digitalWrite(directionB, LOW);
        } else {
          digitalWrite(directionB, HIGH);
        }
        analogWrite(speedA, 0);
        analogWrite(speedB, 255);
        break;

    }
  }
}

Credits

RogerGold

RogerGold

1 project • 1 follower

Comments