Wednesday, March 16, 2016

HC-05 bluetooth module with arduino to control RGB led

INTRODUCTION TO BLUETOOTH MODULE HC-05

HC-05 Bluetooth module is a bluetooth communication device that can communicate with bluetooth of smart phones and laptops. We can make various projects by using this little module in which we can control any electrical and electronics devices and appliances with our smart phones.



It has 6 pins but we are gonna use only 4 pins and they are
1. VCC
2. Ground
3. TXD
4. RXD
The rest pins are used to put new password on the module. you also need to download a android apps named as BLUETOOTH TERMINAL which is available on google playstore.

Circuit Connection 

VCC of bluetooth module to 5v of arduino board
GND of bluetooth module to Gnd of arduino board
TXD of bluetooth module to D10 of arduino board
RXD of bluetooth module to D11 of arduino board

positive pin of led to D3 of arduino 
negative pin of led to Gnd of arduino

please watch the video for the circuit connection


Program Codes in Arduino IDE
=>first you need to download SoftwareSerial library from github website
or click the link here
=> download ZIP,, after downloading, extract the files
=> Now copy the extracted file to the following directory of your computer hard disc.
     C:\Program Files (x86)\Arduino\libraries
i. this is only a test code for controlling one led
connect led to pin D3 of arduino


code ::::::::::::::::;;


#include<SoftwareSerial.h>
SoftwareSerial sangitSerial(10,11);
int led=3;
void setup() {
  pinMode(led,OUTPUT);
  sangitSerial.begin(9600);
}

void loop() {
  while(sangitSerial.available())
  {
    sangitSerial.print("hi this is me computer");
    char value=sangitSerial.read();
    if(value=='a')
    digitalWrite(led,HIGH);
    else 
    digitalWrite(led,LOW);
  }
}



ii. final code for RGB led
connect red to pin D5
              green to pin D6
              blue to pin D7
download    bluetooth terminal apps from android play store 

code ::::::::::::::::::::::::

#include<SoftwareSerial.h>
SoftwareSerial sangitSerial(10,11);
int red=5;
int green=6;
int blue=7;
void setup() {
  // put your setup code here, to run once:
  sangitSerial.begin(9600);
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(blue,OUTPUT);
}

void loop() {
  while(sangitSerial.available())
  {
    char value=sangitSerial.read();
    if(value=='r')
    {
      digitalWrite(red,HIGH);
      digitalWrite(green,LOW);
      digitalWrite(blue,LOW);
    }
    else if(value=='g')
    {
      digitalWrite(red,LOW);
      digitalWrite(green,HIGH);
      digitalWrite(blue,LOW);
    }
    else if(value=='b')
    {
      digitalWrite(red,LOW);
      digitalWrite(green,LOW);
      digitalWrite(blue,HIGH);
    }
    else if(value=='y')
    {
      digitalWrite(red,HIGH);
      digitalWrite(green,HIGH);
      digitalWrite(blue,LOW);
    }
    else if(value=='z')
    {
      digitalWrite(red,LOW);
      digitalWrite(green,HIGH);
      digitalWrite(blue,HIGH);
    }
    else if(value=='x')
    {
      digitalWrite(red,HIGH);
      digitalWrite(green,LOW);
      digitalWrite(blue,HIGH);
    }
    else if(value=='w')
    {
      digitalWrite(red,HIGH);
      digitalWrite(green,HIGH);
      digitalWrite(blue,HIGH);
    }
    else
    {
      digitalWrite(red,LOW);
      digitalWrite(green,LOW);
      digitalWrite(blue,LOW);
    }
  }
}

No comments:

Post a Comment