/* Cayenne Ethernet Example This sketch connects to the Cayenne server using an Arduino Ethernet Shield W5100 and runs the main communication loop. The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager. Steps: 1. Set the token variable to match the Arduino token from the Dashboard. 2. Compile and upload this sketch. For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data should be sent to those pins using virtualWrites. Examples for sending and receiving Virtual Pin data are under the Basics folder. */ //#define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include #include #include char token[] = ""; int Trigger = 5; int Echo = 6; int Trigger1 = 22; int Echo1 = 24; int Trigger2 = 26; int Echo2 = 28; int Light = 2; #include Servo myservo; Servo myservo1; void setup() { myservo.attach(3); myservo1.attach(7); myservo.write(0); myservo1.write(90); pinMode(Light, OUTPUT); pinMode(Trigger, OUTPUT); pinMode(Echo, INPUT); pinMode(Trigger1, OUTPUT); pinMode(Echo1, INPUT); pinMode(Trigger2, OUTPUT); pinMode(Echo2, INPUT); Serial.begin(9600); Cayenne.begin(token); mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module delay(1); //wait 1ms for mp3 module to set volume mp3_set_volume (30); } void loop() { Cayenne.run(); } CAYENNE_IN(V1) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 1) { Serial.println("hi"); mp3_play (1); delay (6000); } else { mp3_stop(); } } CAYENNE_IN(V2) { // get value sent from dashboard int currentValue2 = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue2 == 1) { Serial.println("hi 2"); mp3_play (2); delay (6000); } else { mp3_stop(); } } CAYENNE_IN(V3) { // get value sent from dashboard int currentValue3 = getValue.asInt(); // 0 to 1 if (currentValue3 == 1) { Serial.println("hi 3"); mp3_play (3); delay (6000); } else { mp3_stop(); } } CAYENNE_OUT(V5) { long duration, distance; digitalWrite(Trigger, LOW); delayMicroseconds(2); digitalWrite(Trigger, HIGH); delayMicroseconds(10); digitalWrite(Trigger, LOW); duration = pulseIn(Echo, HIGH); distance = (duration / 2) / 29.1; Serial.print(distance); Serial.println("Centimeter:"); delay(500); Cayenne.virtualWrite(V5, distance); if ((distance > 10) && (distance < 100)) { myservo1.write(90); mp3_play(7); delay(3000); } } CAYENNE_IN(V4) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); } else { digitalWrite(Light, LOW); delay(100); } } CAYENNE_IN(V6) { // get value sent from dashboard int currentValue6 = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue6 == 1) { mp3_play (4); myservo.write(90); delay (6000); myservo.write(0); } else { mp3_play(8); myservo.write(90); delay (6000); myservo.write(0); } } CAYENNE_IN(V7) { // get value sent from dashboard int currentValue7 = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue7 == 1) { mp3_play (5); myservo.write(90); delay (6000); myservo.write(0); } else { mp3_play(9); myservo.write(90); delay (6000); myservo.write(0); } } CAYENNE_IN(V8) { // get value sent from dashboard int currentValue8 = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue8 == 1) { mp3_play (6); myservo.write(90); delay (6000); myservo.write(0); } else { mp3_play(10); myservo.write(90); delay (6000); myservo.write(0); } } CAYENNE_OUT(V9) { long duration1, distance1; digitalWrite(Trigger1, LOW); delayMicroseconds(2); digitalWrite(Trigger1, HIGH); delayMicroseconds(10); digitalWrite(Trigger1, LOW); duration1 = pulseIn(Echo1, HIGH); distance1 = (duration1 / 2) / 29.1; delay(500); Cayenne.virtualWrite(V9, distance1); if ((distance1 > 10) && (distance1 < 100)) { myservo1.write(45); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); } } CAYENNE_OUT(V10) { long duration2, distance2; digitalWrite(Trigger2, LOW); delayMicroseconds(2); digitalWrite(Trigger2, HIGH); delayMicroseconds(10); digitalWrite(Trigger2, LOW); duration2 = pulseIn(Echo2, HIGH); distance2 = (duration2 / 2) / 29.1; delay(500); Cayenne.virtualWrite(V10, distance2); if ((distance2 > 10) && (distance2 < 100)) { myservo1.write(135); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); digitalWrite(Light, LOW); delay(1000); digitalWrite(Light, HIGH); delay(1000); } }