Pages: [1]   Go Down
Author Topic: ARDUINO TO OPERATE A RELAY REMOTELY  (Read 1597 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i coped the code from http://forum.arduino.cc/index.php?topic=177551.msg1322776#msg1322776nothing similarity but but the code below is  using 2 commands  of light senser after a interval i want it to accept 5 commands with interval and light pin 13 to a given period of time ,actually i will  place a old phone on the light senser and give 5 miss call  after a interval of time making the relay to switch on


Code:
[code]///////Define Pins
int sensepin = 0;
int ledpin =13;
int Counter1 = 0; //Relay closed seconds counter
int Counter2 = 0; //Relay closed minutes counter
int Counter3 = 0; //Relay open seconds counter
int Counter4 = 0; //Relay open minutes counte
void setup() {
  analogReference(DEFAULT);
  pinMode (ledpin, OUTPUT);  //The LED pin needs to be set as an output
  Serial.begin(9600);
}

void blinkonce ( ) {
  
  digitalWrite(ledpin,HIGH);
  delay(900000);//delay(1800000)= HALF HOUR ,,,delay(900000)IS 15 MIN
  digitalWrite(ledpin,LOW);
  

}

void loop() {

  do{
    delay(80000); // delay for of time
   int val = analogRead(sensepin);
    Serial.println (val);
  if (val >10 )  //if the value is (val > 70)?
   // read the state of the relay value:
   sensepin = digitalRead(sensepin);
  // check if the relay is closed.
   if (sensepin == LOW) {    
    //    
     digitalWrite(sensepin,LOW);
       delay(80000); // delay for of time
       Counter1++; //Increment seconds closed counter
          if (Counter1 > 10){
            
      Counter2++; //Increment minutes closed counter
      Counter1 = 0;}//Reset seconds closed counter
      delay(60000); // delay for of time
  }
     }while (sensepin == LOW);//Continue until relay opens
        if (sensepin == HIGH){ //Print the total minutes closed
        Serial.print("Minutes On: ");
        Serial.println(Counter2);
        Counter2 = 0;
  }
  
  do{
   // read the state of the relay value:
   sensepin = digitalRead(sensepin);
  // check if the relay is open.
   if (sensepin == LOW) {    
    // turn LED off:    
     digitalWrite(sensepin, LOW);
      delay(60000); //delay for of time
       Counter3++; //Increment seconds open counter
     delay(1000); //Wait one second
     if (Counter3 > 10){
      Counter4++; //Increment minutes off counter.
      Counter3 = 0;}//Reset seconds off counter
       sensepin = digitalRead(sensepin);
  }
     }while (sensepin == LOW);//Continue until relay closes
        if (sensepin == HIGH){ //Print the total minutes open
        Serial.print("Minutes Off: ");
        Serial.println(Counter4);
        Counter4 = 0;//Reset minutes off counter
         blinkonce();
    delay(60000); //delay for of time

  }
}
}
[/code]


* Untitled.png (37.54 KB, 614x544 - viewed 31 times.)
« Last Edit: July 20, 2013, 02:48:36 pm by love7007 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you have a question?

Why are you SHOUTING?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: