Relay clicking, but not actually working on GPIO

Hi there, I’m trying to build a simple remote garage door opener (as many others have done!) and I’m running into an issue I just can’t seem to solve.

I have a relay board connected to VIN, GND, and D0 on my Photon. The C and NO pins of the relay are connected to the garage door opener (and opens/closes the door when shorted out). Code is pasted below.

So here’s what happens: When I set D0 HIGH, the relay board LED lights up and the relay clicks. The first time upon powerup, the door opens or closes as expected. After that, further attempts do not open or close the door until I shut off the Photon and power it all back up.

Oddly, if I move my wire from D0 to 3v3, the door opens and closes reliably. This obviously isn’t an option since 3v3 isn’t switchable.

Any ideas? I’ve read other tutorials and watched videos of others putting these things together simply… maybe I’m doing something wrong :slight_smile:

my code:

int lastOpenSensor = 0;
int openSensor = 0;

int relayPin = D0;
int doorOpenSensorPin = D1;

void setup() {
    Particle.function("openClose", openClose);
    Particle.variable("openSensor", &openSensor, INT);
    pinMode(relayPin, OUTPUT);
    pinMode(doorOpenSensorPin, INPUT_PULLUP);


void loop() {

    if (openSensor != lastOpenSensor) {

        lastOpenSensor = openSensor;


void publishDoorState() {
    if (openSensor == 1 ) {
        Particle.publish("doorState", "door-opened", 1);
    else {
        Particle.publish("doorState", "door-closed", 1);

int openClose(String value) {
    digitalWrite(relayPin, HIGH);
    digitalWrite(relayPin, LOW);

    return 0;

int getDoorSensor() {
   //your code here
   openSensor = digitalRead(doorOpenSensorPin);
   return openSensor;

@wells Exactly which pins on the relay board are connected to VIN, GND and D0 on the Photon. I would assume VCC to VIN, GND to GND and IN to D0? The chances are that your relay is Low Level Trigger. That means the relay is switched from NC to NO when D0 is LOW and this means immediately after you do your pinMode(relayPin, OUTPUT); you need to digitalWrite(relayPin, HIGH); to set the relay off. Your function openClose needs to have HIGH and LOW swapped.

thanks for your reply! it’s definitely not a low level trigger—I see continuity between COM and NO when D0 is HIGH, and continuity between COM and NC when D0 is LOW.

I see at least 2 issues you may encounter. The relay says 5v-12v and the photon only outputs 3.3v. Also, there’s no rating for the current draw on the coil. The photon only outputs about 20mA on the GPIO pins and so it may not supply enough power to activate the relay reliably. You can try some things such as add capacitance to the Photon Vin or use a MOSFET or transistor to supply 5V to the relay coil. Since you can activate the coil by hooking the coil to 3.3v directly, this tells me it may be both capacitance and current. When powering from Vin directly you may be able to draw a short burst of current that allows operation at the 3.3V.

1 Like

@ninjatill After my post earlier I reflected on the operation of the relay board and had a look at the Amazon site details. I belief you are right that signal voltage or sourcing current is the issue - the solution to which for @wells is either try putting a transistor or mosfet switch on D0 to switch higher current and 5V to the IN pin OR buy another relay board with an opto-isolator that can be controlled directly from the photon pin.

1 Like

I believe the Opto-Isolator boards all have the JD-Vcc to Vcc Jumper, and are Active LOW, as @armor originally expected.

@wells, a Relay such as This should work well for you, per the comments.
By removing the JD-Vcc Jumper, the relay coils are not powered by the Photon Pins, see this Thread for details.