Hi,
I have been reading a lot and trying out but it seems I do not get a simple Led to turn on when a relay is ON. Basically I have the code to operate relay1 and relay2 in a sequence so by pressing a button relay1 is ON and upon set time it goes OFF and relay 2 goes ON.
What I would like is to have LED1 and LED2 in the dashboard so I can see which relays is actually ON.
the relays work as set it is just I do not get the LEDs implemented.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/c69200b7-9d1f-4419-83b2-a3a5a7964d8a
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
bool button;
bool relay1;
bool relay2;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#define relay1 1
#define relay2 2
String relay1State;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since Button is READ_WRITE variable, onButtonChange() is
executed every time a new value is received from IoT Cloud.
*/
unsigned long startTime = millis();
unsigned long lastButtonPress = 0;
void onButtonChange() {
if(millis() - lastButtonPress > 20000) {
lastButtonPress = millis();
digitalWrite(relay1, HIGH); // turn on relay1
Serial.println("relay1 is ON");
startTime = millis();
while(millis()-startTime<5000){}
digitalWrite(relay1, LOW); // turn off relay1
startTime = millis();
while(millis()-startTime<1000){}
digitalWrite(relay2, HIGH); // turn on relay2
startTime = millis();
while(millis()-startTime<10000){}
digitalWrite(relay2, LOW); // turn off relay2
}
}
/*
Since Relay1 is READ_WRITE variable, onRelay1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay1Change() {
// Add your code here
}
/*
Since Relay2 is READ_WRITE variable, onRelay2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay2Change() {
// Add your code here to act upon Relay2 change
}
/*
Since Relay1Status is READ_WRITE variable, onRelay1StatusChange() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay1StatusChange() {
// Add your code here to act upon Relay1Status change
}
/*
Since Relay2Status is READ_WRITE variable, onRelay2StatusChange() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay2StatusChange() {
// Add your code here to act upon Relay2Status change
}