Pulse Width Modulation Using a Potentiometer

Pulse Width Modulation Using a Potentiometer © GPL3+

In this project, I am going to demonstrate how to use a potentiometer to dim LEDs.

  • 11,953 views
  • 0 comments
  • 2 respects

Components and supplies

Apps and online services

About this project

Mode of Operation

A potentiometer, or "pot" for short, is a variable resistor. It's the same type of control you'd use to change volume or dim a lamp. A potentiometer changes resistance as it is turned. By using it as a "voltage divider", the Arduino can sense the position of the knob, and use that value to control anything you wish.

In this example we are going to fade 3 LEDs depending upon the position of the knob of a potentiometer.

Configuring idIoTware Shield

Once we upload the code to Arduino, we can rotate the potentiometer to fade the LEDs accordingly. No more connecting LEDs to breadboards and messy wiring. With the idIoTware shield the sky's the limit.

Code

pwm_potArduino
int ledPin1 = 3;    // LED connected to digital pin 3
int ledPin2 = 6;    // LED connected to digital pin 6
int ledPin3 = 9;    // LED connected to digital pin 9
int potentiometerPin = A2; 


void setup()  
    { 
     // nothing happens in setup 
    } 
 
void loop() 
    { 
      int potValue = potentiometerValue();
      int fadeValue = map(potValue, 0, 1023, 0, 255);   // sets the value (range from 0 to 255):
      
      analogWrite(ledPin1, fadeValue);
      analogWrite(ledPin2, fadeValue);
      analogWrite(ledPin3, fadeValue);        
      // wait for 30 milliseconds to see the dimming effect    
      delay(30);                            
    }

    
//function to calculate potentiometer value
int potentiometerValue()
   {
    int val = analogRead(potentiometerPin);
    return val;
   }    

Schematics

idiotware-shield

Comments

Similar projects you might like

Exploring Pulse Width Modulation

by 3 developers

  • 803 views
  • 0 comments
  • 4 respects

SD Card Temperature Data Logger

Project tutorial by 3 developers

  • 7,902 views
  • 0 comments
  • 6 respects

LED Ring Real Time Clock

Project showcase by 3 developers

  • 1,378 views
  • 0 comments
  • 1 respect

Location Display With Idiotware Shield

Project tutorial by 3 developers

  • 1,268 views
  • 0 comments
  • 3 respects

Light Sensitive Theremin

Project tutorial by 3 developers

  • 2,249 views
  • 0 comments
  • 3 respects

LED Ring Patterns

by Rupin Chheda and Ravi Parmar

  • 1,969 views
  • 1 comment
  • 7 respects
Add projectSign up / Login