當前位置:編程學習大全網 - 編程軟體 - 請教兩個Arduino通過HC-05藍牙模塊通信

請教兩個Arduino通過HC-05藍牙模塊通信

把hc 05的key引腳置高電位就進入命令模式,給個例程:

/*

AUTHOR: Hazim Bitar (techbitar)

DATE: Aug 29, 2013

LICENSE: Public domain (use at your own risk)

CONTACT: techbitar at gmail dot com (techbitar.com)

*/

#include

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()

{

pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode

digitalWrite(9, HIGH);

Serial.begin(9600);

Serial.println("Enter AT commands:");

BTSerial.begin(38400); // HC-05 default speed in AT command more

}

void loop()

{

// Keep reading from HC-05 and send to Arduino Serial Monitor

if (BTSerial.available())

Serial.write(BTSerial.read());

// Keep reading from Arduino Serial Monitor and send to HC-05

if (Serial.available())

BTSerial.write(Serial.read());

}

  • 上一篇:直接編程教學
  • 下一篇:編程問題調試
  • copyright 2024編程學習大全網