Description
I used 3 potentiometers to light three LED lights. Each potentiometer controls the brightness of one LED light.
Components
- 1 Arduino
- 3 LEDs
- 3 Resistors (220Ω)
- 3 Potentiometers
- 1 Breadboard
Code
// select the input pin for the potentiometer
int sensorPinRed = A0;
int sensorPinGreen = A1;
int sensorPinBlue = A2;
// select the pin for the LEDs
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
// variable to store the value coming from the sensor
int sensorValueRed = 0;
int sensorValueGreen = 0;
int sensorValueBlue = 0;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValueRed = analogRead(sensorPinRed);
sensorValueGreen = analogRead(sensorPinGreen);
sensorValueBlue = analogRead(sensorPinBlue);
// turn the Pins on
analogWrite(redPin, sensorValueRed/4);
analogWrite(greenPin, sensorValueGreen/4);
analogWrite(bluePin, sensorValueBlue/4);
// stop the program for 10 milliseconds:
delay(10);
}
