Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Confluence
For you

Electrical Engineering
Results will update as you type.
  • Aesthetic elements in Eagle
  • Actuators and Outputs
  • Aktuatoren (DE)
  • Analog Input
  • Analog Sensors
  • Arduino Grundlagen
  • Arduino Programmieren
  • Arduino und Processing
  • Shift Registers
  • Carvey
  • Capacitors
  • Bread Boards
  • Digitaler Input
  • Digitaler Output
  • Eagle
  • Energy Harvesting
  • H-Bridge
  • I2C (en)
  • Interrupt Service Routine
  • Mosfet Transistor
  • LED
  • PCBs Herstellen
  • Pololu Servo Controller
  • Relays as Switches
  • Pulse Width Modulation
  • RFiD
  • Schrittmotorentreiber
  • SD Karten
  • Signal Filtering
  • Transistors as Switches
  • Widerstand
  • PCB Manufacturing
  • PlatformIO
  • Lynx Smart Motion Servo
  • Electronics Basics (EN)
  • Arduino Basics (en)
  • Arduino Programming (EN)
  • Digital Outputs (en)
  • Digital Input (en)
  • Serial Communication (en)
  • Pulse Width Modulation (en)
  • Resistors (en)
  • Arduino and P5.js
  • Arduino and ml5.js
  • Project box 2021
  • Servo Motors
  • H-Bridge (DE)
  • Networking
  • Bit Shifting
  • C++ (Arduino) Variables
  • Stepper Motor Drivers
  • Interrupt Service Routine (en)
  • Common Arduino Problems
  • Finite State Machine
  • Voltage Regulators
  • Arduino USB HID (Human Interface Devices)

    Two hearts overlapped with each other
    Welcome back
    Catch up on the top discussions and highlights from your team.
    /
    Pulse Width Modulation (en)

    Pulse Width Modulation (en)

    Aug 24, 2020

    German Version

    There is no way to generate an analogue value on the Arduino directly, so to make an LED fade we need to use pulse-width modulation. A digital signal from the Arduino switches the corresponding PIN (PWM pins are marked with PWM or ~) ON and OFF very quickly. The longer the ON times of the pin, the brighter the LED appears to us - in contrast, the LED appears darker to us when the OFF times are longer. The PWM function of the microcontroller enables us to set simple values at the corresponding PIN. 0 corresponds to 0V or OFF and 255 corresponds to 5V or ON. Any intermediate value (e.g. 127) can be seen as a combination of 0V and 5V and then corresponds to e.g. 2.5V.

    Visualization

    This visualization shows how a PWM value is generated by the Arduino.

    Function
     

    To use a PWM-enabled pin on the Arduino e.g. To dim an LED, we call the following function:

    analogWrite(PIN, value);
    Value (0-255) at the specified PIN


    Here is a short example that fades an LED

    Example PWM Expand source
    #define LED_PIN 11 // PWM enabled pin
     
    void setup()
    {
      pinMode(LED_PIN, OUTPUT); 
    }
     
    void loop()
    {
      for(int i=0; i<255; i++)
      {
        analogWrite(LED_PIN, i); // Set the value i on LED_PIN 
        delay(10);
      }
       
      for(int i= 255; i>0; i--)
      {
        analogWrite(LED_PIN, i); // Set the value i on LED_PIN 
        delay(10);
      }
    }

    Further Information:

    PWM - on Arduino.cc
    The Secrets of Arduino PWM - on Arduino.cc
    analogWrite() - on Arduino.cc
    Pulse-Width-Modulation - on Wikipedia.org

    , multiple selections available,
    {"serverDuration": 16, "requestCorrelationId": "cd8fac84b6f148e8bb4c95f1316692a4"}