Skip to content

Arduino Generating a Pulse Does Not Produce Correct Width

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about Arduino Generating a Pulse Does Not Produce Correct Width. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

Manual pulse generation using digitalWrite and delayMicroseconds produces wrong pulse width.

Quick Fix

Wrong

digitalWrite(9, HIGH);
delayMicroseconds(10);  // Overhead makes this >10 µs
digitalWrite(9, LOW);
Pulse width is ~15 µs instead of 10 µs (includes digitalWrite overhead).
int pulsePin = 9;

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

void sendPulse(int widthUs) {
  digitalWrite(pulsePin, HIGH);
  delayMicroseconds(widthUs);
  digitalWrite(pulsePin, LOW);
}

void loop() {
  sendPulse(10);  // ~10 µs pulse (compensated)
  delay(1000);
}
Oscilloscope shows ~10 µs pulse on pin 9 every second.

Prevention

delayMicroseconds() is fairly accurate (3-4 clock cycle overhead on AVR). For pulses under 10 µs, use direct port access (PORTx) or NOP delays. The overhead of digitalWrite is ~5 µs on AVR. For precision pulses, use hardware PWM or timer output compare.

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

FAQ

### What is the minimum pulse I can generate?

~1 µs using direct port access on 16 MHz AVR. Using digitalWrite, the minimum is ~10 µs due to function overhead.

How accurate is delayMicroseconds()?

Accurate to within 1-3 µs for values >10 µs. For values <10 µs, the function call overhead dominates.

Can I generate pulses without blocking?

Use hardware timers in CTC mode or PWM mode to generate pulses without CPU involvement.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro