LED Dimmer With Potentiometer

1,564

8

9

Published

Introduction: LED Dimmer With Potentiometer

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

Step 1: Materials

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

Step 2: Getting Started

Plug Arduino into computer with USB cable.

Step 3: 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

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 = 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;

void setup() {

pinMode(9, OUTPUT);

pinMode(potPin, INPUT);}

void loop() {

Recommendations

• 3D CAM and CNC Class

606 Enrolled

• Casting Contest

We have a be nice policy.

Questions

GArbagw

cool way to combine more than one skill. i can use this in class

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

Simple, we have to start somewhere