NN

NN

#include <SoftwareSerial.h>
SoftwareSerial BT(5, 6);
String readString;

void setup()  
{
  // set digital pin to control as an output
  pinMode(13, OUTPUT);
  // set the data rate for the SoftwareSerial port
  BT.begin(9600);
  // Send test message to other device
  BT.println("Hello from Arduino");
}


void loop() 
{
  
  lecture();
  if (readString.length() >0)  // Vérifie que la variable contient de l'information
  {
    
    if (readString == "allumer")
    {
      digitalWrite(13, HIGH);
      BT.println("LED on");
    }
    if (readString == "eteindre")
    {
      digitalWrite(13, LOW);
      BT.println("LED off");
    }
    if (readString == "quoi")
    {
      BT.println("Send 'allumer' to turn LED on");
      BT.println("Send 'eteindre' to turn LED off");
    }   
    readString="";
  }
}

void lecture()
{
  while (BT.available()) // if text arrived in from BT serial...
    { delay(3);
      char a = BT.read();
      readString += a;
    }
}

Voila le code que j’ai utilisé pour communiquer avec mon smartphone