Newbie here so apologies in advance. I have a photon wired to a 2Channel relay to open/close my garage door. It was working perfectly fine for a few hours and I left the house. When I came home my neighbor told me my garage door was opening and closing repeatedly. No matter how I wire this thing (use 1 relay or both relays) or write the code the relay will just randomly close and open again. Is this some sort of power issue? I am using USB to power the photon.
yea i have it disconnected now just sitting in my lap. The relay will just randomly close and open back up even if I do not call the relayOne function (though that works too ) I really don’t want to pay $30 for the RelayShield as that will push the cost of this project over some off the shelf options. If I get rid of my garage code and flash Tinker to my photon the relay does NOT randomly open and close
Yup same problem. Interestingly enough I tried using the Blynk app and I can create a momentary button that toggles the relay to make it work. No random opening and closing. This isn’t an ideal solution though since I cannot integrate IFTTT proximity recipes
I had some issues getting a relay to toggle off correctly. I suspect your pin is floating and the relay has a drive transistor which is a very sensitive FET. Try this:
I’ve had some of the exact same issues. My wife woke up early on Saturday morning to the garage door going up and down. Funny how toggling - in a loop - means it will continue to loop and continue to toggle.
I’m pretty much a newbie too, so much of this is a guess (although our garage door going up and down all night was not a guess!). But, could the brackets in your first code example be causing part of the problem? From this page the setup and loop functions each need to be contained in open/close brackets:
// actions are performed in the functions "setup" and "loop"
// but no information is reported to the larger program
void setup()
{
// ...
}
void loop()
{
// ...
}
The brackets in your code don’t seem to be enclosing the functions. I don’t have the vaguest notion if that’s causing the issue, but I thought it might be worth a look.
In my garage door expedition Part B, I am using Tinker with the Photon Relay Board. I just push the respective Digital Write Button to go HIGH and then push it again to go low: the poor man’s version of a momentary. Someday, when I understand more, I’d like to improve that situation.
Good thinking though not quite right this time. Functions can be defined in the top level scope so this won’t be his issue. His control flow is like this (pseudo code)
define a variable relay1 globally for all functions
begin setup function (executed once by the system)
register a relay1Pulse with the cloud API
set initial state of relay1 to output
end setup function
begin loop function (called many times by the system)
do nothing!
end loop function
begin relay1Pulse function (only called remotely via the cloud API)
relay on
wait one second
relay off
reply to the caller with a value 1 to show them we succeeded
end relay1Pulse function
The control flow doesn’t enter functions as they are defined.
Hi, Totally not helpful for the actual relay issue. However my garage door remote was a 3V version. So I shorted the button on the remote and then have the photon to give me 3V to the battery contacts for 1/2 a second and go low again. Works like a charm.
HTH
Gerry