Go Down

Topic: ARDUINO TO OPERATE A RELAY REMOTELY (Read 2472 times) previous topic - next topic


Jul 20, 2013, 09:01 pm Last Edit: Jul 20, 2013, 09:48 pm by love7007 Reason: 1
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: [Select]
[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() {
 pinMode (ledpin, OUTPUT);  //The LED pin needs to be set as an output

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


void loop() {

   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) {    
      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: ");
       Counter2 = 0;
  // 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: ");
       Counter4 = 0;//Reset minutes off counter
   delay(60000); //delay for of time



Did you have a question?

Why are you SHOUTING?
"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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131