Monday, August 14, 1989

Bluetooth Led Sketch

// Basic Bluetooth sketch HC-05_02
// Connect the HC-05 module and communicate using the serial monitor
//
// The HC-05 defaults to commincation mode when first powered on.
// The default baud rate for communication mode is 9600
// For BT-Coder

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
//
int ledPin = 13;
char data = 0;   

void setup()
{
   // Serial.begin(9600);
  
   // BTserial.println("Arduino is ready");
     pinMode(ledPin, OUTPUT);
    // HC-05 default serial speed for commincation mode is 9600
    BTserial.begin(9600); 
}

void loop()
{

    // Keep reading from HC-05 and send to Arduino Serial Monitor
    if (BTserial.available())
    {
    data = BTserial.read();      //Read the incoming data and store it into variable data
 //   Serial.print(data);        //Print Value inside data in Serial monitor
  //  Serial.print("\n");        //New line
    if(data == 'q')            //Checks whether value of data is equal to 1
      digitalWrite(ledPin, HIGH);  //If value is 1 then LED turns ON
    else if(data == 'p')       //Checks whether value of data is equal to 0
      digitalWrite(ledPin, LOW);   //If value is 0 then LED turns OFF
       }
}




























No comments:

Post a Comment