Monday, September 30, 2013

arduino-bluetooth switch


`

                                           Bluetooth Switch

moinakhtar J.D
frugal-labs tech solution PVT. LTD

1. Bluetooth module

AT commands can found here(u.com/files/ElecFreaks/HC-0305 serail module AT commamd set 201104 revised.pdf)
According to datasheet and referring to schematics of HC-05 used in this bluetooth module
we can see 6 pin are provoided for external use,
Hold module such that you get antenna at the top and external pin's facing earth,as shown in below fig.

if we consider the first at you left is first pin of board then we have
pin 1 -- Not connected
pin 2 – KEY
pin 3 – RX
pin 4 – TX
pin 5 – 5v
pin 6 – GND

Note 1 :: when we verify RX and TX pin of board with actual RX and TX of module(CHIP) using multimeter in contunity mode, we found that RX on board actulally TX of CHIP and vice versa.

2.MICROCONTROLLER
we have used arduino board

as show in the image we have RX and TX for serial communication with arduino

3.SWITCH

for this project an SSR is used HFD27/005 s
datasheet can be found here(http://www.datasheetdir.com/HFD27-005-S+download)
remember pin below 1A mark is pin-16
by seeing data-sheet we have this following diagram

look at the last image,
when SSR is not triggered 4 and 6 are connected and 13 and 11 are connected together leaving 8 and 9 unconnected respectively
and here when a 5v is applied at 1 and 16 ,pin 4 and 8 will be connected together and 13 and 9 are connected together ,allowing current to pass through them,and leaving 6 and 11 unconnected respectively,
we gone use this phenomenon,for switching AC current

NOTE:during this project i only had HFD27/005 SSR,any other SSR which can controlled using 5v can be used,just make sure where to apply voltage how switches work

4.BLUB
we have used a normally available 60 watt bulb

put it in a plug and connect to switch and check if it is working properly
then turn off the main power and take out plug from AC socket ,

NOTE 2:: you are dealing with AC power so be safe and take required remedies before proceeding from here

CONNECTION

step 1 :: connection between bulb and AC

you will see two wires, select any one wire out of two,and cut in middle, i chose +ve or red coloured wire,
note :: doesn’t matter which wire you choose because AC is available for both negative and positive cycle.

for reference purpose ,i will call the these new terminal as 1 and 2

step 2 :: connection between SSR and BULB
connect terminal 1 to pin 4 on SSR ,and terminal 2 to pin 8 on SSR,

step 3 :: connection between Bluetooth module and Arduino

bluetooth pin ---- Arduino pin
pin3 / RX                     RX
pin4 / TX                      TX
pin5 /5V                       5V
pin6 / GND                 GND

if you have followed some other post then you might get confused about my connection,because usually we connect RX to TX and vice versa for communication,
but recall(Note 1 )
i said
when we verify RX and TX pin of board with actual RX and TX of module(CHIP) using multimeter in continuity mode, we found that RX on board actually TX of CHIP and vice versa.

.hurrah.... we are actually connecting RX to TX and TX to RX,so my connection are pretty good and universly correct
,
connect bluetooth module with system's bluetooth and activate SPP ,protocol
more details on configuring(http://www.instructables.com/id/Cheap-2-Way-Bluetooth-Connection-Between-Arduino-a/)

or just download Bluetooth SPP application(https://play.google.com/store/apps/details?id=mobi.dzs.android.BluetoothSPP&hl=en) for android and follow simple steps,and you will be connected with module Serially

step 4 :: connection between SSR and arduino

SSR ----------- Arduino
pin 1                pin 10
pin 16              pin GND

you may ask ,why we are connecting pin 1 of SSR to pin 10 of Arduino,and not to VCC?
Ans: if we connect pin 1 directly to the VCC of arduino,the SSR will be triggerd ,just by powering Arduino,and light will glow without any data through bluetooth,but we want to make a switch ,i.e wheever i recive perticular number from bluetooth i will turn bulb ON or OFF ,corresponding to number,so programicaly activate SSR i am connecting it to the pin 10.
ALL done with connection and now its time to program

PROGRAM

concept here is ,turn the bulb ON ,if we recieve 1 and Turn bulb OFF if we recive 0 via bluetooth

//initialize relay_pin to 10
int relay_pin=10;
//initializing INBYTE as Intiger
int INBYTE;

void setup(){
//I configured my HC-05 to communicate at 38400 baud rate and hence i am using
  Serial.begin(38400);
//make pin 10 as OUTPUT
  pinMode(relay_pin,OUTPUT);
}
void loop(){
//print Press 1 to ON or 0 to turn OFF LIGHT: on all serial monitor connected to bluetooth
  Serial.println("Press 1 to ON or 0 to turn OFF LIGHT:");
// stay here so long as COM port is empty
  while (!Serial.available());
// read next available byte
  INBYTE = Serial.read();
// if it's a 0 (zero) dont trigger SSR
  if( INBYTE == '0' ) digitalWrite(relay_pin, LOW);
// if it's a 1 (one) trigger SSR
  if( INBYTE == '1' ) digitalWrite(relay_pin, HIGH);
  delay(50);
}


that it plug you AC plug to its socket and press turn on button,bulb will not glow.
Now from device you have connected to bluetooth module,and send 1 to turn ON bulb and ) to turn OFF bulb
that's it enjoy your bluetooth switch and
why we have dummy switches.......??????
wait for next post..to know more
till then enjoy your BT-switch 

hi freind sorry for delay ..here is 

SOME THING NEW FROM HERE

why we are using demo switch?

Assume condition when you dont know ,where you have kept you mobile or the mobile's battery is pretty low.then you cant connect to bluetooth and hence cant use your switch

To over come this problem .we have used demo switch so that you can controll your bluetooth switch even by mechanical switch

first of all we need to make connection
connect one pin to GND and other to resistor we call this pin as switch pin , then connect the other pin to VCC ,
after this connect switch pin to any one pin of M-controller.in my case i connected it to pin 8.
NOTE:
we need this connection beacouse when i change the state of switch button ,my controller will read either 0,or 1 due to establishment /demolishing of connection on between VCC and GND
dont forget to use resistor between switch pin and VCC .

Similarly we change our program to update the components used

int sys = 0;
int ab = '0';
//int ab1 = INBYTE;
 
int as = LOW;
//int as1 = sbyte;
int INBYTE='0';
int sbyte;
int relay_pin=3;
int s = 8;

void setup(){
  Serial.begin(9600);
  pinMode(relay_pin,OUTPUT);
  pinMode(s ,INPUT);
}
void loop(){
  Serial.println("Press 0 to turn OFF or 1 to turn ON LIGHT:");
  //delay(1000);
  sbyte = digitalRead(s);
  //int sys;
  if(Serial.available()){
    INBYTE = Serial.read();
    Serial.println(INBYTE);
  }
  //if (INBYTE == ab) sys = sys;
  //if (sbyte == as) sys = sys;
  if (INBYTE != ab){
    sys =!sys;
    ab=INBYTE;
  }
  if (sbyte != as) {
    sys =!sys;
    as=sbyte;
  }
  //delay(1000);
  if ( sys == 1) digitalWrite(relay_pin, HIGH);
  //delay(1000);
  if ( sys == 0) digitalWrite(relay_pin, LOW);
  //delay(1000);
 
}

No comments:

Post a Comment