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.

  • 20,193 views
  • 0 comments
  • 3 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

  • 3,459 views
  • 1 comment
  • 6 respects

SD Card Temperature Data Logger

Project tutorial by 3 developers

  • 15,501 views
  • 0 comments
  • 11 respects

LED Ring Real Time Clock

Project showcase by 3 developers

  • 2,521 views
  • 0 comments
  • 1 respect

LED Ring Patterns

by Rupin Chheda and Ravi Parmar

  • 3,446 views
  • 1 comment
  • 7 respects

Location Display With Idiotware Shield

Project tutorial by 3 developers

  • 2,358 views
  • 0 comments
  • 5 respects

How to Use a Datalogger

by MisterBotBreak

  • 5,905 views
  • 2 comments
  • 21 respects
Add projectSign up / Login