BLUETOOTH CONTROLLED ROBOT CAR

CIRCUIT DIAGRAM

Bluetooth control robot car

 

PROGRAMMING CODE

int R1 = 4, R2 = 5, L1 = 6, L2 = 7;
void setup() {
  Serial.begin(9600);
  pinMode(R1, OUTPUT);
  pinMode(R2, OUTPUT);
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    char c = Serial.read();
    Serial.print("INPUT : ");
    Serial.println(c);
    if (c == 'f') {
      Serial.println("FORWARD");
      f();
    }
    else if (c == 'b') {
      Serial.println("BACKWARD");
      b();
    }
    else if (c == 'r') {
      Serial.println("RIGHT");
      r();
    }
    else if (c == 'l') {
      Serial.println("LEFT");
      l();
    }
    else if (c == 's') {
      Serial.println("STOP");
      s();
    }
    else {
      Serial.println("Default");
      s();
    }
    
  } // END OF SERIAL AVAILABLE
} // END OF LOOP

void f() {
  digitalWrite(L1, HIGH);
  digitalWrite(L2, LOW);
  digitalWrite(R1, HIGH);
  digitalWrite(R2, LOW);
}
void b() {
  digitalWrite(L1, LOW);
  digitalWrite(L2, HIGH);
  digitalWrite(R1, LOW);
  digitalWrite(R2, HIGH);
}
void l() {
  digitalWrite(L1, LOW);
  digitalWrite(L2, LOW);
  digitalWrite(R1, HIGH);
  digitalWrite(R2, LOW);
}
void r() {
  digitalWrite(L1, HIGH);
  digitalWrite(L2, LOW);
  digitalWrite(R1, LOW);
  digitalWrite(R2, LOW);
}
void s() {
  digitalWrite(L1, LOW);
  digitalWrite(L2, LOW);
  digitalWrite(R1, LOW);
  digitalWrite(R2, LOW);
}

 

Leave a Reply

avatar
  Subscribe  
Notify of

Arduino Tutorials with Basic Electronics: CONTENT

Translate »