임베디드/Arduino

Bluetooth connecting

sj0020 2020. 8. 20. 10:40

 

/*
 RXD = 아두이노 2번핀에 연결
 TXD = 아두이노 3번핀에 연결
*/

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(3,2);

void setup() {
  Serial.begin(9600);  //HW Serial. 9600bps = 통신속도. 숫자높을수록 빠르지만 안정성떨어짐
  BTSerial.begin(9600); //SW Serial.
}

void loop() {
  if(BTSerial.available()){
    Serial.write(BTSerial.read());
  }

  if (Serial.available()){
    BTSerial.write(Serial.read());
  }
}