17. LED Brightness Control Using Potentiometer

Back To All Submissions
Previous Submission
Next Submission

Solving Approach:

How do you plan to solve it?

 

 

Code

/*Paste your code here*/

int ledPin = 9; 
int ptMeter =A0; 
int ptVal;
long ledVal;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  ptVal = analogRead(ptMeter); 
  ledVal = 0.2490 * ptVal; //convert potentionmeter range of 0-1024 to led 0-255.
  						   //ptVal*255/1024 = ledVal
  						   //0.2485 is roughly 255/1024 	
  Serial.println(ledVal);
  analogWrite(ledPin, ledVal);
  
  
}

 

Output

Video

Add video of output (know more)

 

 

 

 

 

Photo of Output

Add a photo of your hardware showing the output.

 

 

 

 

Was this helpful?
Upvote
Downvote