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

Bluetooth Code - Version2 3 With LED and Buzzer

This document contains code for controlling a robot using serial communication. It defines pin assignments for motors, lights and a buzzer. The setup function sets the pins as outputs. The loop continuously reads serial input and controls the motors, lights and buzzer based on the received character command. Commands include forward, backward, left, right and stopping the motors as well as turning on/off the buzzer and flashing lights.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Bluetooth Code - Version2 3 With LED and Buzzer

This document contains code for controlling a robot using serial communication. It defines pin assignments for motors, lights and a buzzer. The setup function sets the pins as outputs. The loop continuously reads serial input and controls the motors, lights and buzzer based on the received character command. Commands include forward, backward, left, right and stopping the motors as well as turning on/off the buzzer and flashing lights.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Starting of Program

int BUZ = 6;
int RED = 7;
int BLU = 8;
int m1a = 9;
int m1b = 10;
int m2a = 11;
int m2b = 12;
char val;

void setup() 
{  
pinMode(BUZ, OUTPUT);  // Digital pin 6 set as output Pin
pinMode(RED, OUTPUT);  // Digital pin 7 set as output Pin
pinMode(BLU, OUTPUT);  // Digital pin 8 set as output Pin
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); 
    }
if( val == 'V') // Buzzer on
    {
      digitalWrite(BUZ, HIGH);
      delay (1000);
      digitalWrite(BUZ, LOW);
      delay (1000); 
    }
  else if(val == 'v') // Buzzer off
    {
      digitalWrite(BUZ, LOW);
      
    }
if( val == 'U') // Back lights on
    {
      digitalWrite(RED, HIGH);
      delay (500);
      digitalWrite(RED, LOW);
      delay (500); 
digitalWrite(BLUE, HIGH);
      delay (500);
      digitalWrite(BLU, LOW);
      delay (500); 

    }
  else if(val == 'u') // Back lights off
    {
      digitalWrite(RED, LOW);
      
    }

You might also like