Pages: [1]   Go Down
Author Topic: Problems bluetooth connection between Android and Arduino!!!help me!!!  (Read 290 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone I am new to the forum.
I am planning a school for radio-controlled toy car with Arduino via Android and the problem that the mobile phone is not communicating with arduino
can anyone help me??  smiley-cry
this is the sketch:

Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1);

int forwardreverse = 10; // Pin 10 - Forward
int leftright = 11; // Pin 11 - Left
int frenable = 5; // Pin 5 - VAI (forward/reverse)
int lrenable = 6; // Pin 6 - VAI (left/right)



char val;  // Variabile riceve i dati tramite porta seriale

void setup() {

  // Inizzializzazione dei pin digitali come uscite
 
  pinMode(forwardreverse, OUTPUT);
  pinMode(leftright, OUTPUT);
  pinMode(frenable, OUTPUT);
  pinMode(lrenable, OUTPUT);
 
  mySerial.begin(115200);
  // Avviare la comunicazione seriale a 9600bps
}




// Fordward action +++++++VAI avanti o indietro +++++++++++++++++++++++
void go_forward() {
  digitalWrite(forwardreverse, HIGH);
  Serial.println ("VADO avanti o indietro");
}

// +++++++++STOP avanti o indietro ++++++++++++++++++++
void stop_go_forward() {
  digitalWrite(forwardreverse, LOW);
  Serial.println ("STOP avanti o indietro");
}



// %%%%%%%%%%%%VAI sinistra o destra%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void go_right() {
  digitalWrite(lrenable, HIGH);
  Serial.println ("GIRO");
}

// %%%%%%%%%%%%%%%STOP sinistra o destra%%%%%%%%%%%%%%%%%%%%%%%%%%%
void stop_turn() {
  digitalWrite(lrenable, LOW);
  Serial.println ("STOP giro");
}


// AVANTI ON  |  |  |  |  |scegli avanti|  |  |  |  |  |  |  |  |  |  |  |  |
void avanti_on() {
  digitalWrite(forwardreverse, HIGH);
  Serial.println ("ho scelto avanti");
}

// AVANTI OFF (indietro) |  |  |  scegli indietro|  |  |  |  |  |  |  |  |  |
void avanti_off() {
  digitalWrite(forwardreverse, LOW);
  Serial.println ("ho scelto indietro");
}

// SINISTRA ON -------------scegli sinistra----------------------------
void sinistra_on() {
  digitalWrite(leftright, HIGH);
  Serial.println ("ho scelto sinistra");
}

// SINISTRA OFF (destra) --------scegli destra-------------------------
void sinistra_off() {
  digitalWrite(leftright, LOW);
  Serial.println ("ho scelto destra");
}


 




// Lettura porta seriale ed eseguire il comando
  void performCommand() {
  if (mySerial.available()) {
    val = Serial.read();
    Serial.println("test");
 
    if (val == 'f') { // Avanti
      go_forward();
    } else if (val == 'z') { // Stop Avanti
      stop_go_forward();
    } else if (val == 'l') { // Destra
      go_right();
    } else if (val == 'v') { // Stop Girare
      stop_turn();
    } else if (val == 'a') { // Avanti 
      avanti_on();
    } else if (val == 'c') { // Indietro 
      avanti_off();
    } else if (val == 'd') { // Sinistra 
      sinistra_on();
    } else if (val == 'e') { // Destra 
      sinistra_off();
    }
}
}


void loop() {
  performCommand();
}
« Last Edit: June 26, 2013, 07:47:18 am by thefabiowanted1 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nobody has an idea to solve the problem?  smiley-cry
Logged

Pages: [1]   Go Up
Jump to: