Arduino IoT - simplest way to let LED or lamp STAY on instead of blinking on/off

  • Thread starter Deleted member 750607
  • Start date

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
yeah there's still an error..am I supposed to write something next to IF ?
I copy and pasted this exact bit you sent me, minus the capitalization, etc:

Code:
void onLedSwitchChange () {
if {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
}
 

Ya’akov

Joined Jan 27, 2019
9,101
yeah there's still an error..am I supposed to write something next to IF ?
I copy and pasted this exact bit you sent me, minus the capitalization, etc:

Code:
void onLedSwitchChange () {
if {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
}
Well that's broken, where is the argument for if? if (something) {
In any case, what is IEDSwitch that appears in the errors you sent earlier?
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
Code:
void onLedSwitchChange ()
{
if (LEDpin == LOW);
{  // executes if true
digitalWrite (LEDpin, HIGH);
}
if (LEDpin == HIGH);
{           //executes if false
digitalWrite (LEDpin, LOW);
}
}

how's this?
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
Well that's broken, where is the argument for if? if (something) {
In any case, what is IEDSwitch that appears in the errors you sent earlier?
This is the line that's giving me trouble

if (LEDpin == LOW)

this is the line that shows an error
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
im honestly very confused
this is what I have

Code:
/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 4"
  https://create.arduino.cc/cloud/things/4f735077-bf74-4536-a54f-2e28dca5b605

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudLight lEDSwitch;

  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"
int LEDpin = 6;

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);
  pinMode(LEDpin, OUTPUT);

  // 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
 
 
}

void onLedSwitchChange () {
if (LEDpin == LOW) {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
}
 

Ya’akov

Joined Jan 27, 2019
9,101
im honestly very confused
this is what I have

Code:
/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 4"
  https://create.arduino.cc/cloud/things/4f735077-bf74-4536-a54f-2e28dca5b605

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudLight lEDSwitch;

  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"
int LEDpin = 6;

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);
  pinMode(LEDpin, OUTPUT);

  // 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


}

