#include #define VIRTUAL_PIN V9 #define VIRTUAL_PIN V10 #define VIRTUAL_PIN V7 #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include char token[] = "$$$$$$$"; // Your network name and password. char ssid[] = "0000000"; char password[] = "#######"; #define PIN 10 #define PIN 11 #define echoPin 12 // Echo Pin #define trigPin 13// Trigger Pin int maximumRange = 200; // Maximum range needed int minimumRange = 0; // Minimum range needed long duration, distance; // Duration used to calculate distance // Set ESP8266 Serial object #define EspSerial Serial ESP8266 wifi(EspSerial); void setup() { EspSerial.begin(115200); delay(10); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); Cayenne.begin(token, wifi, ssid, password); } CAYENNE_IN(V9) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(10, HIGH); } else { digitalWrite(10, LOW); } } CAYENNE_IN(V10) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(11, HIGH); } else { digitalWrite(11, LOW); } } void loop() { Cayenne.run(); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); //Calculate the distance (in cm) based on the speed of sound. distance = duration/58.2; delay(1000); } CAYENNE_OUT(V7) { Cayenne.virtualWrite(V7, distance); }