Asher Thomas Babu
Published © CC0

ControlledFade using Potentiometer

Control the brightness of an LED using analogWrite

BeginnerProtip4
ControlledFade using Potentiometer

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
5 mm LED: Red
5 mm LED: Red
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Story

Read more

Schematics

Schematic

Code

Code

C/C++
/* Analog Read to LED
 * ------------------ 
 *
 * controls a brightness of a light emitting diode(LED) connected to digital  
 * pin 13. The brightness depends on the value obtained by analogRead().
 * In the easiest case we connect
 * a potentiometer to analog pin 2.
 *
 * Created 30 March 2019
 * by AsherThomasBabu
 * 
 *
 */

int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the value coming from the sensor

void setup() {
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
}

void loop() {
  val = analogRead(potPin);    // read the value from the sensor
  analogWrite(ledPin, val);    // sets the LED brigthness to the value read from 
}
 

Credits

Asher Thomas Babu

Asher Thomas Babu

0 projects • 0 followers

Comments