0% found this document useful (0 votes)
46 views

Bluetooth Code

This Arduino code defines variables to control the pins on a motor controller board. The setup function sets 4 pins as outputs to control 2 motors. The loop function reads serial input and uses if/else statements to set the pin values to control the motors for forward, backward, left, right and stop movements as well as diagonal movements based on the character received from serial.

Uploaded by

Akansha Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Bluetooth Code

This Arduino code defines variables to control the pins on a motor controller board. The setup function sets 4 pins as outputs to control 2 motors. The loop function reads serial input and uses if/else statements to set the pin values to control the motors for forward, backward, left, right and stop movements as well as diagonal movements based on the character received from serial.

Uploaded by

Akansha Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// Starting of Program

int m1a = 9;
int m1b = 10;
int m2a = 11;
int m2b = 12;
char val;

void setup() 
{  
pinMode(m1a, OUTPUT);  // Digital pin 10 set as output Pin
pinMode(m1b, OUTPUT);  // Digital pin 11 set as output Pin
pinMode(m2a, OUTPUT);  // Digital pin 12 set as output Pin
pinMode(m2b, OUTPUT);  // Digital pin 13 set as output Pin
Serial.begin(9600);
}

void loop()
{
  while (Serial.available() > 0)
 {
  val = Serial.read();
  Serial.println(val);
 }

  if( val == 'F') // Forward


  {
      digitalWrite(m1a, HIGH);
      digitalWrite(m1b, LOW);
      digitalWrite(m2a, HIGH);
      digitalWrite(m2b, LOW);  
  }
  else if(val == 'B') // Backward
  {
      digitalWrite(m1a, LOW);
      digitalWrite(m1b, HIGH);
      digitalWrite(m2a, LOW);
      digitalWrite(m2b, HIGH); 
  }
  
    else if(val == 'L') //Left
  {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, HIGH);
    digitalWrite(m2b, LOW);
  }
    else if(val == 'R') //Right
  {
    digitalWrite(m1a, HIGH);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW); 
  }
    
  else if(val == 'S') //Stop
  {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW); 
  }
  else if(val == 'I') //Forward Right
  {
    digitalWrite(m1a, HIGH);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW);
  }
  else if(val == 'J') //Backward Right
  {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, HIGH);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW);
  }
   else if(val == 'G') //Forward Left
  {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, HIGH);     digitalWrite(m2b, LOW);
  }
  else if(val == 'H') //Backward Left
  {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, HIGH); 
  }
}

You might also like