Go Down

Topic: controlling 5v relay with iviewer (Read 180 times) previous topic - next topic

sixrc

hello.
i am trying to open my garage through iviewer 4 on adroid, using an arduino shield and a relay.
when i send the string from iviewer to the arduino it works but after the pulse it doesn't stop. the relay keeps pulsing for a while in a loop. i wanted to send just one pulse.

i'd be glad if somebody could help me.

Code: [Select]

#include <SPI.h>
#include <Ethernet.h>

//---- MAC----------
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 25);
//-----  PORTA (80)------
EthernetServer server(80);

//---RELAY (OUTPUTS)--------

int modRele1S1 = 8;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
 
 
  //---start das saidas
  pinMode(modRele1S1, OUTPUT);
  digitalWrite(modRele1S1,HIGH); 
 
}

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("novo cliente");
    // an http request ends with a blank line
    String vars;
   
    //--var -----------------
   
    int varmodRele1S1 = 0;
 
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.print(c);
        vars.concat(c);
        //------ command fusion -------------------------
       
        if (vars.endsWith("/modRele1S1onoff")) varmodRele1S1 = 1; //----garage door------
       
       
   
           
           //-----------ON/OFF----------------
          if(varmodRele1S1 == 1)
            {
            digitalWrite(modRele1S1,LOW); // pulse
            delay(300);
            digitalWrite(modRele1S1,HIGH); // pulse

      }
    }
  }
}

Go Up