PULSE RELAY

8 years 11 months ago #2796 by matteo_vr
PULSE RELAY was created by matteo_vr
Goodmorning everyone
I wanted to know if is possibe make the relay acts as a button .
do the ON command and after two seconds back in OFF state

thank you

Please Log in or Create an account to join the conversation.

8 years 10 months ago #2914 by matteo_vr
Replied by matteo_vr on topic PULSE RELAY
NO solution????

Please Log in or Create an account to join the conversation.

8 years 10 months ago - 8 years 10 months ago #2918 by markusonfire
Replied by markusonfire on topic PULSE RELAY
When you say "The Relay" which particular relay are you referring to?

In general, yes, it's possible to make a relay activate for two seconds then deactivate.

Just connect it's control pins to GND and a GPIO Output, then have the GPIO pin pulled high for 2 seconds before being pulled low again.

You might need to be more specific or post your existing schematics/code if you want more help.

Please Log in or Create an account to join the conversation.

8 years 10 months ago #2925 by matteo_vr
Replied by matteo_vr on topic PULSE RELAY
thank you
I meant the project .( iot-playground.com/blog/2-uncategorised/...y-switch-arduino-ide ).. I would simply like to return in off the relay because I have to put it in parallel with a button
then if you have a suitable piece of code to my project
graze 1000

Please Log in or Create an account to join the conversation.

8 years 10 months ago - 8 years 10 months ago #2926 by markusonfire
Replied by markusonfire on topic PULSE RELAY
This is pretty simple stuff which you could teach yourself with a bit of study.

Rather than pasting the code for you - I'll help guide you thru one way to do it (Once you understand this, you might think of better and cleaner ways to do it).

See this part in the code:
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio/1") != -1)
    val = 1;
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 according to the request
  digitalWrite(2, val);

It's basically saying "Look at the command recieved, and put the relay into that state by setting the GPIO to high or low"

Essentially what you want, is that for all requests, the relay should be activated for 2 seconds, then turn deactivated (Like a momentary switch).

Although the sketch is designed to maintain and control state (And I'm on the train, so don't have time to re-tweak the whole sketch), here's a quick-and-dirty way to get your desired behavior.:

Change the above code to the following:
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio/1") != -1)
    val = 1;
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 High no matter if the request said High or Low
  digitalWrite(2, 1);

  delay(2000); Wait for 2 seconds

  // Set GPIO2 back to low
  digitalWrite(2, 0);

Like I said, this is a messy Way of doing things, and leaves a lot of artifacts in the code that become superfluous, but try it out, and work from there.

The best way to get the behavior you want is to understand the existing code, and then make small changes, testing as you go.

Good luck.

Please Log in or Create an account to join the conversation.

8 years 10 months ago #2949 by matteo_vr
Replied by matteo_vr on topic PULSE RELAY
tank's this week try and feedback

Please Log in or Create an account to join the conversation.

Time to create page: 0.219 seconds

Forum latest

  • No posts to display.