====== COMMUNIQUER AVEC UN SMARTPHONE VIA UN MODULE BLUETOOTH ====== * Auteur : Damien MUTI DESGROUAS - Sevan Papazian (promo 2018) * Date : dernière mise à jour le 09/02/2021 * Licence : libre ! * Contexte : Apprentissage * Fichiers : liens éventuels * https: ===== Introduction ===== {{ :wiki:tutoriels:arduino:twigbt00.jpg?200 |}} Un module bluetooth permet une communication entre la carte Arduino et un smartphone ou un ordinateur sans avoir à connecter un câble. Vous trouverez un lien sur un tutoriel sur la manière d'utiliser un module BlueTooth avec une carte Arduino: * [[https://eskimon.fr/tuto-arduino-907-utiliser-un-module-bluetooth-hc-05-avec-arduino|Eskimon - module-bluetooth-hc-05]] * [[https://www.aranacorp.com/fr/arduino-et-le-module-bluetooth-hc-06/|module-bluetooth-hc-06]] * [[https://knowledge.parcours-performance.com/arduino-bluetooth-hc-05-hc-06/|caractéristiques techniques module-bluetooth-hc-05-06]] * [[http://www.martyncurrey.com/arduino-and-hc-06-zs-040/|module-bluetooth-hc-06-ZS-040]] Les caractéristiques du module-bluetooth-hc-06 : * [[http://www.dsdtech-global.com/2017/07/dsd-tech-hc-06-wireless-bluetooth.html/|caractéristiques techniques module-bluetooth-hc-06]] * [[https://www.itead.cc/wiki/Serial_Port_Bluetooth_Module_(Slave):_HC-06|caractéristiques techniques module-bluetooth-hc-06 - 1]] ===== Utilisation du module HC06===== Il faut suivre le tutoriel donné sur le lien suivant : * [[https://www.aranacorp.com/fr/arduino-et-le-module-bluetooth-hc-06/|module-bluetooth-hc-06]] ==== Schéma de câblage ==== Ce tutoriel donne le schéma de câblage : {{ :wiki:tutoriels:arduino:arduino-bluetooth-hc06_bb.png?400 |}} ==== Initialisation du module ==== Le programme initial permettant de donner un nom, un code PIN, etc. au module Bluetooth : #include SoftwareSerial Module_BT(2,3); // RX, TX void setup(){ //Initialize Serial Monitor Serial.begin(9600); Serial.println("ENTER AT Commands:"); //Initialize Bluetooth Serial Port Module_BT.begin(9600); } void loop(){ //Write data from HC06 to Serial Monitor if (Module_BT.available()){ Serial.write(Module_BT.read()); } //Write from Serial Monitor to HC06 if (Serial.available()){ Module_BT.write(Serial.read()); } } Le code Arduino est téléchargeable ici : {{ :wiki:tutoriels:arduino:init_hc-06.zip |}} === Problème de connexion === Dans une classe où il y a plusieurs modules BT, il est parfois difficile de trouver le module BT que vous avez connecté à votre carte. Sur les applications de communication Série en Bluetooth (Bluetooth Serial), il apparaît seulement plusieurs "HC-05"... Difficile de choisir. On peut s'en sortir si on connait l'adresse MAC (identifiant unique du matériel) du type : 7D:2C:55:C0:2E:83. La solution est disponible sur cet Article : [[https://forum.arduino.cc/t/hc-05-bluetooth-mac-adress/571920/2|Forum Arduino]] La liste de toutes les commandes AT pour le module BT en mode "commande" : [[https://eskimon.fr/commandes_AT_HC05.pdf|Embedded Bluetooth Serial Communication Module - AT command set]] ==== Dialogue entre le smartphone et la carte Arduino ==== === Contrôler une LED === == Présentation == Voici un programme permettant de contrôler la LED de la carte (connectée à la patte N°13). Le programme permet par exemple de d'allumer ou d'éteindre la LED, ainsi que de faire clignoter la LED à une période définie par un utilisateur. La vidéo suivante montre son fonctionnement : [[https://youtu.be/29GeLzOfgfs|Arduino - module Bluetooth HC06 - Smartphone]] == Application Bluetooth Terminal == Il faut d'abord télécharger une application sur votre smartphone permettant le dialogue entre votre smartphone et le module Bluetooth. Par exemple l'application : * [[https://play.google.com/store/apps/details?id=Qwerty.BluetoothTerminal&hl=en|Bluetooth Terminal]] == Programme de test du module == Ce Programme permet d'allumer une LED en envoyant ON via le terminal BT du smartphone. Si on envoie OFF, la LED s'éteind. Si on envoie un nombre "T" compris entre 0 et 10000, la LED va clignoter avec une période T. #include SoftwareSerial hc06(2, 3); String cmd = ""; float sensor_val = 0; // faire clignoter clignoter la led byte led = 8; int Tblink = 100; float isBlink = false; // drapeau pour lancer le clignotement... ou non void setup() { // pin 13 OUTPUT pinMode(led, OUTPUT); //Initialize Serial Monitor Serial.begin(9600); //Initialize Bluetooth Serial Port hc06.begin(115200); /// Tester aussi avec 9600 si vous rencontrez des difficultés de communication avec le moule BT } void loop() { //Read data from HC06 while (hc06.available() > 0) { cmd += (char)hc06.read(); } //Select function with cmd if (cmd != "") { Serial.print("Command recieved : "); Serial.println(cmd); // We expect ON or OFF from bluetooth if (cmd == "ON") { Serial.println("Function is on"); digitalWrite(led, HIGH); // alumer la led isBlink = false; // arrêter le clignotement } else if (cmd == "OFF") { Serial.println("Function is off"); digitalWrite(led, LOW); // éteindre la led isBlink = false; // arrêter le clignotement } else { // convertir la comande en un entier int x = cmd.toInt(); // conversion de la chaine de caractère en un entier if (x >= 0 && x <= 10000) { // si la commande est un nombre entre 0 et 10000 (soit 10s) Tblink = x; clignoterLed(13, x, x); isBlink=true; } else { Serial.println("Function is off by default"); } } cmd = ""; //reset cmd } // gestion du clignotement if (isBlink) { clignoterLed(led,Tblink,Tblink); } // Simulate sensor measurement sensor_val = (float)random(256); // random number between 0 and 255 //Write sensor data to HC06 hc06.print(sensor_val); delay(100); } void clignoterLed(int led, int Ta, int Te) { // led : patte connécéet à la led, Ta: temps d'allumage, Te: temps led éteinte digitalWrite(led, HIGH); delay(Ta); digitalWrite(led, LOW); delay(Te); } Le code Arduino est téléchargeable ici : {{ :wiki:tutoriels:arduino:test_send_recieve_hc06_clignoter_led.zip |}} === Lire les données d'un capteur : ici potentiomètre === == Montage == Reprendre le montage précédent et y incorporer un potentiomètre branché sur A0 comme l'image suivante : {{ :wiki:tutoriels:arduino:test_send_recieve_hc06_donnees_capteur_bb.png?800 |}} == Algorithme == * Lire les données sur le capteur (ici le potentiomètre) * envoyer les données via le port Bleutooth * Afficher les données sur un terminal Bluetooth d'un smartphone. == Programme == télécharger le programme Arduino sur le lien suivant : * {{ :wiki:tutoriels:arduino:test_send_recieve_hc06_donnees_capteur.zip |}} === Connection directe du module BT sur les pattes RX et TX de la carte === Il est possible de connecter directement les broches RX et TX du module BT respectivement aux pattes digitales TX et RX de la carte Arduino. Dans ce cas, la communication série s'effectue directement via la classe "Serial" incluse dans la carte. Le schéma est le suivant : {{ :wiki:tutoriels:arduino:bt_arduino_rx_tx.png?800 |}} Le programme et les explications permettant de contrôler une LED est le suivant : [[https://icn.lycee-valin.fr/dokuwiki/doku.php?id=arduino:le_bluetooth|ICN au Lycée Valin]] Le code Arduino est le suivant : // définition de la broche 13 de la carte en tant que variable const int led_rouge = 13; String message; // fonction d'initialisation de la carte void setup() { pinMode(led_rouge, OUTPUT); // initialisation de la broche 13 comme étant une sortie Serial.begin(9600); // initialisation de la liaison série } void loop() { if (Serial.available() > 0 ) //Si un message a été reçu faire ceci { message=Serial.readString(); // lire le message if(message=="1"){ digitalWrite(led_rouge, HIGH); // allume la LED } if(message=="0"){ digitalWrite(led_rouge, LOW); // éteint la LED } } } Dans ce code, il est nécessaire cette fois-ci que l'application Android envoie "1" pour allumer la LED et "0" pour l'éteindre. ===== Créer une application Android sur App Inventor 2 ===== ==== Présentation ==== Nous allons créer une application Android permetant de dialoguer avec une carte Arduino via un module Bluetooth. L'outil en ligne MIT App Inventor offre une manière graphique très élégante de fabriquer une application Android: * http://appinventor.mit.edu/ Vous trouverez un tutoriel très simple en français sur la construction d'une application permettant de contrôler deux boutons (ON/OFF), de recevoir et d'afficher des données envoyées par une carte Arduino via un module Bluetooth : * https://www.aranacorp.com/fr/creez-une-app-avec-app-inventor-2/ ==== Contrôler une LED et recevoir des données d'un capteur ==== Nous allons utiliser le programme Arduino précédemment écrit permettant d'allumer et d'éteindre une LED (patte 13) et d'envoyer des données lues sur un potentiomètre via le port Bluetooth. {{ :wiki:tutoriels:arduino:test_send_recieve_hc06_donnees_capteur_bb.png?400 |}} {{ :wiki:tutoriels:arduino:20200422_164904_1.jpg?400 |}} Le programme Arduino est téléchargeable sur ce lien : * {{ :wiki:tutoriels:arduino:test_send_recieve_hc06_donnees_capteur.zip |}} Grace à l'outil en ligne MIT App Inventor il est possible de créer une application permettant de se connecter au module Bluetooth, comprenant deux boutons ON et OFF permettant d’allumer ou d'éteindre la LED 13, et permettant d'afficher les données envoyées par la carte: {{ :wiki:tutoriels:arduino:screenshot_20200422-165616.jpg?200 |}} MIT App Inventor permet de designer l'interface de l'application en sélectionnant les boutons et les fonctionnalités : {{ :wiki:tutoriels:arduino:image_appli.png?200 |}} A chaque composant correspond une description détaillée qu'il est possible de customiser. Par exemple ici pour le bouton ON : {{ :wiki:tutoriels:arduino:image_composantes.png?400 |}} La programmation de l'application s'effectue sous Scratch qui est une programmation graphique par bloc comme le montre l'image suivante : {{ :wiki:tutoriels:arduino:programme_test_led.png?800 |}} Vous pouvez télécharger l'application Android sur le lien suivant : * {{ :wiki:tutoriels:arduino:application.zip |}} Le projet développé sur l'outil en ligne MIT App Inventor peut être modifié en téléchargeant le lien suivant : * {{ :wiki:tutoriels:arduino:projet_mit_app_inventor_test_led.zip |}} Une version différente du projet est disponible sur ces liens : * {{ :wiki:tutoriels:arduino:test_led_1.aia.zip | Programme App Inventor}} * {{ :wiki:tutoriels:arduino:test_led_1.zip |Application Android associée}} Il est possible de visualiser l'application Android créée directement sur votre ordinateur à l'aide d'un émulateur Android. Les informations d'installation sont disponibles sur ce lien : * [[http://appinventor.mit.edu/explore/ai2/setup-emulator|Installing and Running the Emulator in AI2]] L'installation sur Windows est disponible sur le lien suivant : * [[http://appinv.us/aisetup_windows|aiStarter]] ==== Utiliser un slider horizontal pour contrôler la fréquence de clignotement d'une LED ==== Voici quelques tutoriels permettant d'insérer un slider dans l'application: * [[https://www.youtube.com/watch?v=8vEa6-qV64s|Tuto Slider horizontal 1]] * [[https://www.youtube.com/watch?v=ex6W_LYBGuA|Tuto Slider horizontal 2]] La nouvelle application est basée sur le même programme que la partie précédente. On y insère un slider permettant d'envoyer la période de clignotement entre 0 et 1000ms. L'interface de l'application est la suivante : {{ :wiki:tutoriels:arduino:interface_test_led_slider.jpg?300 |}} le programme et l'application sont disponibles sur les liens suivants: * {{ :wiki:tutoriels:arduino:test_led_slider.aia.zip |Programme App Inventor}} * {{ :wiki:tutoriels:arduino:test_led_slider.apk.zip |Application Android}} * {{ :wiki:tutoriels:arduino:test_send_recieve_hc06_donnees_capteur.zip |Programme Arduino Associé}} (identique à la partie précédente) Le programme est effectué sous Scratch : {{ :wiki:tutoriels:arduino:programme_test_led_slider.png?800 |}} Ce programme peut ensuite être modifié pour contrôler un moteur, un servomoteur, la couleur d'une LED multicolore, ou toute autre application nécessitant l'utilisation d'un paramètre. ==== Gestion du Son et des images sur App Inventor 2 ==== Voici un lien expliquant comment accéder aux images et au sons sur App Inventor 2 : * [[https://appinventor.mit.edu/explore/ai2/concepts/images-and-sounds.html|Accessing Images and Sounds (App Inventor 2)]] * [[https://appinventor.mit.edu/explore/content/media|Media Components]] * [[https://appinventor.mit.edu/explore/content/hellopurr.html]| Un exemple utilisant une image et un son]] * [[http://www.appinventor.org/content/howDoYou/timedLists/music|Comment jouer une liste de sons]] * [[http://teen-code.com/2017/02/23/tuto-comment-integrer-sons-dans-appli-mobile/|Comment intégrer un son dans une application mobile]] ===== Application à un habit interactif - Bluetooth et Processing===== ==== Présentation ==== En s'inspirant des [[wiki:tutoriels:affiche-interactive:accueil|affiches interactives]], il est possible de créer des objets interactifs capables de réagir en lançant un médiat (son, vidéo, animation). Cette interaction intervient par exemple lorsque la valeur renvoyée par la mesure d'un paramètre associée à un capteur est inférieure à un seuil. On choisit exemple un capteur de distance à ultrason. ==== Montage ==== Le système comporte deux cartes Arduino ===== Dabble : Une librairie spécifique pour contrôler la carte Arduino via un module Bluetooth ===== ==== Installer la librairie Dabble ==== Dans l'IDE d'Arduino, aller dans Croquis> Inclure une bibliothèque > Gérer les bibliothèques : {{ :wiki:tutoriels:arduino:inclure_bibliotheque.jpg?600 |}} Dans le moteur de recherche du Gestionaire de bibliothèque, taper le nom du module Bluetooth (ici hc-06) : {{ :wiki:tutoriels:arduino:gestionaire_librairies.png?600 |}} Installer la librairie "DabbleESP32", en cliquant sur le bouton "Installer". Nous disposons maintenant de tous les exemples de cette librairie : {{ :wiki:tutoriels:arduino:exemples_dabble.jpg?600 |}} Cette librairie permet maintenant de contrôler certains capteurs et actionneurs (LED,etc.) branchée sur la carte Arduino. Pour cela, il suffit de télécharger l'interface de Dabble sur votre Smartphone : * [[https://thestempedia.com/docs/dabble/getting-started-with-dabble/|Dabble]] ====== Utilisation d'un module HC-05 ====== {{ :wiki:tutoriels:arduino:ori-module-bluetooth-hc05-26097.jpeg?400 |}} ===== Mode Commende : initialisation du module - Facultatif ===== voir tutoriel : [[https://retroetgeek.com/arduino/configuration-du-module-hc-05-pour-arduino/|Retrogeek]] ==== Câblage ==== {{ :wiki:tutoriels:arduino:hc-05configuration-circuit_bb.jpg?600 |}} ==== Programme ==== #include SoftwareSerial mySerial(10, 11); // RX, TX void setup() { Serial.begin(9600); pinMode(9,OUTPUT); digitalWrite(9,HIGH); Serial.println("Enter AT commands:"); mySerial.begin(38400); } void loop() { if (mySerial.available()) Serial.write(mySerial.read()); if (Serial.available()) mySerial.write(Serial.read()); } ==== Les commandes AT ==== AT : Vérifier la connexion avec le module AT+NAME : Voir le nom du module AT+ADDR : Voir l’adresse du module AT+VERSION : Connaitre la version AT+UART : Connaitre la vitesse de connexion AT+ROLE: Voir le rôle du module (1=master/ 0=slave/ 2=esclave boucle) AT+RESET : Redemarrage dy module et sortir du mode AT AT+ORGL : Restorer le module d’usine AT+PSWD: Consulter le mot de passe AT+BIND=adresse,du,slave (on a remplacé les : par des , ) , permet de connecter un module master à un slave ===== Bibliographie ===== Data sheet : * [[http://yourduino.com/docs/CSR-BC417-datasheet.pdf|]] Tutoriel Arduino : * [[https://electronicshobbyists.com/hc-05-bluetooth-module-interfacing-with-arduino-arduino-bluetooth-module-tutorial/|]] * [[https://retroetgeek.com/arduino/configuration-du-module-hc-05-pour-arduino/|]] Tutoriel en PDF : * [[https://www.gotronic.fr/pj2-guide-de-mise-en-marche-du-module-bluetooth-hc-1546.pdf|Gotronic]] Un tutoriel en vidéo : * [[https://www.youtube.com/watch?v=aQcJ4uHdQEA|Bluetooth for Android and Arduino HC-05 Module, Java implementation]] ===== Notice d'installation ===== L'installation du module Bluetooth HC05, c'est à dire la connexion et le test de ce composant est accessible sur le tutoriel de Gotronic : * [[https://www.gotronic.fr/pj2-guide-de-mise-en-marche-du-module-bluetooth-hc-1546.pdf|Tutoriel Gotronic HC05]] ====== Module HC-05 Grove BLE v1 ====== {{ :wiki:tutoriels:arduino:grove-ble-dual_model-v1.0.jpeg?400 |}} Le tutoriel d'utilisation est le suivant : [[https://wiki.seeedstudio.com/Grove-BLE-dual_model-v1.0/|Wiki Seeeduino -Grove-BLE-dual_model-v1.0 ]] Le code permettant de connaître les caractéristiques du modules BT Grove-BLE est accessible ici : [[https://github.com/Seeed-Studio/HM_13_SW|Github]] ===== Etalonage du module ===== Le code permettant de connaître les caractéristiques du module BT Grove-BLE est le suivant : [[https://github.com/Seeed-Studio/HM_13_SW/blob/master/HM_13_SW.ino|Programme Arduino Sur Github]] /* Bluetooth HM13 Demo Code 2014 Copyright (c) Seeed Technology Inc. All right reserved. Author: Jacky Zhang This demo code is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA For more details about the product please check http://www.seeedstudio.com/depot/ */ /* Upload this sketch into Arduino Uno and press reset*/ #include //Software Serial Port #define RxD 2 #define TxD 3 #define MASTER 1 //change this macro to define the Bluetooth as Master or not SoftwareSerial blueToothSerial(RxD,TxD);//the software serial port char recv_str[100]; void setup() { Serial.begin(115200); //Serial port for debugging pinMode(RxD, INPUT); //UART pin for Bluetooth pinMode(TxD, OUTPUT); //UART pin for Bluetooth Serial.println("\r\nPower on!!"); if(setupBlueToothConnection() != 0) while(1); //initialize Bluetooth //this block is waiting for connection was established. while(1) { if(recvMsg(1000) == 0) { if(strcmp((char *)recv_str, (char *)"OK+CONB") == 0) { Serial.println("connected\r\n"); break; } } delay(200); } } void loop() { #if MASTER //central role //in master mode, the bluetooth send message periodically. delay(400); Serial.println("send: hi"); blueToothSerial.print("hi"); delay(100); //get any message to print if(recvMsg(1000) == 0) { Serial.print("recv: "); Serial.print((char *)recv_str); Serial.println(""); } #else //peripheral role delay(200); //the slave role only send message when received one. if(recvMsg(1000) == 0) { Serial.print("recv: "); Serial.print((char *)recv_str); Serial.println(""); Serial.println("send: hello"); blueToothSerial.print("hello");//return back message } #endif } //used for compare two string, return 0 if one equals to each other int strcmp(char *a, char *b) { unsigned int ptr = 0; while(a[ptr] != '\0') { if(a[ptr] != b[ptr]) return -1; ptr++; } return 0; } //configure the Bluetooth through AT commands int setupBlueToothConnection() { #if MASTER Serial.println("this is MASTER\r\n"); #else Serial.println("this is SLAVE\r\n"); #endif Serial.print("Setting up Bluetooth link\r\n"); delay(3500);//wait for module restart //send command to module in different baud rate while(1) { delay(500); blueToothSerial.begin(9600); delay(500); Serial.print("try 9600\r\n"); if(sendBlueToothCommand("AT") == 0) break; delay(500); blueToothSerial.begin(115200); delay(500); Serial.print("try 115200\r\n"); if(sendBlueToothCommand("AT") == 0) break; } //we have to set the baud rate to 9600, since the soft serial is not stable at 115200 sendBlueToothCommand("AT+RENEW");//restore factory configurations sendBlueToothCommand("AT+BAUD2");//reset the module's baud rate sendBlueToothCommand("AT+AUTH1");//enable authentication sendBlueToothCommand("AT+RESET");//restart module to take effect blueToothSerial.begin(9600);//reset the Arduino's baud rate delay(3500);//wait for module restart //configure parameters of the module sendBlueToothCommand("AT+VERS?");//get firmware version sendBlueToothCommand("AT+ADDE?");//get EDR MAC sendBlueToothCommand("AT+ADDB?");//get BLE MAC sendBlueToothCommand("AT+NAMEHM-13-EDR");//set EDR name sendBlueToothCommand("AT+NAMBHM-13-BLE");//set BLE name sendBlueToothCommand("AT+PINE123451");//set EDR password sendBlueToothCommand("AT+PINB123451");//set BLE password sendBlueToothCommand("AT+SCAN0");//set module visible sendBlueToothCommand("AT+NOTI1");//enable connect notifications //sendBlueToothCommand("AT+NOTP1");//enable address notifications sendBlueToothCommand("AT+PIO01");//enable key function #if MASTER sendBlueToothCommand("AT+ROLB1");//set to master mode #else sendBlueToothCommand("AT+ROLB0");//set to slave mode #endif sendBlueToothCommand("AT+RESET");//restart module to take effect delay(3500);//wait for module restart if(sendBlueToothCommand("AT") != 0) return -1;//detect if the module exists Serial.print("Setup complete\r\n\r\n"); return 0; } //send command to Bluetooth and return if there is a response int sendBlueToothCommand(char command[]) { Serial.print("send: "); Serial.print(command); Serial.println(""); blueToothSerial.print(command); delay(200); if(recvMsg(200) != 0) return -1; Serial.print("recv: "); Serial.print(recv_str); Serial.println(""); return 0; } //receive message from Bluetooth with time out int recvMsg(unsigned int timeout) { //wait for feedback unsigned int time = 0; unsigned char num; unsigned char i; //waiting for the first character with time out i = 0; while(1) { delay(50); if(blueToothSerial.available()) { recv_str[i] = char(blueToothSerial.read()); i++; break; } time++; if(time > (timeout / 50)) return -1; } //read other characters from uart buffer to string while(blueToothSerial.available() && (i < 100)) { recv_str[i] = char(blueToothSerial.read()); i++; } recv_str[i] = '\0'; return 0; } ===== Programme de test du module ===== Ce Programme permet d'allumer une LED en envoyant ON via le terminal BT du smartphone. Si on envoie OFF, la LED s'éteind. Si on envoie un nombre "T" compris entre 0 et 10000, la LED va clignoter avec une période T. #include SoftwareSerial hc06(2, 3); String cmd = ""; float sensor_val = 0; // faire clignoter clignoter la led byte led = 8; int Tblink = 100; float isBlink = false; // drapeau pour lancer le clignotement... ou non void setup() { // pin 13 OUTPUT pinMode(led, OUTPUT); //Initialize Serial Monitor Serial.begin(9600); //Initialize Bluetooth Serial Port hc06.begin(115200); } void loop() { //Read data from HC06 while (hc06.available() > 0) { cmd += (char)hc06.read(); } //Select function with cmd if (cmd != "") { Serial.print("Command recieved : "); Serial.println(cmd); // We expect ON or OFF from bluetooth if (cmd == "ON") { Serial.println("Function is on"); digitalWrite(led, HIGH); // alumer la led isBlink = false; // arrêter le clignotement } else if (cmd == "OFF") { Serial.println("Function is off"); digitalWrite(led, LOW); // éteindre la led isBlink = false; // arrêter le clignotement } else { // convertir la comande en un entier int x = cmd.toInt(); // conversion de la chaine de caractère en un entier if (x >= 0 && x <= 10000) { // si la commande est un nombre entre 0 et 10000 (soit 10s) Tblink = x; clignoterLed(13, x, x); isBlink=true; } else { Serial.println("Function is off by default"); } } cmd = ""; //reset cmd } // gestion du clignotement if (isBlink) { clignoterLed(led,Tblink,Tblink); } // Simulate sensor measurement sensor_val = (float)random(256); // random number between 0 and 255 //Write sensor data to HC06 hc06.print(sensor_val); delay(100); } void clignoterLed(int led, int Ta, int Te) { // led : patte connécéet à la led, Ta: temps d'allumage, Te: temps led éteinte digitalWrite(led, HIGH); delay(Ta); digitalWrite(led, LOW); delay(Te); } ====== Carte Arduino Nano BLE ====== La carte Arduino nano BLE contient un module Bluetooth intégré. La documentation de la carte Arduino Nano BLE est disponible sur le lien suivant : https://store.arduino.cc/arduino-nano-33-ble Le schéma des pattes d'entrée et sortie est le suivant : {{ :wiki:tutoriels:arduino:schema_broches_arduino_nano_ble.png?600 |}} Les schémas de câblage et fritzing sont disponibles sur le lien suivant : https://store.arduino.cc/arduino-nano-33-ble : * [[https://content.arduino.cc/assets/NANO%2033%20BLE.fzpz|Schéma Fritzing]] La librairie permettant de contrôler la carte depuis l'IDE est la suivante : [[https://www.arduino.cc/en/Reference/ArduinoBLE|ArduinoBLE library]] ===== Bibliographie ===== Tutoriel Seeeduino : * [[https://wiki.seeedstudio.com/Grove-BLE_v1/|HC-05 Grove BLE v1]]