Pages: [1]   Go Down
Author Topic: Use the android phone to control the relay shield for appliances switch  (Read 3150 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 70
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

We release a ITEAD BT Debugging Assistant software on android, and you can use it to build some home automation prototyping.Use the relay you can switch many appliances easily, so here we show you a simple demo that how to use your android cell phone to control the relay by Arduino via Bluetooth.


We have am Arduino multi-channel relay/switch shield with 2 mechanical relays and 2 MOS switch. Using the 12V power for Arduino, the MOS switch channel can drive the fan by this DC 12V power supply. So we will use the cell phone to control the Arduino, turn on and turn of the fan. It's the same as using the mechanical relay channel to control a fan with external 220/110V AC power supply.

We make a simple controlling protocol, every command includes 3 byte, the first byte is command header, if Arduino receive a character 'C' it means channel control. This command will go with 2 more byte parameter - channel number and channel status, channel can be 1-3 (1 and 2 is the relay channel, 3 and 4 is MOS switch channel),  status can be 0 or 1 (0 means turn off, 1 means turn on). So a simple command for Arduino to turn on the channel 4 is "C41" , turn off channel 1 is "C10".

Plug the BTBee on the IS shield, and plug the shield on Arduino board. Connect the 12V DC fan with Channel 4. Down load this simple demo code into the Arduino - just very simple demo so it without verify code in this project.

Code:
unsigned char state=0;
unsigned char p=0;
char COM[3];
unsigned char c,s;

void setup()
{
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  digitalWrite(4,LOW);
  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  digitalWrite(7,LOW);
  Serial.begin(9600);
}

void loop()
{
  switch(state)
  {
  case 0:
    if(Serial.available())
    {
      COM[p]=Serial.read();
      state=1;
    }
    break;

  case 1:
    p++;
    state=0;
    if(p==3) state=2;
    break;

  case 2:
    p=0;
    if(COM[1]=='1') c=4;
    else if(COM[1]=='2') c=5;
    else if(COM[1]=='3') c=6;
    else if(COM[1]=='4') c=7;

    if(COM[2]=='0') s=0;
    else if (COM[2]=='1') s=1;
    digitalWrite(c,s);
    state=0;
    break;
  }
}
Open the ITEAD BT Debugging Assistant, connect the BTBee and enter the monitor window (more information about how to use this software you can click here) , type the controlling command in input box, if we need to turn on the fan, write "C41" and press the "Send", you can see the "OK" reply from Arduino, and the fan start rotating. If you send the "C40" and get the "OK" reply, you will see the fan slowdown and stop.



More information here: http://iteadstudio.com/application-note/use-android-phone-to-control-arduino-relay-shield
« Last Edit: July 29, 2011, 11:42:26 am by ITead » Logged

Itead Studio - Make innovation easier

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13673
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still an interesting combination... wished that  there were more hours in a day  smiley
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 70
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Now we have finished another small demo, using the Android cell phone with ITEAD BT Debugging assistant to control the DC motor by MotoMama shield. MotoMama is base on L298N and with a XBee interface, so plug the BTBee on it, we can use the software to send the command with speed Parameter -255- +255 to control the speed, also the Direction of rotation.
Logged

Itead Studio - Make innovation easier

Pages: [1]   Go Up
Jump to: