Skip to main content

Command Palette

Search for a command to run...

What is the Arduino Uno duty cycle?

Published
4 min read
What is the Arduino Uno duty cycle?

This is an excellent question that gets to the heart of how Arduino controls things like LED brightness, motor speed, and servos.

The short answer is: The Arduino Uno itself doesn't have a fixed duty cycle. You, as the programmer, define the duty cycle for its PWM outputs, and it can be any value from 0% to 100%.

Let me explain in detail.

1. What is Duty Cycle?

Duty cycle is the percentage of one period in which a signal is ON (high).

text

Duty Cycle = (ON Time / Total Period Time) × 100%

Visual Example:

text

50% Duty Cycle:  _┌┐_┌┐_┌┐_┌┐_   (ON half the time, OFF half the time)
25% Duty Cycle:  _┌┐____┌┐____┌┐_ (ON 25% of the time)
75% Duty Cycle:  _┌┐┌┐┌┐_┌┐┌┐┌┐_ (ON 75% of the time)

2. Arduino Uno PWM Technical Specifications

The Arduino Uno uses 8-bit timers for Pulse Width Modulation (PWM):

FeatureSpecification
PWM Resolution8-bit
PWM Values0 to 255
Duty Cycle Range0% to 100%
PWM Frequency~490 Hz (pins 5, 6: ~980 Hz)
PWM Pins3, 5, 6, 9, 10, 11

Duty Cycle Calculation:

text

Duty Cycle = (PWM Value / 255) × 100%

Common Values:

cpp

analogWrite(0)   → 0/255 = 0% Duty Cycle
analogWrite(64)  → 64/255 = 25.1% Duty Cycle
analogWrite(127) → 127/255 = 49.8% Duty Cycle
analogWrite(191) → 191/255 = 74.9% Duty Cycle
analogWrite(255) → 255/255 = 100% Duty Cycle

3. Practical Code Examples

Example 1: Basic Duty Cycle Control

cpp

const int pwmPin = 9; // PWM capable pin
int dutyCycle = 0;    // 0-255 range

void setup() {
  pinMode(pwmPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // Set to 50% duty cycle (127/255 ≈ 50%)
  analogWrite(pwmPin, 127);
  Serial.println("50% Duty Cycle");
  delay(2000);

  // Set to 25% duty cycle (64/255 ≈ 25%)
  analogWrite(pwmPin, 64);
  Serial.println("25% Duty Cycle");
  delay(2000);

  // Set to 75% duty cycle (191/255 ≈ 75%)
  analogWrite(pwmPin, 191);
  Serial.println("75% Duty Cycle");
  delay(2000);
}

Example 2: LED Brightness Control (Fading)

cpp

int ledPin = 9;    // LED connected to digital pin 9
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Set the brightness (duty cycle) of pin 9
  analogWrite(ledPin, brightness);

  // Change the brightness for next time through the loop
  brightness = brightness + fadeAmount;

  // Reverse the direction of fading at the ends
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }

  delay(30); // Wait for 30 milliseconds
}

Example 3: Motor Speed Control

cpp

const int motorPin = 3;

void setup() {
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // Gradually increase speed (duty cycle) from 0% to 100%
  for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) {
    analogWrite(motorPin, dutyCycle);

    // Calculate and display actual percentage
    float percentage = (dutyCycle / 255.0) * 100;
    Serial.print("Duty Cycle: ");
    Serial.print(percentage);
    Serial.println("%");

    delay(20);
  }

  delay(1000);

  // Gradually decrease speed back to 0%
  for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--) {
    analogWrite(motorPin, dutyCycle);
    delay(20);
  }

  delay(1000);
}

4. Measuring Duty Cycle with Oscilloscope

If you want to verify the duty cycle, you can measure it:

Expected Results:

  • analogWrite(9, 0) → 0V constant (0% duty cycle)

  • analogWrite(9, 64) → ~1.25V average (25% duty cycle)

  • analogWrite(9, 127) → ~2.5V average (50% duty cycle)

  • analogWrite(9, 191) → ~3.75V average (75% duty cycle)

  • analogWrite(9, 255) → 5V constant (100% duty cycle)

5. Advanced: Changing PWM Frequency

The default frequencies work for most applications, but you can change them:

cpp

// For pins 5 and 6 (Timer 0)
void setup() {
  // Set PWM frequency to ~31kHz for pins 5 and 6
  TCCR0B = TCCR0B & 0b11111000 | 0x01;

  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  analogWrite(5, 127); // 50% duty cycle at higher frequency
}

Frequency Prescaler Values:

  • 0x01 → ~31kHz

  • 0x02 → ~4kHz

  • 0x03 → ~490Hz (default)

  • 0x04 → ~122Hz

  • 0x05 → ~30Hz

6. Common Applications

Duty CycleApplication
0%LED off, Motor stopped
25%Dim LED, Slow motor
50%Medium brightness, Medium speed
75%Bright LED, Fast motor
100%Full brightness, Full speed

Summary

  • The Arduino Uno doesn't have "a" duty cycle - you control it programmatically

  • Range: 0% to 100% (0 to 255 in 8-bit values)

  • Use analogWrite(pin, value) where value = 0-255

  • Default frequency: ~490Hz (pins 5 and 6: ~980Hz)

  • Resolution: 256 steps (0-255), which is about 0.4% per step

The key point is: You are in complete control of the duty cycle. You tell the Arduino exactly what percentage you want by writing values from 0 to 255 to the PWM pins.

More from this blog

A

Ampheo Electronic Blog-Chip and component knowledge sharing

181 posts

Original and Genuine Electronic Components Distributor