77Views0Replies

Author Options:

i want to start and stop my line follower robot robot by blutooth Answered

please help me , i have no idea how to change it. i have line follower robot , and i want to operate my robot by blutooth , i want start and stop my line follower robot by blutooh ,my line follower robot code is

//code is

int rightmotor1=12;
int leftmotor1=13;
int rightmotor2=9;
int leftmotor2=8;


int sensorleft=5;
int sensorcenter=6;
int sensorright=7;


int l1=1;
int l2=1;
int l3=1;

int f1=0;
int f2=0;
int f3=0;

//////////////////////////////////////

void setup()
{

pinMode(rightmotor1,OUTPUT);
pinMode(leftmotor1,OUTPUT);
pinMode(rightmotor2,OUTPUT);
pinMode(leftmotor2,OUTPUT);

pinMode(sensorleft,INPUT);
pinMode(sensorcenter,INPUT);
pinMode(sensorright,INPUT);

}
///////////////////////////////////////////////////

void loop()
{
l1=digitalRead(sensorleft);
l2=digitalRead(sensorcenter);
l3=digitalRead(sensorright);

/////////////////////////////////////////////////////////////////////
if(l1==1&&l2==1&&l3==1)   //feedback when comes all sensor on white
{
l1=f1;
l2=f2;
l3=f3;
}

////////////////////////////////////////////////////////////////////////////
if(l1==0&&l2==1&&l3==1||l1==0&&l2==0&&l3==1)   //left turn
{
  digitalWrite(rightmotor1,1);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,0);
  digitalWrite(leftmotor2,0);
}
else
if(l1==1&&l2==1&&l3==0||l1==1&&l2==0&&l3==0)  //right turn
{
  digitalWrite(rightmotor1,0);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,1);
  digitalWrite(leftmotor2,0);
}
else
if(l1==1&&l2==0&&l3==1)  //go forward straight
{
  digitalWrite(rightmotor1,1);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,1);
  digitalWrite(leftmotor2,0);
}
else
if(l1==0&&l2==0&&l3==0) //stop
{
  digitalWrite(rightmotor1,0);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,0);
  digitalWrite(leftmotor2,0);
  delay(2000);
   digitalWrite(rightmotor1,1);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,1);
  digitalWrite(leftmotor2,0);
 
}

///////////////////////////////////////////////////////////////////
f1=l1;
f2=l2;
f3=l3;        //memory variables
////////////////////////////////////////////////////////////////////
} ,





i want to keep all code in function and want to call in blutoooh code


i want my robot start and stop by blutooth please help me
my blutooth code is

#include <SoftwareSerial.h>


SoftwareSerial mySerial(10, 11); // RX, TX
String state;// string to store incoming message from bluetooth
int  LED = 5; // LED on pin 13

void setup() {
mySerial.begin(9600);
Serial.begin(9600); // serial communication to check the data on serial monitor
   pinMode(LED, OUTPUT);

mySerial.println("Welcome to the wonderful world of bluetooth communication");
  delay(1000);
  mySerial.println("Sending a '1' will turn on the LED, Sending a '0' will turn off the LED");
  delay(1000);
  mySerial.println("a '3' will flash the LED and a '4' will kick out a lot of data from the LDR");


}
//-----------------------------------------------------------------------// 
void loop() {
  while (mySerial.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable
  char c = mySerial.read(); //Conduct a serial read
  state += c; //build the string- either "On" or "off"
  } 
  if (state.length() > 0) {
    Serial.println(state);


  if(state == "turn on")
  {
    digitalWrite(5, HIGH);
   
      }
 
  else if(state == "turn off")
  {
    digitalWrite(5, LOW);
     }
     else if(state == "turn1 on")
  {
    digitalWrite(5, HIGH);
   
      }
 
  else if(state == "turn2 off")
  {
    digitalWrite(5, LOW);
     }
 
 
state ="";}} //Reset the variable





i am using arduino atmega2560 and blutooth hc 06 and using  l298n 3 sensor

Discussions