void onLedSwitchChange () {
if (LEDpin == LOW) {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
}
And what is the output from that, what are the errors?

Nevermind, I looked over the code more carefully. There are two problems here:

1. CloudLight lEDSwitch; Note the capitalization. LEDSwitch, not lEDSwitch.
2. LEDSwitch is your variable, why are you using LEDpin? Change the code to:

Code:
void onLedSwitchChange () {
if (LEDSwitch) {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
Since we are only testing for truth, as long as
Code:
LEDSwitch
evaluates true the first block in the if statement will execute, if it not, the second will.

I tried to use the sketch editor at Arduino to test things but I would have to have an IoT device to go past creating the variable, it won't generate a sketch for me, and all my Arduinos are just ordinary models.

Here's what I understand. You correctly described the process. You create the Thing and a variable associated with it. That variable is connected to a widget in the dashboard and the widget changes the value of the variable according to the type you selected.

The generated sketch includes and event handler, in this case
Code:
onLEDSwitchChange()
. That event handler is fired when you change the state of the switch in the dashboard and the variable value is available to the code in the handler.

In your case, that variable is
Code:
LEDSwitch
, but you mistyped it, and it is case sensitive, and you didn't use it in your code on the second attempt, you used
Code:
LEDPin
.

Try the revision I provided and tell me what it does, if there are errors, include them so I can see what is happening. I think you are very, very close to both making this work and figuring out how to use it. There are just too many moving parts for you to get them all at once, let's keep some of them still and work out how to make the others move the way you want. Never change two things at once when trying to debug it will just drive you nuts.
 
Last edited:

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
And what is the output from that, what are the errors?

Nevermind, I looked over the code more carefully. There are two problems here:

1. CloudLight lEDSwitch; Note the capitalization. LEDSwitch, not lEDSwitch.
2. LEDSwitch is your variable, why are you using LEDpin? Change the code to:

Code:
void onLedSwitchChange () {
if (LEDSwitch) {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
Since we are only testing for truth, as long as
Code:
LEDSwitch
evaluates true the first block in the if statement will execute, if it not, the second will.

I tried to use the sketch editor at Arduino to test things but I would have to have an IoT device to go past creating the variable, it won't generate a sketch for me, and all my Arduinos are just ordinary models.

Here's what I understand. You correctly described the process. You create the Thing and a variable associated with it. That variable is connected to a widget in the dashboard and the widget changes the value of the variable according to the type you selected.

The generated sketch includes and event handler, in this case
Code:
onLEDSwitchChange()
. That event handler is fired when you change the state of the switch in the dashboard and the variable value is available to the code in the handler.

In your case, that variable is
Code:
LEDSwitch
, but you mistyped it, and it is case sensitive, and you didn't use it in your code on the second attempt, you used
Code:
LEDPin
.

Try the revision I provided and tell me what it does, if there are errors, include them so I can see what is happening. I think you are very, very close to both making this work and figuring out how to use it. There are just too many moving parts for you to get them all at once, let's keep some of them still and work out how to make the others move the way you want. Never change two things at once when trying to debug it will just drive you nuts.

ok here is the code I am trying now...

Code:
/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 4"
  https://create.arduino.cc/cloud/things/4f735077-bf74-4536-a54f-2e28dca5b605

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudLight LEDSwitch;

  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"
const int LEDpin = 6;
int LEDSwitch;

void setup() {
   pinMode(LEDpin, OUTPUT);
  // 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();
}

void onLedSwitchChange () {
if (LEDSwitch == HIGH) {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
}
and this is the error message
"Error: Verifying working_copy_with_forum_apr06a"


Start verifying /tmp/299801666/build/sketch/working_copy_with_forum_apr06a.ino.cpp.o: In function `initProperties()': /tmp/299801666/build/sketch/thingProperties.h:21: undefined reference to `onLEDSwitchChange()' collect2: error: ld returned 1 exit status exit status 1 /tmp/299801666/build/sketch/working_copy_with_forum_apr06a.ino.cpp.o: In function `initProperties()': /tmp/299801666/build/sketch/thingProperties.h:21: undefined reference to `onLEDSwitchChange()' collect2: error: ld returned 1 exit status exit status 1
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
ok here is the code I am trying now...

Code:
/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 4"
  https://create.arduino.cc/cloud/things/4f735077-bf74-4536-a54f-2e28dca5b605

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudLight LEDSwitch;

  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"
const int LEDpin = 6;
int LEDSwitch;

void setup() {
   pinMode(LEDpin, OUTPUT);
  // 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();
}

void onLedSwitchChange () {
if (LEDSwitch == HIGH) {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
}
and this is the error message
"Error: Verifying working_copy_with_forum_apr06a"


Start verifying /tmp/299801666/build/sketch/working_copy_with_forum_apr06a.ino.cpp.o: In function `initProperties()': /tmp/299801666/build/sketch/thingProperties.h:21: undefined reference to `onLEDSwitchChange()' collect2: error: ld returned 1 exit status exit status 1 /tmp/299801666/build/sketch/working_copy_with_forum_apr06a.ino.cpp.o: In function `initProperties()': /tmp/299801666/build/sketch/thingProperties.h:21: undefined reference to `onLEDSwitchChange()' collect2: error: ld returned 1 exit status exit status 1
I also tried turning all the instances of "LEDSwitch" to "lEDSwitch"
 

Ya’akov

Joined Jan 27, 2019
9,101
OK, two things. The errors you are getting now say: undefined reference to `onLEDSwitchChange() which means there is something wrong with the sketch generation.

Second thing: what are you still using "if (LEDSwitch == HIGH) {"? See my code above, just "if (LEDSwitch) {".

I can't help you with the error being created by the sketch generator, I don't know what the source of that is. I would say start over clean with a new Thing and use the code I provided. Make sure the variable to associate with the switch is called "LEDSwitch".
 

djsfantasi

Joined Apr 11, 2010
9,160
I think the name in the code is lEDswitch. Note the lower case L (or l)

lEDswitch is NOT a variable. Hence the difficulties you’re having. It is an IoT “object” defined by CloudLight. As an object, it has methods and values associated with it.

You’ll need one of these to successfully modify the sketch. You’ll have to read carefully the IoT documentation to find the definition of CloudSwitch.

There might be (might, because I didn’t read the documentation), a value of switchStatus or method switchStatus(), that returns the status of a switch from the dashboard. You need the reference it like:
<IoTobjectname>.value
or
<IoTobjectname>.method

Again, for example only, instead of referring to the variable in the samples Yaakov gave you, you’d need to replace LEDswitch with this:

If(LEDswitch.switchStatus == LOW)...

You have some research and reading to do regarding IoT library object definitions for the CloudSwitch object.
 

Ya’akov

Joined Jan 27, 2019
9,101
I think the name in the code is lEDswitch. Note the lower case L (or l)

lEDswitch is NOT a variable. Hence the difficulties you’re having. It is an IoT “object” defined by CloudLight. As an object, it has methods and values associated with it.

You’ll need one of these to successfully modify the sketch. You’ll have to read carefully the IoT documentation to find the definition of CloudSwitch.

There might be (might, because I didn’t read the documentation), a value of switchStatus or method switchStatus(), that returns the status of a switch from the dashboard. You need the reference it like:
<IoTobjectname>.value
or
<IoTobjectname>.method

Again, for example only, instead of referring to the variable in the samples Yaakov gave you, you’d need to replace LEDswitch with this:

If(LEDswitch.switchStatus == LOW)...

You have some research and reading to do regarding IoT library object definitions for the CloudSwitch object.
This is the Arduino Cloud stuff, @djsfantasi. The sketch framework is generated by an IDE and the variables are associated with a "widget" in the "dashboard" magically.
 

djsfantasi

Joined Apr 11, 2010
9,160
This is the Arduino Cloud stuff, @djsfantasi. The sketch framework is generated by an IDE and the variables are associated with a "widget" in the "dashboard" magically.
Ok, I believe you.

But why would they use the syntax for objects? That’s got to be against some standard somewhere?

To me, it like saying

int myLIGHTstate​

is a float when used to control incandescent lamps. Otherwise it’s an int.
 

Ya’akov

Joined Jan 27, 2019
9,101
Ok, I believe you.

But why would they use the syntax for objects? That’s got to be against some standard somewhere?

To me, it like saying

int myLIGHTstate​

is a float when used to control incandescent lamps. Otherwise it’s an int.
The widget is an on/off switch, two states. True for on, false for off.

You make a "Thing" in the web IDE, created dashboard widgets, create variables, then associate the two. Then, the IDE generates a sketch framework. In it, there are on<Widget>Change() functions and in that scope your associated variable is available.

So, LEDSwitch is a variable associated with a switch widget, the onLEDSwitchChange() function is generated magically. So, if (LEDSwitch) {}; executes when the switch is on.

(I did as much research as I could without buying an IoT enabled Arduino or signing up for an "upgraded" plan which would allow ESP32s)
 

djsfantasi

Joined Apr 11, 2010
9,160
The widget is an on/off switch, two states. True for on, false for off.

You make a "Thing" in the web IDE, created dashboard widgets, create variables, then associate the two. Then, the IDE generates a sketch framework. In it, there are on<Widget>Change() functions and in that scope your associated variable is available.

So, LEDSwitch is a variable associated with a switch widget, the onLEDSwitchChange() function is generated magically. So, if (LEDSwitch) {}; executes when the switch is on.

(I did as much research as I could without buying an IoT enabled Arduino or signing up for an "upgraded" plan which would allow ESP32s)
I understand what you’re saying. And I totally believe you.

But regardless of IoT, why would you redefine syntax to have two meanings?
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
And what is the output from that, what are the errors?

Nevermind, I looked over the code more carefully. There are two problems here:

1. CloudLight lEDSwitch; Note the capitalization. LEDSwitch, not lEDSwitch.
2. LEDSwitch is your variable, why are you using LEDpin? Change the code to:

Code:
void onLedSwitchChange () {
if (LEDSwitch) {  // executes if true
digitalWrite (LEDpin, HIGH);
} else {           //executes if false
digitalWrite (LEDpin, LOW);
}
Since we are only testing for truth, as long as
Code:
LEDSwitch
evaluates true the first block in the if statement will execute, if it not, the second will.

I tried to use the sketch editor at Arduino to test things but I would have to have an IoT device to go past creating the variable, it won't generate a sketch for me, and all my Arduinos are just ordinary models.

Here's what I understand. You correctly described the process. You create the Thing and a variable associated with it. That variable is connected to a widget in the dashboard and the widget changes the value of the variable according to the type you selected.

The generated sketch includes and event handler, in this case
Code:
onLEDSwitchChange()
. That event handler is fired when you change the state of the switch in the dashboard and the variable value is available to the code in the handler.

In your case, that variable is
Code:
LEDSwitch
, but you mistyped it, and it is case sensitive, and you didn't use it in your code on the second attempt, you used
Code:
LEDPin
.

Try the revision I provided and tell me what it does, if there are errors, include them so I can see what is happening. I think you are very, very close to both making this work and figuring out how to use it. There are just too many moving parts for you to get them all at once, let's keep some of them still and work out how to make the others move the way you want. Never change two things at once when trying to debug it will just drive you nuts.
I got it to work!
In case you're curious what was changed (LOL)...I didn't realize that I had to write "digitalRead" before LEDpin next to the "if" part

Thanks again, you've been so helpful, wish I could repay you!
 

Ya’akov

Joined Jan 27, 2019
9,101
I got it to work!
In case you're curious what was changed (LOL)...I didn't realize that I had to write "digitalRead" before LEDpin next to the "if" part

Thanks again, you've been so helpful, wish I could repay you!
Great! Things should get easier now. I hope you do some really cool things.

The best way to repay me is to hang out here and help other people if you can. Or, you can do it somewhere else, but in any case, if you know a little more than someone else, teach them that.

Congratulations, you've got a start on building some cool stuff.
 
Top