Herunterladen Diese Seite drucken

TRU Components HC-05 Bedienungsanleitung Seite 2

Bluetooth-funkmodul für arduino
Inbetriebnahme
Verbinden Sie das Modul wie folgt mit einen Arduino™ UNO:
Bluetooth
-Modul
Arduino
®
VCC
Spannungsversorgung (3,3 V/DC)
GND
Masse Spannungsversorgung
DOUT
D0 (RX)
DIN
D1 (TX)
Testprogramm
Das folgende kleine Testprogramm konfiguriert das Bluetooth
Modul. Die serielle Verbindung zum Bluetooth
eine Software UART aufgebaut. Dadurch ist es möglich, Debug-
Ausgaben über die serielle Hardware UART zu machen.
#include <SoftwareSerial.h>
#define RxD 2
#define TxD 3
SoftwareSerial
blueToothSerial(RxD,TxD);
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
}
void loop()
{
if(blueToothSerial.read() == ‚a')
{
blueToothSerial.println(„You
are connected to Bluetooth Bee");
//You can write you BT
communication logic here
}
}
void setupBlueToothConnection()
{
Serial.print(„Setting up Bluetooth
link"); /*For debugging, Comment this
line if not required*/
TM
-Modul, wird über
®
blueToothSerial.begin(38400); /*Set
BluetoothBee BaudRate to default baud
rate 38400*/
delay(1000);
sendBlueToothCommand(„\r\
n+STWMOD=0\r\n");
sendBlueToothCommand(„\r\
n+STNA=modem\r\n");
sendBlueToothCommand(„\r\
n+STAUTO=0\r\n");
-
sendBlueToothCommand(„\r\
®
n+STOAUT=1\r\n");
sendBlueToothCommand(„\r\
n+STPIN=0000\r\n");
delay(2000); // This delay is
required.
blueToothSerial.print(„\r\n+INQ=1\
r\n");
delay(2000); // This delay is
required.
Serial.print(„Setup complete");
}
void sendBlueToothCommand(char
command[])
{
char a;
blueToothSerial.print(command);
Serial.print(command);
delay(3000);
while(blueToothSerial.available())
{
Serial.
print(char(blueToothSerial.read()));
}
}
Hinweis:
Es gibt für das Bluetooth
bliotheken im Internet, die sie mit diesem Modul verwen-
den können. In den Beispielen müssen Sie dazu nur die
Anschlusspins anpassen.
-Modul mittlerweile mehrer Bi-
®
loading

Diese Anleitung auch für:

2268248