Mar 162014

I got myself a rotary potentiometer at and decided to come up with a basic article.

First, lets have a quick look at the below schematic to understand how a potentiometer works.



Now, lets plug it to our arduino and while we are it, lets use its retrieved value (thru analogread) to dim a led (thru analogwrite).



Now lets have a look at the arduino sketch


byte potPin=0; //Analog 0 connected to the potentiometer
byte LEDPin=6; //Connected to LED on Pin 6
float potValue=0; //Value returned from the potentiometer
float v=0; //voltage (0-5v)

void setup(){
  pinMode(LEDPin, OUTPUT); //Set Pin 6 as an Output
void loop(){
  potValue = analogRead(potPin)/4; //Read the potentiometer, convert it to 0 - 255
  v=potValue*5/255; //to calculate the voltage send out on pin6
  Serial.println(v, 2);
  analogWrite(LEDPin, potValue); //Write the converted potentiometer value to LED pin

here we go : rotate your potentiometer and see your led dim in and out

 Posted by at 16 h 53 min

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.