salve a tutti, con arduino mega e hc-06 voglio comandare un led via smartphone ma caricando questo progetto :
#include <SoftwareSerial.h>
int rxPin = 3;
int txPin = 2;
SoftwareSerial bluetooth(rxPin, txPin);
String message; //string that stores the incoming message
const int Led = 13;
void setup()
{
Serial.begin(9600); //set baud rate
bluetooth.begin(9600); //set baud rate
pinMode(Led,OUTPUT);
}
void loop()
{
while(bluetooth.available()){
message+=char(bluetooth.read());
}
if(!bluetooth.available())
{
if(message!="")
{//if data is available
if(message == "H"){
digitalWrite(Led, HIGH);
Serial.println("Led ON"); //show the data
delay(20);
message=""; //clear the data
}
else if(message == "L"){
digitalWrite(Led, LOW);
Serial.println("Led OFF"); //show the data
delay(20);
message=""; //clear the data
}
}
}
}
il risultato è negativo... il cellulare si collega al Bluetooth ma non esegue nessuna funzione.
HO anche provato i comandi AT ma il Bluetooth non mi risponde:
#include <SoftwareSerial.h>
int rxPin = 3;
int txPin = 2;
SoftwareSerial bluetooth(rxPin, txPin);
String message; //string that stores the incoming message
void setup()
{
Serial.begin(9600);
bluetooth.begin(9600);
Serial.println("Lista dei comandi HC-06:\n");
Serial.println("AT Se la comunicazione funziona il modulo risponde OK");
Serial.println("AT+VERSION Restituisce la versione del firmware");
Serial.println("AT+BAUDx Imposta il Baudrate, al posto di x mettere 1 per 1200 bps, 2=2400, 3=4800, 4=9600, 5=19200, 6=38400, 7=57600, 8=115200, 9=230400, A=460800, B=921600, C=1382400");
Serial.println("AT+NAMEstring Al posto di string mettere il nome che vuoi dare al modulo (massimo 20 caratteri)");
Serial.println("AT+PINxxxx Imposta il pincode del modulo bluetooth (es.1234)");
}
void loop()
{
if (bluetooth.available())
{
Serial.write(bluetooth.read());
}
if (Serial.available())
{
bluetooth.write(Serial.read());
}
}
Spero che qualcuno mi può aiutare a risolvere il problema .