Description:
Took my existing LED circuit and added in a potentiometer in order to control the blinking speed. To prep the potentiometer, I soldered a ground, 5v and analog wire to it. Then I connected the analog wire to the analog output on the Arduino board and the 5v wire to the power source on the board. The ground wire was connected to an appropriate ground area as well. Once done, I uploaded new code to take advantage of the pot and the blinking became controllable by twisting the pot to higher/lower settings.
Then, I added an additional pot using a different analog input and similar setup to above. With updated code, I became able to control both the speed and the strength of the LED.
Items used for circuit:
- (1) Breadboard
- (3) 220 resistor
- (3) short connector wires
- (8) long wires
- (1) Arduino uno board
- (1) Red LED
- (1) Blue LED
- (1) Green LED
- (2) Potentiometers
- (3) Wires for each "Pot" (ground, 5v, analog)
Code used to control 2 Pot LED:
/*
* one pot dims, the other pot changes the blinking rate
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = 2; // select the input pin for the potentiometer 1
int pot2Pin = 4; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int led1Pin = 9; // select the pin for the LED 1
int led2Pin = 11; // select the pin for the LED 2
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking
analogWrite(led2Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(led2Pin, 0); // dim LED to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
}
- Login to post comments