Sei sulla pagina 1di 4

Food Living Outside Play Technology Workshop

android bluetooth controlled outlet


by smaw51 on July 25, 2012

Table of Contents

android bluetooth controlled outlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: Android bluetooth controlled outlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

http://www.instructables.com/id/android-bluetooth-controlled-outlet/
Intro: Android bluetooth controlled outlet
This is a fairly simple and relatively cheap project that allows you to turn on and off an outlet via Bluetooth on your android phone. The materials I used were:

5V Relay Module -- www.amazon.com/gp/product/B0057OC6D8/ref=oh_details_o00_s00_i02 (any other relay should do, this was what I found)
Arduino R3 -- http://www.amazon.com/gp/product/B006H06TVG/ref=oh_details_o00_s00_i01
Bluetooth Shield for Arduino -- http://www.amazon.com/gp/product/B007BYI172/ref=oh_details_o04_s00_i00 (the regular BT antennas will work too)
4 section gang box, or any other box to hold everything.
outlet, wires, extra surge protector, acrylic sheet, or any other cover.

If you were to buy everything fresh, it would probably run around 65-75 dollars depending on where and how you shop.

With the bluetooth shield I got, the printed Tx and Rx selectors are reversed, at least for the libraries i found. The relay is also opposite what you would think, as in HIGH
closes the relay and LOW opens the gate.

Split the one of the lines on your power cord, I did the black one, attach the one going to your wall to the common terminal and the other to the normally open terminal.
more info can be found here:
http://arduino-info.wikispaces.com/ArduinoPower
all about power and the arduino as well as nice pictures and stuff.

You will need to have a separate power source for your arduino, I have a 9v running out the back.

I have found BlueTerm to be the best way of communicating from your phone to the arduino BT
https://play.google.com/store/apps/details?id=es.pymasde.blueterm&hl=en
It is free and smooth. There are other programs out there that do just the same and maybe more, But I like this one because it's simple.

Upload the code and make sure everything is plugged in and you're ready to turn off your lights!

I did try to make this outlet dim-able, but my relay didn't like it, it just stayed open when I had something plugged in.

code:

#include <SoftwareSerial.h> //Software Serial Port


#define RxD 6 //oppsite what the board is lables as
#define TxD 2//oppsite what the board is lables as
#define switchPin 9 //relay connector
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
char recvChar;

void setup()
{
Serial.begin(38400);
pinMode(RxD,INPUT);
pinMode(TxD, OUTPUT);
pinMode(switchPin,OUTPUT);
setupBlueToothConnection();
digitalWrite(switchPin,HIGH); //turns relay off
}

void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
delay(1000);
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is ready!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}//end setup bt connection

//Checks if the response "OK" is received


void CheckOK()
{
char a,b;
while(1)
{
if(blueToothSerial.available())
{
a = blueToothSerial.read();

if('O' == a)
{
// Wait for next character K. available() is required in some cases, as K is not immediately available.
while(blueToothSerial.available())
{
b = blueToothSerial.read();
break;
}
if('K' == b)
{
http://www.instructables.com/id/android-bluetooth-controlled-outlet/
break;
}
}
}
}

while( (a = blueToothSerial.read()) != -1)


{
//Wait until all other response chars are received
}
}// end check ok

void sendBlueToothCommand(char command[])


{
blueToothSerial.print(command);
CheckOK();
}

void loop()
{
recvChar = blueToothSerial.read();
Serial.println(recvChar);
Serial.write(recvChar);

switch(recvChar)
{
case '1':
digitalWrite(switchPin,LOW);//opposite to what you would think
blueToothSerial.println("relay on");
break;

case '0':
digitalWrite(switchPin,HIGH);
blueToothSerial.println("relay off");
break;

}// end switch

}//end loop

http://www.instructables.com/id/android-bluetooth-controlled-outlet/
Related Instructables

Android-
Yet SEEED Studio / Simple Controlled
Another Arduino -- 5V Arduino Arduino Web Controlled Pneumatic
Arduino 110v Relay module Stoplight Controlled Valentine by Cannon
Power (Digital) -- Controller by Relay Box by gschoppe Powered By
Controller by Electronic Brick natantus Arduino by
thematthewknot
maewert by rik zachrattner

http://www.instructables.com/id/android-bluetooth-controlled-outlet/

Potrebbero piacerti anche