I have tried to control the lumen sub sea light with the code you have provided but however have trouble doing so. I was able to make the light turn on it’s own however, I was wondering if there is a way to control light by flipping a switch running through an arduino.
The Lumen light is controlled by a PWM signal that can be generated with the Arduino Servo library. Can you please post the code you have tried as well as a picture of your wiring setup? That will help us figure this out quickly!
@elmho01,
Do you have a common ground between the power supply for the Lumen and the Arduino? The Arduino cannot control the light if there is no common ground.
Regards,
TCIII AVD
You have some syntax errors in your code, which will allow your code to compile and run without any warnings, but may not produce the results you expect.
if (buttonS = HIGH)
To make a logical comparison, use if (buttonS == HIGH). You should look up the difference.
else (buttonS = LOW);
Same thing here, and the semicolon following the else statement has some important implications, too. Note that you probably don’t want to be making a logical comparison here. I suggest you search the Internet for examples of ‘if-then-else’ statements in c or c++, you can even look for Arduino-specific examples.
I realize that but i’m still confused. I tried replacing it with 0 and 1 but it seems like the charge isn’t dischargng.So no matter whether it is on or off, it remains on.
And removing the semicolon next to the else causes an error.
The semicolon next to the else statement is invalid because if you want to specify a condition like else (buttonS == 0); {, then you need to use else if so that it becomes else if (buttonS == 0); {. The way you have it, the else statement code will never execute.
Putting the semicolon after the comparison is equivalent to putting an empty statement after the condition. If the condition is true, the next statement is executed. Putting multiple expressions inside of curly braces { } causes those expressions to be interpreted as a single statement.
Here is an example:
#include <stdio.h>
int main() {
int x = 1;
if (x > 0) {
printf("hello\n");
} else if (x < 0); {
printf("goodbye\n");
}
}
Outputs:
hello
goodbye
The above program is equivalent to:
#include <stdio.h>
int main() {
int x = 1;
if (x > 0) {
printf("hello\n");
} else if (x < 0) {
;
}
printf("goodbye\n");
}
What the program should be in order to get the output you would expect:
#include <stdio.h>
int main() {
int x = 1;
if (x > 0) {
printf("hello\n");
} else if (x < 0) { // <- NO SEMICOLON
printf("goodbye\n");
}
}