I’ve been playing around with a single channel relay, turning an led on/off via a button. Things worked fine.
The next step was to use the Blynk app. After fiddling about with the installation etc, it worked fine.
The next idea was to use to separate pins to control the same relay. One pin to energise the relay, until the button is pressed again and the second pin to work as a timer/delay, in order to de-energise the relay after X amount of time.
Now, with both pins connected to the same relay, nothing. Testing them individually, it’s okay (other than not having the code for the delay).
Whats the best way around this? Using diodes between each pin or transistors? Or can this be sorted in code? Pull a pin down when the other pin is high?
Just to add, I’m not using my code with the Blynk app, as their example code for an LED worked fine. My problem has only arisen when using two pins.
I’ve been playing around with a single channel relay, turning an led on/off via a button. Things worked fine.
The next step was to use the Blynk app. After fiddling about with the installation etc, it worked fine.
The next idea was to use to separate pins to control the same relay. One pin to energise the relay, until the button is pressed again and the second pin to work as a timer/delay, in order to de-energise the relay after X amount of time.
Now, with both pins connected to the same relay, nothing. Testing them individually, it’s okay (other than not having the code for the delay).
Whats the best way around this? Using diodes between each pin or transistors? Or can this be sorted in code? Pull a pin down when the other pin is high?
Just to add, I’m not using my code with the Blynk app, as their example code for an LED worked fine. My problem has only arisen when using two pins.
Thank you in advance
So you connected 2 digital pins to the relay? A schematic would def help. If you don't have much experience try easyeda or fritzing.
And by a single channel relay you mean a relay module? Hopefully you aren't driving the relay directly from the digital pins without the protection relay modules provide. If you are using a module, be aware, that most of them are 5v relays, and your ESP is 3.3v. You might be able to properly trigger the relay, but it would be best to communicate with it via a transistor with the relay VIN to 5v (attached).
What you are asking sounds reasonable enough to sort out in code, but again, a schematic would go a long way even if just roughly drawn but atleast accurate to your setup.
It is a very bad idea to connect two outputs together, especially
when one can be high while the other is low! Doing that shorts
the Vcc supply to ground through both outputs! Both probably
will be ruined.
It seems that you should be able to do what you want with good
code and only one output.
Herb
alex_fagard:
So you connected 2 digital pins to the relay? A schematic would def help. If you don't have much experience try easyeda or fritzing.
And by a single channel relay you mean a relay module? Hopefully you aren't driving the relay directly from the digital pins without the protection relay modules provide. If you are using a module, be aware, that most of them are 5v relays, and your ESP is 3.3v. You might be able to properly trigger the relay, but it would be best to communicate with it via a transistor with the relay VIN to 5v (attached).
What you are asking sounds reasonable enough to sort out in code, but again, a schematic would go a long way even if just roughly drawn but atleast accurate to your setup.
I’ve added a terrible drawing of a schematic.
Correct, I want to drive a relay with two pins. One pin used with a delay/timer and one to toggle, such as a light switch.
Both work as a stand alone, but not together.
I was hoping for a known hardware solution, as coding is not my strong suit but I’ll read into it that way more. Thank you
Edit:the schematic won’t upload and I have no way of changing the file type currently as my mobile phone in faulty.
It just shows a relay module being powered by an external power source with the only connections from the Wemos being two digital pins, that are used to trigger the relay
@herbschwarz
Ah, I was thinking that may be the case but couldnt seem to get around it. Cheers
@Paul__B
You must be correct, because as far as I can tell, I’ve given my information over and asked if there’s a way to control a relay via two pins. Both with different functions.
Maybe I’m not asking the right questions? I’ve tried them separate, which work. Together, they don’t. Is there a way to get both to work together, either with hardware or code. So I’m unsure to what you’re actually getting at, as thats what I asked in the #1 post. Cheers
Why would it need to use a different pin depending on how long you want to turn the relay on?
This is an XY-problem - probably you're not sure how to program the desired behavior using a single pin (why, I'm not sure - this doesn't sound like challenging behavior to achieve, though you haven't showed us your code), but have written code to do the two functions with different output pins, and then tried to connect them together to combine that functionality in hardware, because you don't know how to do it in software.
Don't connect two pins together that are both set as OUTPUT - if one is set HIGH and the other LOW, they will fight eachother, and this can damage the microcontroller (as it will probably exceed the max current spec for the pin). This sort of thing should be done in software, not hardware. There are ways, but they should be used only when a software solution is impractical, as they require additional components and more wiring work and add additional points of failure and opportunity for wiring mistakes.
Why would it need to use a different pin depending on how long you want to turn the relay on?
This is an XY-problem - probably you're not sure how to program the desired behavior using a single pin (why, I'm not sure - this doesn't sound like challenging behavior to achieve, though you haven't showed us your code), but have written code to do the two functions with different output pins, and then tried to connect them together to combine that functionality in hardware, because you don't know how to do it in software.
Don't connect two pins together that are both set as OUTPUT - if one is set HIGH and the other LOW, they will fight eachother, and this can damage the microcontroller (as it will probably exceed the max current spec for the pin). This sort of thing should be done in software, not hardware. There are ways, but they should be used only when a software solution is impractical, as they require additional components and more wiring work and add additional points of failure and opportunity for wiring mistakes.
Okay, thank you.
I’ll leave it there then and look into software and maybe virtual pins of Blynk.