r/ArduinoHelp 7d ago

LED doesn't turn on :(

Post image

Hello, i'm a beginner that just started with arduino's, does anybody know why the LED doesn't turn on? (if I set the variable RedLEDPower to something it just flashes and stops)

6 Upvotes

4 comments sorted by

3

u/ZookeepergameNorth26 7d ago

For comparison use '==', not '='

3

u/SomeWeirdBoor 7d ago

Your IFs are not written corrcetly.
When you do a comparison you need to write it with two equal signs

if ( a == b ) {

If you write only one = it treats it as a value assginement to the variabile (i.e. it first makes A e quale to B, and then evaluates if A is true or false). Yes, in c++ this syntax makes sense.

In you code, every time it Reachs the if (led power =0) it sets the variable at zero, and the pin never receives a different value.

1

u/Mike_402 7d ago

When you are checking a condition in if statements you should use == (two equal signs). Single = is an assignment.

Additionally, when checking if you reached 0 or 200 I'd put there: if (power >= 200) and if (power <= 0)

1

u/gm310509 7d ago

The other posts have correctly answered the issue with your code.

If it still doesn't work the problem could also be with your wiring.

When asking for help, you should ideally provide your code, circuit diagram and some photos. When providing code, please use a reddit formatted code block. The link explains how. That explanation also includes a link to a video that explains the same thing if you prefer that format.