Adding a simple limit switch

@scamilleri1228 an you send a pic of your connection of esp8266 with relay module.

@scamilleri1228 this worked for me and is this wat you want? i had connected a led between NC and com terminal.

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
int x;
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  digitalWrite(4,HIGH);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
  Cayenne.loop();
  
}
CAYENNE_IN(1)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    x = 1;
    Serial.println("x is 1");
    digitalWrite(4, HIGH);
  }
  else
  {
    x = 0;
    Serial.println("x is 0");
    digitalWrite(4, LOW);
  }
}
1 Like

shramiksalgaonkar
November 8
@scamilleri1228 this worked for me and is this wat you want? i had connected a led between NC and com terminal.

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
int x;
// WiFi network info.
char ssid = β€œβ€;
char wifiPassword = β€œβ€;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = β€œβ€;
char password = β€œβ€;
char clientID = β€œβ€;

unsigned long lastMillis = 0;

void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
digitalWrite(4,HIGH);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();

}
CAYENNE_IN(1)
{
int currentValue = getValue.asInt();
if (currentValue == 1)
{
x = 1;
Serial.println(β€œx is 1”);
digitalWrite(4, HIGH);
}
else
{
x = 0;
Serial.println(β€œx is 0”);
digitalWrite(4, LOW);
}
}
Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.

That’s did it, thank you again for sticking with me through this.

2 Likes