IdiotWare TeamRupin ChhedaJehangir Khajotia
Published © GPL3+

Pulse Width Modulation Using a Potentiometer

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

BeginnerProtip1 hour27,962
Pulse Width Modulation Using a Potentiometer

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
idIoTware Shield
idIoTware Shield
×1
USB-A to B Cable
USB-A to B Cable
×1
Generic Jumper (0.1")
Generic Jumper (0.1")
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

idiotware-shield

Code

pwm_pot

Arduino
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;
   }    

Credits

IdiotWare Team

IdiotWare Team

20 projects • 16 followers
The Idiotware Shield is a learning platform for quickly bringing to life hundreds of Arduino projects, whether you’re a novice or expert.
Rupin Chheda

Rupin Chheda

35 projects • 83 followers
Resident Maker at CuriosityGym! Electronics Engineer, CAD Modeller, Educator
Jehangir Khajotia

Jehangir Khajotia

14 projects • 19 followers

Comments