top of page

Pot Controlled LED Brightness Code
int potPin = 0; //this is the analog pin that will read the varying signal coming from the potentiometer
int ledPin = 8; // this is the pin that will send signal
int analogInputValue = 0; // this is the number being read from the potentiometer (0-1023)
void setup() {
pinMode(ledPin, OUTPUT); // sets pin 8 as your output
Serial.begin(9600);
}
void loop() {
analogInputValue = analogRead(potPin); // reads the value coming from the potentiometer
int brightness = map(analogInputValue, 0, 1023, 0, 255); //variable that maps the light values to 0-255 range
analogWrite(ledPin, brightness); //Sends the “mapped” signal to the ledPin based on the analog value from the pot
}
bottom of page