Modules Bluetooth HC-05 et HC-06 avec Arduino
FunduinoPublié le
Eine LED per Smartphone schalten – auch per Sprachbefehl
Tu en as besoin
Module Bluetooth HC-05 - UART, 3,3-6 V, portée jusqu’à 100 m
7,86 € *Réf. art. F23107169Vers le produit — Module Bluetooth HC-05 - UART, 3,3-6 V, portée jusqu’à 100 m
Microcontrôleur Funduino UNO R3 - ATmega328P, 16 MHz, pour Arduino
11,12 € *Réf. art. F23107480Vers le produit — Microcontrôleur Funduino UNO R3 - ATmega328P, 16 MHz, pour Arduino
Breadboard 830 points - plaque d’expérimentation pour Arduino, sans soudure
2,90 € *Réf. art. FUN-1010553Vers le produit — Breadboard 830 points - plaque d’expérimentation pour Arduino, sans soudure
Câbles pour breadboard mâle-mâle - 40 pièces, 20 cm
1,74 € *Réf. art. FUN-1010558Vers le produit — Câbles pour breadboard mâle-mâle - 40 pièces, 20 cm
LED 5 mm - 100 pièces, 5 couleurs, 2 V
1,97 € *Réf. art. F23107316Vers le produit — LED 5 mm - 100 pièces, 5 couleurs, 2 V
Assortiment de résistances 100 pièces - 5 valeurs de 100 Ω à 10 kΩ, 0,5 W
1,72 € *Réf. art. F23107216Vers le produit — Assortiment de résistances 100 pièces - 5 valeurs de 100 Ω à 10 kΩ, 0,5 W
Les 6 pièces au total 27,31 € *
* Tous les prix incluent la TVA légale, hors frais d’expédition.
Connecter le module Bluetooth
Allumer une LED par Bluetooth
Commander une LED par Bluetooth à l’aide d’un programme
char blueToothVal; // Les valeurs doivent être envoyées par Bluetooth
char lastValue; // mémorise le dernier état de la LED (allumée/éteinte)
void setup()
{
Serial.begin(9600); // Démarrer la liaison série, avec un débit fixé à 9600 bauds
pinMode(13, OUTPUT); // Configurer la broche 13 en sortie
}
void loop()
{
if (Serial.available()) // si des données sont reçues...
{
blueToothVal = Serial.read(); // ... elles doivent être lues
}
if (blueToothVal == '1') // si le module Bluetooth reçoit un « 1 »...
{
digitalWrite(13, HIGH); // ... la LED doit s'allumer
if (lastValue != '1') // si la dernière valeur reçue n'était pas un « 1 »...
Serial.println(F("LED is on")); // ... afficher « LED is on » dans le moniteur série
lastValue = blueToothVal;
}
else if (blueToothVal == '0') // si le module Bluetooth reçoit un « 0 »...
{
digitalWrite(13, LOW); // ... la LED doit s'éteindre
if (lastValue != '0') // si la dernière valeur reçue n'était pas un « 0 »...
Serial.println(F("LED is off")); // ... afficher « LED is off » dans le moniteur série
lastValue = blueToothVal;
}
}Commande vocale : étendre le montage
Commande vocale : le code du programme
Code du programme – Commande vocale de cinq LED
String voice;
int
ledweiss = 2, // Connect the white LED to pin 2
ledrot = 3, // Connect the red LED to pin 3
ledblau = 4, // etc.
ledgelb = 5,
ledgruen = 6;
void allon() // Function for the command to turn on all LEDs
{
digitalWrite(ledweiss, HIGH);
digitalWrite(ledrot, HIGH);
digitalWrite(ledblau, HIGH);
digitalWrite(ledgelb, HIGH);
digitalWrite(ledgruen, HIGH);
}
void alloff() // Function for the command to turn off all LEDs
{
digitalWrite(ledweiss, LOW);
digitalWrite(ledrot, LOW);
digitalWrite(ledblau, LOW);
digitalWrite(ledgelb, LOW);
digitalWrite(ledgruen, LOW);
}
void setup()
{
Serial.begin(9600);
pinMode(ledweiss, OUTPUT); // Set the pins connected to the LEDs as outputs
pinMode(ledrot, OUTPUT);
pinMode(ledblau, OUTPUT);
pinMode(ledgelb, OUTPUT);
pinMode(ledgruen, OUTPUT);
}
void loop()
{
while (Serial.available()) // Check whether readable values are available
{
delay(10);
char c = Serial.read();
if (c == '#') { break; } // "#" marks the end of a command, so the loop is exited when "#" is encountered
voice += c;
}
if (voice.length() > 0)
{
Serial.println(voice);
// In this section, commands are assigned to the individual functions
if (voice == "*alle an") { allon(); } // All pins should be switched on (using the previously defined allon function)
else if (voice == "*alle aus") { alloff(); } // All pins should be switched off (using the previously defined alloff function)
// This section defines how to turn on the individual LEDs
else if (voice == "*weiß an") { digitalWrite(ledweiss, HIGH); }
else if (voice == "*rot an") { digitalWrite(ledrot, HIGH); }
else if (voice == "*blau an") { digitalWrite(ledblau, HIGH); }
else if (voice == "*gelb an") { digitalWrite(ledgelb, HIGH); }
else if (voice == "*grün an") { digitalWrite(ledgruen, HIGH); }
// This section defines how to turn off the individual LEDs
else if (voice == "*weiß aus") { digitalWrite(ledweiss, LOW); }
else if (voice == "*rot aus") { digitalWrite(ledrot, LOW); }
else if (voice == "*blau aus") { digitalWrite(ledblau, LOW); }
else if (voice == "*gelb aus") { digitalWrite(ledgelb, LOW); }
else if (voice == "*grün aus") { digitalWrite(ledgruen, LOW); }
voice = "";
}
}L’application « Contrôle vocal Bluetooth pour Arduino »
1 / 2
Terminé !
Évaluer le guide