Daniel Harel
Published © GPL3+

Light Switch Bluetooth

Turn on your room light using your phone

IntermediateShowcase (no instructions)921
Light Switch Bluetooth

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Relay Module (Generic)
×1
Hook Up Wire Kit, 22 AWG
Hook Up Wire Kit, 22 AWG
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Schematic

Bluetooth app

Bluetooth app I made
(It may contain some bugs)

Code

The code

C/C++
#include <SoftwareSerial.h>
SoftwareSerial MyBlue(8,10);

String message;
char character;
int lastButtonState = 0;

int buttonPin = 3;
int relayPin = 4;

void setup() {
  Serial.begin(9600);
  MyBlue.begin(9660);
  
  pinMode(buttonPin, INPUT);
  pinMode(relayPin, OUTPUT);
}

void loop() { 
  while(MyBlue.available()){
    character = MyBlue.read();
    if(character == '#'){
      Serial.println(message);
     switch(message.toInt()){
      case 1:
      Serial.println("on bluetooth");
        digitalWrite(relayPin,HIGH);
        break;
      case 0:
      Serial.println("off bluetooth");
        digitalWrite(relayPin,LOW);
        break;
     }
     message = "";
     Serial.println();
    }else{
      Serial.println(character);
      message.concat(character);
    }
  }
  if (digitalRead(buttonPin) == HIGH) {
    if(lastButtonState == 0){
      lastButtonState = 1;
      Serial.println("on");
      digitalWrite(relayPin,HIGH);
    }else if (lastButtonState == 1){
      Serial.println("off");
      lastButtonState = 0;
      digitalWrite(relayPin,LOW);
    }
    delay(300);
  }
}

Credits

Daniel Harel
1 project • 2 followers
16 years old, Loves building, programming electronics and 3D printing.
Contact

Comments

Please log in or sign up to comment.