#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "67f07213-384c-442a-854a-44ca22bc0f8f";
const char SSID[] = "Wokwi-GUEST"; // Network SSID (name)
const char PASS[] = ""; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = "E2iFP@?ngCFQhb5ySftYRAPmr"; // Secret device password
void onFanChange();
void onForwardChange();
void onLed1Change();
void onLed2Change();
void onBackwardChange();
CloudSwitch fan;
CloudSwitch forward;
CloudSwitch led1;
CloudSwitch led2;
CloudSwitch backward;
int relay1=23;
int realay2=21;
int relay3=19;
int relay4=18;
int relay5=17;
void initProperties(){
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(fan, READWRITE, ON_CHANGE, onFanChange);
ArduinoCloud.addProperty(forward, READWRITE, ON_CHANGE, onForwardChange);
ArduinoCloud.addProperty(led1, READWRITE, ON_CHANGE, onLed1Change);
ArduinoCloud.addProperty(led2, READWRITE, ON_CHANGE, onLed2Change);
ArduinoCloud.addProperty(backward, READWRITE, ON_CHANGE, onBackwardChange);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(35, INPUT_PULLUP);
pinMode(34, INPUT_PULLUP);
pinMode(23, OUTPUT);
pinMode(21, OUTPUT);
pinMode(19, OUTPUT);
pinMode(18, OUTPUT);
pinMode(17, OUTPUT);
}
void loop() {
ArduinoCloud.update();
if (!digitalRead(34)) relay4 = true;
else
relay4 = false;
if (!digitalRead(35)) relay5 = true;
else
relay5 = false;
}
void onForwardChange() {
// Add your code here to act upon Forward change
if (forward) digitalWrite(23, HIGH);
else digitalWrite(23, LOW);
}
/*
Since Reverse is READ_WRITE variable, onReverseChange() is
executed every time a new value is received from IoT Cloud.
*/
/*
Since Led1 is READ_WRITE variable, onLed1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLed1Change() {
// Add your code here to act upon Led1 change
if (led1) digitalWrite(21, HIGH);
else digitalWrite(21, LOW);
}
/*
Since Led2 is READ_WRITE variable, onLed2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLed2Change() {
// Add your code here to act upon Led2 change
if (led2) digitalWrite(19, HIGH);
else digitalWrite(19, LOW);
}
/*
Since Fan is READ_WRITE variable, onFanChange() is
executed every time a new value is received from IoT Cloud.
*/
void onFanChange() {
// Add your code here to act upon Fan change
if (fan) digitalWrite(18, HIGH);
else digitalWrite(18, LOW);
}
void onBackwardChange() {
// Add your code here to act upon Fan change
if (backward) digitalWrite(17, HIGH);
else digitalWrite(17, LOW);
}