Problem opening NCD2Relay with Blynk

Helllooooooo Particle People. I have a Photon that I’m trying to use to open a relay with the Blynk cloud app. The relay board I’m using is the NCD2Relay. I am trying to use pin D0 or D7 to turn on the relay. I’m not sure I have this right but if someone could take a look I would be very happy. BTW, I can turn on the blue LED with D7 pink through Blynk, so I’m pretty sure that part is working. Just not sure about the relay code. Do I have to setup two serial communications? serial and serial1?

Thanks in advance.

here is my code:

// This #include statement was automatically added by the Particle IDE.
#include "NCD2Relay/NCD2Relay.h"
#define BLYNK_PRINT Serial
#include "blynk/blynk.h"

NCD2Relay relayController;


char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  pinMode(D0, OUTPUT);
  pinMode(D7, OUTPUT);
  relayController.setAddress(0,0,0);
}

void loop()
{
    Blynk.run();    
    if(D0==HIGH || D7==HIGH){
        relayController.turnOnRelay(1);
    }
    else{
        relayController.turnOffRelay(1);
    };
}

For controling the relays on that board, you’d rather use a Virtual Blynk pin and not waste one precious physical pin.
Next, since D0 is the dedicated I2C data pin (which is the interface that board uses to communicate with the Photon) it’s not good to mess with that one.
And finally, reading the state of a physical GPIO would be if(digitalRead(D7) == HIGH).

What you do there is like this

// defines in the framework
#define D0    0
#define D7    7
#define HIGH  1

// your code translated
if (0 == 1 || 7 == 1)
  // will never be true

This worked. You’re the man, man. Thanks a lot.

1 Like