Hi all
Dear friends i am stuck in between of my Project to operate 2 channel 12vdc relay via my android mobile using "ARDUINO BLUETOOTH CONTROL DEVICE" android application.
first take a look.
Following is my Code which i am using.
/*
* Home Automation
*/
int relay1 = 3; // light 1
int relay2 = 4; // light 2
int state;
int flag=0; //makes sure that the serial only prints once the state
void setup() {
// sets the pins as outputs:
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
// initialize serial communication at 9600 bits per second:
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 relay will turn off
if (state == '0') {
digitalWrite(relay1, LOW); // relay1 off
digitalWrite(relay2, LOW); // realy2 off
if(flag == 0){
Serial.println("relay: off");
flag=1;
}
}
// if the state is '1' the relay1 will on
else if (state == '1') {
digitalWrite(relay1, HIGH); // set relay1 high
digitalWrite(relay2, LOW); // set relay2 low
if(flag == 0){
Serial.println("relay1: on");
flag=1;
}
}
// if the state is '2' the relay1 will on
else if (state == '2') {
digitalWrite(relay1, LOW); // set relay1 low
digitalWrite(relay2, HIGH); // set relay2 high
if(flag == 0){
Serial.println("relay2: on");
flag=1;
}
}
}
i compile it successfuly
i upload it successfuly
but nothig is heappning when i am pressin "OFF or ON" from my mobile
i am attatched the screen shot of android application whinch i am using for this purpose.
please guide me where i am going wrong,
either i have need to edit somthing in coding or need to change mobile app
please help me to solve
thank you
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
