Skip to content

Ard Analog Write

DodaTech 1 min read

In this tutorial, you'll learn about Arduino analogWrite Not Producing PWM. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

analogWrite() does not produce a variable voltage on the pin.

Quick Fix

Wrong

analogWrite(4, 128);  // Pin 4 is not PWM-capable on Uno
No PWM signal on pin 4.
int pwmPin = 9;  // PWM-capable pin on Uno
void setup() {
  pinMode(pwmPin, OUTPUT);
}
void loop() {
  analogWrite(pwmPin, 128);  // 50% duty cycle
  delay(2000);
  analogWrite(pwmPin, 64);   // 25% duty cycle
  delay(2000);
}
LED brightness changes (or multimeter shows varying voltage).

Prevention

analogWrite() only works on PWM-capable pins (marked with ~ on Uno: 3,5,6,9,10,11). analogWrite is NOT a true analog output — it is PWM (0-255 duty cycle). For true analog output, use an external DAC or a low-pass filter.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### Which pins support analogWrite on Uno?

Pins 3, 5, 6, 9, 10, 11 (marked with ~). On Mega, more pins support PWM. Check the board pinout diagram.

What is the PWM frequency?

490 Hz on most pins, 980 Hz on pins 5 and 6 (Uno). The frequency affects motor and LED behavior.

Can I change the PWM frequency?

Yes, by changing the timer prescaler. But it affects all pins using that timer. Use the TCCR0B/TCCR1B/TCCR2B registers.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro