# Decision making

## Programming theory

In programming, an if statement is a construct that causes the program to act differently depending upon some condition. We already saw this in Lesson 3:

if (counter == 15) {
Serial.println("Resetting ...");
counter = 0;
}

Here, the code inside curly braces is only run if counter is equal to 15.

Common comparisons are:

Operator Meaning Example
== Equal to if (x == 7) { }
< Less than if (x < 7) { }
<= Less than or equal to if (x <= 7) { }
> Greater than if (x > 7) { }
>= Greater than or equal to if (x >= 7) { }

## Wiring

Use the same circuit as the previous lesson.

## Exercise

Develop a “night light” that will turn on the LED when the light sensor reads a low value. You can simulate “night” by covering the sensor with your finger to block the light. You will need to use your previous program to determine typical values that correspond to “dark” vs “light”.

Hint: You might find it helpful to look at pages 19 – 20 of the Arduino Notebook.

Don’t forget to save your code into a new file so that you don’t overwrite your previous work.