# Project: LED Dimmer Control

## Objectives and Overview

Previously, you’ve programmed the LED fades into your code. For this challenge, you’re going to be using a potentiometer to control the fades.

This is much like the project you did for the potentiometer lesson, but this time there are added challenges!

## Creating an LED Dimmer Control

These challenges build on the basic activity that you did in the potentiometer guide where you faded an LED by turning the potentiometer. Each challenge is designed to expand a skill that you covered in that project!

The main concept is that you’re mapping the input sent by the potentiometer to an output of the LED.

This basic concept can be extended and used with other components as well!

### Supplies

The supplies are the same as for the basic potentiometer activity. Here’s a reminder:

• Jumper wires
• Potentiometer
• 10k Ohm resistor for the potentiometer
• LED circuit supplies:
• LED and 220 (or 560) Ohm resistor

Remember, since these challenges use more than 1 LED, you’ll need a resistor for each LED!

### Steps

This challenge builds on the example project that you did in the potentiometer guide. If you need a refresher on any concepts in this experiment, head back to that guide!

### Circuit

This is the diagram and steps for the basic activity. For the Experimenter Challenges, you’ll need to build on this basic circuit to solve the problem!

1. Connect the 5V (Power) on the Arduino to the + rail of the breadboard.
2. Connect the GND on the Arduino to the – rail of the breadboard.
3. Wire up the LED circuit that you’ve previously done. If you need help, look back to one of the previous projects.
4. Attach the potentiometer to the breadboard. Place it so that the pins are closest (on the left side) to the Arduino. The edge of the potentiometer can hang over into the middle of the breadboard where the rails split.
5. Use 1 jumper wire to connect the power rail of the breadboard to the V+ (top pin) on the potentiometer.
6. Use 1 jumper wire to connect the output (middle pin) of the potentiometer to the A0 analog input on the Arduino board. Make sure to use the A0 input and not a digital input.
7. Use 1 jumper wire to connect the GND (bottom pin) of the potentiometer.

### Sketch

The sketch for the Experimenter Challenge will build on the basic potentiometer sketch that you’ve previously used.

Here is a refresher:

```.hljs-comment,.hljs-quote{color:#999}.hljs-variable,.hljs-template-variable,.hljs-tag,.hljs-name,.hljs-selector-id,.hljs-selector-class,.hljs-regexp,.hljs-deletion{color:#f2777a}.hljs-number,.hljs-built_in,.hljs-builtin-name,.hljs-literal,.hljs-type,.hljs-params,.hljs-meta,.hljs-link{color:#f99157}.hljs-attribute{color:#fc6}.hljs-string,.hljs-symbol,.hljs-bullet,.hljs-addition{color:#9c9}.hljs-title,.hljs-section{color:#69c}.hljs-keyword,.hljs-selector-tag{color:#c9c}.hljs{display:block;overflow-x:auto;background:#2d2d2d;color:#ccc;padding:.5em}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:bold}.wp-block-code{border:0;padding:0}.wp-block-code>div{overflow:auto}.shcb-language{border:0;clip:rect(1px,1px,1px,1px);-webkit-clip-path:inset(50%);clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-wrap:normal;word-break:normal}.hljs{box-sizing:border-box}.hljs.shcb-code-table{display:table;width:100%}.hljs.shcb-code-table>.shcb-loc{color:inherit;display:table-row;width:100%}.hljs.shcb-code-table .shcb-loc>span{display:table-cell}.wp-block-code code.hljs:not(.shcb-wrap-lines) {white-space:pre}.wp-block-code code.hljs.shcb-wrap-lines{white-space:pre-wrap}.hljs.shcb-line-numbers{border-spacing:0;counter-reset:line}.hljs.shcb-line-numbers>.shcb-loc{counter-increment:line}.hljs.shcb-line-numbers .shcb-loc>span{padding-left:.75em}.hljs.shcb-line-numbers .shcb-loc::before{border-right:1px solid #ddd;content:counter(line);display:table-cell;padding:0 .75em;text-align:right;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;white-space:nowrap;width:1%}```int ledPin=9; //Variable to store pin of LED
int potentPin=A0; //Variable to store pin of potentiometer
int potentValue=0; //Variable to store last known value of potentiometer
int brightnessValue=0; //Variable to store LED brightness

void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT); //Setup LED pin for output
}

void loop() {
// put your main code here, to run repeatedly:
brightnessValue=map(potentValue,0,1023,0,255); //Map the potentiometer value to a brightness
analogWrite(ledPin,brightnessValue); //Set the brightness of the ledPin
}```Code language: JavaScript (javascript)```

Remember, any changes that you make to the board (such as adding more LEDs) will need to be included in the sketch as well.

## LED Dimmer Control: Experimenter Challenges

Now for the challenges!

In the base activity, your potentiometer controlled the brightness of a single LED. This challenge is going to be fairly open-ended: add more LEDs!

Here are some suggestions for what this could look like:

Multi Fades: Leave the mapping of the first LED similar to how you already have it, and then have another LED with a completely different mapping!

LED-o-meter: Use a row of LEDs that turn on as you dial the potentiometer. Think of the row of LEDs like a meter that lights up as you turn the knob. You could even build out a simple interface for this!

LED Dial: Using at least 3 unique LEDs, map each color to a range of potentiometer values. For example, if the value is low, the green LED can be on.

These are just some suggestions to get you started! You’re able to solve each of these challenges with the skills that you currently know- you’ll just need to combine several concepts!

## Moving Forward

The potentiometer is just one type of analog input. There are lots of things that can be done by combining the potentiometer with other components.

Start experimenting and see what you come up with!