Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
jehankandt
Published © Apache-2.0

Arduino LED with Variable Resister

Arduino LED with Variable Resister

IntermediateFull instructions provided1,395
Arduino LED with Variable Resister

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
5 mm LED: Red
5 mm LED: Red
×4
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Resistor 220 ohm
Resistor 220 ohm
×4

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino LED with Variable Resister

Arduino LED with Variable Resister

Code

Arduino LED with Variable Resister

C/C++
Arduino LED with Variable Resister
int adv; 
int ledpin1 = 3; //led 1
int ledpin2 = 5; //led 2
int ledpin3 = 6; //led 3
int ledpin4 = 9; //led 4

void setup() {
  pinMode(ledpin1,OUTPUT);
  pinMode(ledpin2,OUTPUT);
  pinMode(ledpin3,OUTPUT);
  pinMode(ledpin4,OUTPUT);
  
}

void loop() {
  adv = analogRead(A0);

// Now You have to map value of Potentiometer
  analogWrite(ledpin1, map(adv, 0, 1023, 0, 255));
  analogWrite(ledpin2, map(adv, 0, 1023, 0, 255));
  analogWrite(ledpin3, map(adv, 0, 1023, 0, 255));
  analogWrite(ledpin4, map(adv, 0, 1023, 0, 255));
 
}

Credits

jehankandt
21 projects • 8 followers

Comments