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!
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!
The supplies are the same as for the basic potentiometer activity. Here’s a reminder:
Remember, since these challenges use more than 1 LED, you’ll need a resistor for each LED!
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!
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!
Use this breadboard diagram as your guide:
The sketch for the Experimenter Challenge will build on the basic potentiometer sketch that you’ve previously used.
Here is a refresher:
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:
potentValue=analogRead(potentPin); //Read the value of the potentiometer pin
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.
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!
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!