Potentiometer or variable resistor control LED Code using Arduino

Potentiometer or variable resistor control LED Code (1)

The if() statement is the most basic of all programming control structures. It allows you to make something happen or not depending on whether a given condition is true or not. It looks like this:Potentiometer or variable resistor control LED Code (1)

if (someCondition) {
// do stuff if the condition is true
}

There is a common variation called if-else that looks like this:

if (someCondition) {
// do stuff if the condition is true
} else {
// do stuff if the condition is false
}

There’s also the else-if, where you can check a second condition if the first is false:

if (someCondition) {
// do stuff if the condition is true
} else if (anotherCondition) {
// do stuff only if the first condition is false
// and the second condition is true
}

You’ll use if statements all the time. The example below turns on an LED on pin 13 (the built-in LED on many Arduino boards) if the value read on an analog input goes above a certain threshold.

Circuit

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic:

Potentiometer or variable resistor control LED Code schematic (1)

 

Read more: Potentiometer or variable resistor control LED Code

Leave a Comment

Your email address will not be published. Required fields are marked *