I need to wire in a manual push button into my setup to activate a relay on the relay shield. This would be for exiting the building, you would just press the “EXIT” button and the relay would activate for a given amount of time.
I have the button defined as “D7”
I won’t post the entire code for my project, its long and everything else is working, but here are the pertinent parts for this addition:
if (digitalRead(rex) == LOW){
digitalWrite(relay,HIGH);
delay(5000);
digitalWrite(relay,LOW);
}
I have tried making pinmode “rex” INPUT_PULLUP, and INPUT_PULLDOWN, and obviously changing the digitalRead state as well, and nothing changes, even when jumping straight across with a jumper wire. Any idea as to what I may be doing wrong?
D7 comes on when I have it in INPUT_PULLDOWN and jump from VIN to D7, and is on all the time and goes out when under INPUT_PULLUP and I jump across D7 and GND
I haven’t tried another pin, D2 and D3 are being used, D4 and D5 are first the other relays, and I wasn’t sure about D0 and D1 being for I2C use, I know that messes with my wiegand code, so I just stayed away until I could get everything working. Good to know about the pull_up and VIN issues, should have looked deeper in the docs. I’ll try running to 3v3 and post back.
I’m using D6 already, I’ll use one of the A pins. In the meantime, I’m having an issue getting into the Web IDE to change the pinmode. I’m getting an application error from something called Heroku, I guess I should send in a support ticket, and wait for a response.
@ScruffR, in the meantime, I have this in pinmode INPUT_PULLUP for D7, so jumping to GND should work correct? The D7 light goes out, but still no relay activation.
Not seeing the context of your relay logic does not help. Hence I suggested to use D7 as software controlled indicator to find out if you get to that piece of code at all.
Adding some Serial.print() statements might help getting an idea of what’s going on in your code too.
Here is the rest of the code for this, the Web IDE came back up a few minutes ago. @ScruffR I put the rex back to INPUT_PULLDOWN with no change jumping to 3v3.
I also tried changing to A0, same result.
I see you have your button logic inside the subscription handler. So you need to have the button pressed before the event is fired and keep it pressed till this subscription has been processed. Is this intended?
I’d put that block in loop() to have the button checked regularly - at least while you are testing the button feature.
@ScruffR, That did the trick! Sorry for all the simple problems, I bought my first photon last January and it was my first time ever writing any kind of code, so I’m a little behind the curve. Thanks for all the help.