HeathenHacks
Published © GPL3+

HC-05 Master & Slave Communication

One of many Bluetooth-related projects coming soon.

BeginnerFull instructions provided7,306
HC-05 Master & Slave Communication

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×2
RGB Diffused Common Anode
RGB Diffused Common Anode
×1
Momentary Push Button
×3
Resistor 10k ohm
Resistor 10k ohm
×3
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 2.21k ohm
Resistor 2.21k ohm
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Buttons Circuit Test

HC-05 Master Module Schematics

HC-05 Slave Module Schematics

Code

Buttons.ino

Arduino
int R = 2;
int G = 3;
int B = 4;

int BR = 5;
int BG = 6;
int BB = 7;


void setup() {

pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
pinMode(BR, INPUT);
pinMode(BG, INPUT);
pinMode(BB, INPUT);
  digitalWrite(R, HIGH);  
  digitalWrite(G, HIGH);
  digitalWrite(B, HIGH);
}

void Red(){
  if (digitalRead(BR==1));
  digitalWrite(R, LOW);
  digitalWrite(G, HIGH);
  digitalWrite(B, HIGH);
}

void Green(){
  if (BG == 1);
  digitalWrite(R, HIGH);
  digitalWrite(G, LOW);
  digitalWrite(B, HIGH);
}

void Blue(){
  if (BB == 1);
  digitalWrite(R, HIGH);
  digitalWrite(G, HIGH);
  digitalWrite(B, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:

}

MasterCodeFINAL.ino

Arduino
const int BR = 2; //BR = Button for Red
const int BG = 3; //BG = Button for Green
const int BB = 4; //BB = Button for Blue
byte BRstate = 0;
byte BGstate = 0;
byte BBstate = 0;

void setup() {
  Serial.begin(38400);
  pinMode(BR, INPUT);
  pinMode(BG, INPUT);
  pinMode(BB, INPUT);
}

void loop() {

  BRstate = digitalRead(BR);
  BGstate = digitalRead(BG);
  BBstate = digitalRead(BB);

  if (BRstate == HIGH) {
    Serial.println("Red");
    Serial.write ('R');
  } else {
    Serial.write(0);
  }

  if (BGstate == HIGH) {
    Serial.println("Green");
    Serial.write ('G');
  } else {
    Serial.write(0);
  }

  if (BBstate == HIGH) {
    Serial.println("Blue");
    Serial.write ('B');
  } else {
    Serial.write(0);
  }
}

SlaveCodeFINAL.ino

Arduino
const int R = 5; //R = Red LED
const int G = 6; //G = Green LED
const int B = 7; //B = Blue LED
byte BRstate = 0;
byte BGstate = 0;
byte BBstate = 0;

void setup() {
  Serial.begin(38400);
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);
  digitalWrite (R, HIGH);
  digitalWrite (G, HIGH);
  digitalWrite (B, HIGH);
}

void loop() {

  if (Serial.available() > 0) {
    BRstate = Serial.read();
  }
  if (BRstate == 'R') {
    Serial.println("Red");
    digitalWrite (R, LOW); //Set to LOW to turn ON.
  }  else if (BRstate == 0) {
    digitalWrite (R, HIGH);
  }
  if (Serial.available() > 0) {
    BGstate = Serial.read();
  }
  if (BGstate == 'G') {
    Serial.println("Green");
    digitalWrite (G, LOW);
  } else if (BGstate == 0) {
    digitalWrite (G, HIGH);
  }
  if (Serial.available() > 0) {
    BBstate = Serial.read();
  }
  if (BBstate == 'B') {
    Serial.println("Blue");
    digitalWrite (B, LOW);
  } else if (BBstate == 0) {
    digitalWrite (B, HIGH);
  }
}

Credits

HeathenHacks
24 projects • 57 followers
I don't know what I'm doing here.

Comments