Introduction: Project 2, Dimming LED

About: My name is William. I love to create with Arduino ad discover what can be done with it. I also like messing around with computers.

In this project you are going to learn how to control the brightness of an LED with a potentiometer. In this project you will be taught about analogWrite, analogRead, and using an int function. Hope you enjoy it, and remember to check out the previous project titled, Project 1, Blinking LED.

Hardware required:

  • Arduino UNO
  • Solderless Breadboard
  • Rotary Potentiometer
  • 6 jumper wires
  • LED
  • 220 ohm resistor

Software required:

  • Arduino IDE

Step 1: Hardware

Build the circuit just as the above picture.

Step 2: Code

Now copy the code below into the Arduino IDE, if you don't have it there is a link at the bottom of the page.

int Sensorvalue = 0; //Specifies that Sensorvalue equals 0;

void setup(){

pinMode(8, OUTPUT);


void loop(){

Sensorvalue = analogRead(A0); //Sensorvalue = pin A0, which is connected to the potentionmeter

analogWrite(8, Sensorvalue/4); //using the analogWrite function we can control pin 9 more quickly


Step 3: Verify and Upload

Verify and upload your code to your Arduino Code. For more info on this check out my previous project you can find the link below. Once your code is uploaded you will be able to control the brightness of the LED by turning the potentiometer. Now get creative. you could try to control the speed of a dc motor using one.

More projects will be coming out, stay tuned and learn how to make distance readers, audio visualizers, memory games, an alarm clock and more.

Arduino IDE download:

My previous project: