아두이노

[아두이노] arduino pro micro에 블루투스(HC-06) 연결하기

labj 2016. 6. 14. 02:11

[아두이노] arduino pro micro에 블루투스(HC-06) 연결하기


arduino pro micro에 블루투스(HC-06)을 연결하여 

스마트폰으로 arduino의 LED에 불이 들어오도록 하였습니다. 

밧데리는 3.7v입니다.


스마트폰에는 Bluetooth spp pro 앱을 이용하여 아두이노의 블루투스와 연결하고

LED 불이 켜지도록 명령을 보냈습니다.


HC-06을 Tx, Rx에 연결하고 아두이노에서 data를 Serial1으로 주고 받습니다.  






아두이노 소스 

pro_micro_bluetooth.ino



int ledPin = 9;

 

void setup() {

  Serial1.begin( 9600 );    

}

 

void loop() {

  if ( Serial1.available() > 0 ) {

    int count = Serial1.parseInt();

    if (count > 0) {

        Serial1.print("You have input: ");

        Serial1.println(String(count));

        blinkLED(count);

    }

  }

}

 

void blinkLED(int count) {

  for (int i=0; i< count; i++) {

    digitalWrite(ledPin, HIGH);

    delay(500);

    digitalWrite(ledPin, LOW);

    delay(500);

  } 

}




[아두이노] arduino pro micro에 블루투스(HC-06) 연결하기