Trevor RusinJames Tyler MyersMike Dumaine
Published

Bluetooth Controlled Light Switch

Don't stumble around looking for the light switch, turn it on before you walk inside using a bluetooth-enabled android phone!

IntermediateShowcase (no instructions)4 hours36,020
Bluetooth Controlled Light Switch

Things used in this project

Hardware components

Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
Servos (Tower Pro MG996R)
Hitec HS-311 modified to DC
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Mounting Hardware
Screws, drywall anchors, zip ties, aluminum sheet metal, rubber bands
×1
Android device
Android device
×1

Software apps and online services

BlueTerm
android app

Hand tools and fabrication machines

Drill Press
Used the one in the Junior Design Lab, brought my own bits

Story

Read more

Schematics

Schematic

Arduino, bluetooth module, servo amplifier, and 9v battery connection diagram

Code

Arduino Bluetooth Motor controller code

C/C++
It's an arduino .ino file. You upload it to an arduino.
int motorPin1 = 3; // pin 2 on L293D 
int motorPin2 = 4; // pin 7 on L293D 
int enablePin = 5; // pin 1 on L293D 
int state;
int flag=0;        //makes sure that the serial only prints once the state

void setup() {
    // sets the pins as outputs:
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(enablePin, OUTPUT);
    // sets enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);

    Serial.begin(9600);
}

void loop() {
    //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){     
      state = Serial.read();   
      flag=0;
    }   
    // if the state is '0' the DC motor will turn off
    if (state == '0') {
        digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
        digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
        if(flag == 0){
          Serial.println("Motor: off");
          flag=1;
        }
    }
    // if the state is '1' the motor will turn right
    else if (state == '1') {
        digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
        digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high
        if(flag == 0){
          Serial.println("Motor: right");
          flag=1;
        }
    }
    // if the state is '2' the motor will turn left
    else if (state == '2') {
        digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high
        digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
        if(flag == 0){
          Serial.println("Motor: left");
          flag=1;
        }
    }
}

Credits

Trevor Rusin

Trevor Rusin

1 project • 2 followers
Tyler Myers, Trevor Rusin, and Michael Dumaine: we are students in MEGR3171-L at UNC-C.
James Tyler Myers

James Tyler Myers

1 project • 0 followers
Mike Dumaine

Mike Dumaine

1 project • 0 followers
Thanks to Tyler Myers and Michael Dumaine.

Comments