Go Down

Topic: Problems bluetooth connection between Android and Arduino!!!help me!!! (Read 334 times) previous topic - next topic

thefabiowanted1

Jun 26, 2013, 10:50 am Last Edit: Jun 26, 2013, 02:47 pm by thefabiowanted1 Reason: 1
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??  =(
this is the sketch:

Code: [Select]

#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();
}

thefabiowanted1


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy