DIY Robots

Smartphone Bluetooth Controlled Robot

Code Section:

#include<SoftwareSerial.h>
SoftwareSerial BT(10,11);
String readData;
void setup()
{
BT.begin(9600);
Serial.begin(9600);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}

void loop() 
{
while (BT.available())
  {
    delay(10);
    char c=BT.read();
    readData +=c;
  }
  if(readData.length()>0)
{
      Serial.println(readData);
    
  if (readData=="forward")  
  {
    digitalWrite(6,HIGH); // right fwrd
    digitalWrite(7,HIGH); //left fwrd
    digitalWrite(9,LOW); //right bkwrd
    digitalWrite(8,LOW); // left bkwrd
    delay(100);
   }
  else if (readData=="reverse")  
  {
    digitalWrite(6,LOW);
    digitalWrite(7,LOW);
    digitalWrite(9,HIGH);
    digitalWrite(8,HIGH);
    delay(100);
   }
  else if (readData=="stop")  
  {
    digitalWrite(6,LOW);
    digitalWrite(7,LOW);
    digitalWrite(9,LOW);
    digitalWrite(8,LOW);
    delay(100);
   }
  else if (readData=="right")  
  {
    digitalWrite(6,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(9,HIGH);
    digitalWrite(8,LOW);
    delay(100);
   }
  else if (readData=="left")  
  {
    digitalWrite(6,HIGH);
    digitalWrite(7,LOW);
    digitalWrite(9,LOW);
    digitalWrite(8,HIGH);
    delay(100);
   }
   readData="";
}   
   
}

 

 

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Close
Back to top button
Close