Aller au contenu

Bluetooth

MonProjet

Objectif

Liste de matériel

  • Arduino Uno
  • Module bluetooth hc-06 (4 pins)
  • LED
*

Schéma

0_bluetooth_led_bb.png

Composants Arduino
HC-06 - RXD 10
HC-06 - TXD 11
HC-06 - GND GND
HC-06 - VCC 3.3V
LED grd 13
LED pt GND

Code

#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11); 
// creates a "virtual" serial port/UART
// connect BT module TX to D10
// connect BT module RX to D11
// connect BT Vcc to 5V, GND to GND
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");
}
char a; // stores incoming character from other device
void loop() 
{
  if (BT.available())
  // if text arrived in from BT serial...
  {
    a=(BT.read());
    if (a=='1')
    {
      digitalWrite(13, HIGH);
      BT.println("LED on");
    }
    if (a=='2')
    {
      digitalWrite(13, LOW);
      BT.println("LED off");
    }
    if (a=='?')
    {
      BT.println("Send '1' to turn LED on");
      BT.println("Send '2' to turn LED on");
    }   
    // you can add more "if" statements with other characters to add more commands
  }
}

Précisions

La led peut-être activée en tapant 1 depuis un terminal bluetooth. Par exemple sur un téléphone portable avec l'application [[http://apk-dl.com/connection-terminal%7CConnection Terminal], après avoir lié le périphérique bluetooth (arduino hc-06) et envoyé la commande 1

Date de réalisation

17/03/2015