Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Danny van den Brande
Published © CC BY-SA

Arduino/Android - BLUETOOTH Home Control + APP - HC-06

Hello world! Today I made a Android APP to control 8 relays with Arduino using the HC-06 Bluetooth module.

BeginnerProtip1 hour27,196
Arduino/Android - BLUETOOTH Home Control + APP - HC-06

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
2 x 1 channel Relay KY-019
×1
HC-06 Bluetooth Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Power cables + lamp sockets
×1

Story

Read more

Schematics

Schematic

Code

BLUETOOTH_home_control.ino

Arduino
This code will work with the app i created for it to control relays.
You can build a home automation system with it, or control other devices.
/*
Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
This code will work with the app i created for it to control relays.
You can build a home automation system with it, or control other devices. 
I build it originaly for home control.
If you want the Code for the APP open source You can contact me @ contact@arduinosensors.nl
 */
int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;
int relay5 = 6;
int relay6 = 7;
int relay7 = 8;
int relay8 = 9;

String readString;

void setup() {
  Serial.begin(9600);
  pinMode(relay1, OUTPUT); 
  pinMode(relay2, OUTPUT); 
  pinMode(relay3, OUTPUT); 
  pinMode(relay4, OUTPUT); 
  pinMode(relay5, OUTPUT); 
  pinMode(relay6, OUTPUT); 
  pinMode(relay7, OUTPUT); 
  pinMode(relay8, OUTPUT); 
}

void loop() {
  while (Serial.available()) {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }
  if (readString.length() >0) {
    Serial.println(readString);
    if (readString == "1 ON")     
    {
      digitalWrite(relay1, HIGH);
    }
    if (readString == "1 OFF")
    {
      digitalWrite(relay1, LOW);
    }
    //relay2
    if (readString == "2 ON")     
    {
      digitalWrite(relay2, HIGH);
    }
    if (readString == "2 OFF")
    {
      digitalWrite(relay2, LOW);
    }
    //relay3    
    if (readString == "3 ON")     
    {
      digitalWrite(relay3, HIGH);
    }
    if (readString == "3 OFF")
    {
      digitalWrite(relay3, LOW);
    }
    //relay4    
    if (readString == "4 ON")     
    {
      digitalWrite(relay4, HIGH);
    }
    if (readString == "4 OFF")
    {
      digitalWrite(relay4, LOW);
    }
    //relay5    
    if (readString == "5 ON")     
    {
      digitalWrite(relay5, HIGH);
    }
    if (readString == "5 OFF")
    {
      digitalWrite(relay5, LOW);
    }
    //relay6    
    if (readString == "6 ON")     
    {
      digitalWrite(relay6, HIGH);
    }
    if (readString == "6 OFF")
    {
      digitalWrite(relay6, LOW);
    }
    //relay7    
    if (readString == "7 ON")     
    {
      digitalWrite(relay7, HIGH);
    }
    if (readString == "7 OFF")
    {
      digitalWrite(relay7, LOW);
    }
    //relay8    
    if (readString == "8 ON")     
    {
      digitalWrite(relay8, HIGH);
    }
    if (readString == "8 OFF")
    {
      digitalWrite(relay8, LOW);
    }
    //All on / off    
    if (readString == "ALL ON")     
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, HIGH);
      digitalWrite(relay3, HIGH);
      digitalWrite(relay4, HIGH);
      digitalWrite(relay5, HIGH);
      digitalWrite(relay6, HIGH);
      digitalWrite(relay7, HIGH);
      digitalWrite(relay8, HIGH);
    }
    if (readString == "ALL OFF")
    {
      digitalWrite(relay1, LOW);
      digitalWrite(relay2, LOW);
      digitalWrite(relay3, LOW);
      digitalWrite(relay4, LOW);
      digitalWrite(relay5, LOW);
      digitalWrite(relay6, LOW);
      digitalWrite(relay7, LOW);
      digitalWrite(relay8, LOW);
    }
    //next
    readString="";
  } 
}

Credits

Danny van den Brande

Danny van den Brande

36 projects • 109 followers
"Hello world."

Comments