第1步:工具和組件
這就是您需要的-
Attiny84或85
藍(lán)牙模塊
面包板
跳線
步驟2:電路
如下設(shè)置ATiny和藍(lán)牙之間的連接-
藍(lán)牙模塊Rx-》 ATiny85引腳1
藍(lán)牙模塊Tx-》 ATiny85引腳2
藍(lán)牙模塊接地-》 ATiny85引腳4
藍(lán)牙模塊VCC-》 ATiny85引腳8
步驟3:代碼
在這里是可以運(yùn)行的測(cè)試草圖,連接6點(diǎn)的led并上傳代碼。從串行終端發(fā)送1將打開LED指示燈,發(fā)送0將關(guān)閉它。
#include //Software Serial Port
#define RxD 1
#define TxD 2
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
int led = 4;
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
pinMode(led,OUTPUT);
digitalWrite(led,HIGH);
}
void loop()
{
char recvChar;
while(1){
//check if there‘s any data sent from the remote bluetooth shield
if(blueToothSerial.available()){
recvChar = blueToothSerial.read();
if(recvChar == ’1‘)
digitalWrite(led,HIGH);
else
digitalWrite(led,LOW);
}
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print(“ +STWMOD=0 ”); //set the bluetooth work in slave mode
blueToothSerial.print(“ +STNA=HC-05 ”); //set the bluetooth name as “HC-05”
blueToothSerial.print(“ +STOAUT=1 ”); // Permit Paired device to connect me
blueToothSerial.print(“ +STAUTO=0 ”); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
//blueToothSerial.print(“ +INQ=1 ”); //make the slave bluetooth inquirable
blueToothSerial.print(“bluetooth connected! ”);
delay(2000); // This delay is required.
blueToothSerial.flush();
}
責(zé)任編輯:wv
-
藍(lán)牙
+關(guān)注
關(guān)注
116文章
6029瀏覽量
173158 -
串行通信
+關(guān)注
關(guān)注
4文章
586瀏覽量
36016
發(fā)布評(píng)論請(qǐng)先 登錄
如何增加藍(lán)牙通信距離?

串行通信接口SPI與QSPI的區(qū)別

FS85如何通過OTP編程進(jìn)行配置?
RS232與藍(lán)牙無線通信的對(duì)比 RS232串口設(shè)備的故障排查
串口屏如何與主控制器進(jìn)行通信?

藍(lán)牙AES+RNG如何保障物聯(lián)網(wǎng)信息安全
如何實(shí)現(xiàn)51單片機(jī)與PC機(jī)的串行通信
藍(lán)牙MESH是什么?

了解藍(lán)牙模塊串口通訊基礎(chǔ)知識(shí)

異步通信常用于什么通道
經(jīng)典藍(lán)牙協(xié)議PAN詳解

一個(gè)沒有mesh協(xié)議的ble設(shè)備,如何通過gatt協(xié)議與mesh網(wǎng)絡(luò)通信?
為什么ModBus RTU要與TCP進(jìn)行轉(zhuǎn)換?

評(píng)論