Introduction: LED Dimmer With Potentiometer

Picture of LED Dimmer With Potentiometer

This is an instructable that teaches you how to use a potentiometer to dim an LED.

Step 1: Materials

Picture of Materials

  1. Arduino
  2. Computer
  3. Breadboard
  4. LED
  5. 5 Male wires
  6. Potentiometer
  7. USB cable

Step 2: Getting Started

Picture of Getting Started

Plug Arduino into computer with USB cable.

Step 3: Wiring

Picture of Wiring

After the Arduino is plugged into the computer with the USB cord, we will take the first wire and put one end into ground and the other into j1. Then you will put the second wire from A0 to j3. Then You will put the third wire from 5v to j5.

After that you will put the fourth wire from D9 to j15. Then the fifth and last wire from ground to j17.

Step 4: Potentiometer and LED Setup

Picture of Potentiometer and LED Setup

Put the knob facing away from the wires. Plug it into f1 f3 and f5. Then take the LED put the longer leg into f15 and the shorter one in f17.

Step 5: The Code

These are the variables which tell the computer what specific words mean:

int potPin = A0; This tells the computer that the middle part of the potentiometer, which we are calling potPin, is plugged into A0
int readValue; This tells the computer that whenever we say readValue it means to read the potentiometer

This is the Void Setup which only happens once to set up for the rest of the code:

void setup() { This is just telling you that this is the beginning of the Void Setup

pinMode(9, OUTPUT); This is setting up the light so it can be turned on later

pinMode(potPin, INPUT); This sets up the potentiometer so we can use it later

The next part is the void loop which runs over and over again until you stop it.

void loop() {

readValue = analogRead(potPin); This tells the computer to read the potentiometer whenever we say readValue.

readValue = map(readValue,0,1023,0,255); This converts the numbers from the potentiometer which is from 0-1023, to the numbers for the LED which is from 0-255.

analogWrite(9,readValue); This tells the computer to light up the LED at the brightness the potentiometer is telling it to.

}

This is the whole code by itself:

int potPin = A0;
int readValue = 0;

void setup() {

pinMode(9, OUTPUT);

pinMode(potPin, INPUT);}

void loop() {

readValue = analogRead(potPin);

readValue = map(readValue,0,1023,0,255);

analogWrite(9, readValue);}

Comments

Caoliner (author)2017-12-07

I heard google is about to buy u guys out

Caoliner (author)2017-12-07

Incredible project. It consists of all the correct lines of code, and it is a work of art. Their teacher shouldn't even give them 100 he/she should give them a approximately 217.34

NoskillsrequiredN (author)2017-12-06

Simple, we have to start somewhere

Thanks for the support!!!!

orangoton boiger

crazypj (author)2017-12-05

Is the computer or Arduino running pot and LED? Seems a complicated way tp dim LED, BUT, the explanations of what and why are great

cagoldstein (author)crazypj2017-12-06

The computer is sending the code to the Arduino witch then controls the potentiometer and LED

Swansong (author)2017-12-05

Great first instructable! Thanks for sharing :)

About This Instructable

555views

8favorites

More by cagoldstein:LED Dimmer With Potentiometer
Add instructable to: