Home        Store        Docs        Blog

Lumen Light Control


(Ahmed) #1

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.

Thank You In Adavnce


(Rusty) #2

Hi Ahmed,

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!

Rusty


(TCIII) #3

@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


(Ahmed) #4

Thank you that did help, but now it remains on constantly.


(Ahmed) #5

Lumen Positive —> 12V Battery +
Lumen Negative ----> 12V Ground
Lumen Data —> PWM 9
Switch Positive —> 5V Arduino
Switch Data —> PWM 7

I can’t upload my code any suggestions


(Jacob) #6

You can use this website to get a link to pasted code http://pastebin.com/


(Ahmed) #7

http://pastebin.com/nx64n3BU


(Jacob) #8

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.

-Jacob


(Ahmed) #9

So should they be replaced with values like 0 or 1?


(Rusty) #10

Hi @elmho01,

Comparison statements must use the == symbol. So:

if (buttonS == HIGH)

(Jacob) #11

You should revise the decision portion of your loop() code to look something like this:

if (buttonS == HIGH) {
    do something;
} else {
    do something else;
}

(Ahmed) #12

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.

http://pastebin.com/TLJYnRdh

And removing the semicolon next to the else causes an error.


(Rusty) #13

Ahmed,

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.

-Rusty


(Jacob) #14

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");
        }
}

(Ahmed) #15

That makes sense let me try that.
Because else means otherwise, but you can’t give else an assignment line


(Ahmed) #16

Thank you guys so much for your help, with a little modification it is finally working.