Go Down

Topic: help with my bluetooth car project (Read 877 times) previous topic - next topic

anshchawla

Code: [Select]

int left1=2;
int left2=3;
int right1=4;
int right2=5;


char inSerial[15];

void setup(){
  Serial.begin(9600);
  pinMode(left1, OUTPUT);
  pinMode(left2, OUTPUT);
  pinMode(right1, OUTPUT);
  pinMode(right2, OUTPUT);
  pinMode(0, INPUT);
  pinMode(A3,INPUT);
  pinMode(A2,INPUT);
  pinMode(13,OUTPUT);

 
  }

void loop(){
    int i=0;
    int m=0;
                                       
    if (Serial.available() > 0) {             
       while (Serial.available() > 0) {
         inSerial[i]=Serial.read();
         i++;     
       }
       inSerial[i]='\0';
      Check_Protocol(inSerial);}
      }
       
 
void Check_Protocol(char inStr[]){   
  int i=0;
  int m=0;
 
  if(!strcmp(inStr,"front")){
    digitalWrite(13,HIGH);
    Serial.println("front");
    digitalWrite(left1, HIGH);
    digitalWrite(left2, LOW);
    digitalWrite(right1, HIGH);
    digitalWrite(right2, LOW);
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}
       else if(!strcmp(inStr,"back")){
    digitalWrite(13,LOW);
    Serial.println("back");
    digitalWrite(left2, HIGH);
    digitalWrite(left1, LOW);
    digitalWrite(right2, HIGH);
    digitalWrite(right1, LOW);     
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;} else if(!strcmp(inStr,"left")){
     digitalWrite(13,HIGH);     
    digitalWrite(left1, HIGH);
    digitalWrite(left2, LOW);
    digitalWrite(right2, HIGH);
    digitalWrite(right1, LOW);
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}else if(!strcmp(inStr,"right")){
    digitalWrite(13,LOW);     
    digitalWrite(left2, HIGH);
    digitalWrite(left1, LOW);
    digitalWrite(right1, HIGH);
    digitalWrite(right2, LOW);
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;} else if(!strcmp(inStr,"stop")==0){
      digitalWrite(13,LOW);
    digitalWrite(left1, LOW);
    digitalWrite(left2, LOW);
    digitalWrite(right1, LOW);
    digitalWrite(right2, LOW);
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}   
    else{
    for(m=0;m<11;m++){
      inStr[m]=0;
    }
    i=0;

}}


this is my code i dont know why it is not working i am using an hc05 bluetooth module with its tx pin connected to pin0 of my arduino pro mini and if i connect my bluetooth module to usb to ttl converter and check if it recieves data from my phone at the right baud rate it does i dont know why then the arduino has problem with it
 

wvmarle

Please format your code so it doesn't look too much like an entry to the obfuscated C contest. This is pretty unreadable.

Also make sure your Arduino receives what you think it receives - connect your Bluetooth module to another pair of pins and use SoftwareSerial so you can use the regular Serial interface for debugging. For the final version of your project you can always switch back to using the hardware Serial interface for the HC-05 but first you have to make sure what is in those strings is what you think is there.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up