กลับไปหน้ารวมไฟล์
read-pwm-duty-cycle-visuino-en.md

Signal Analysis: Reading PWM Duty Cycle

We often output PWM signals to dim an LED or control a servo motor. But how does an Arduino read a PWM signal coming from another device, like an RC receiver or an industrial sensor? The Read Duty Cycle project acts as a simple, low-frequency oscilloscope.

invisible_mess_glasses_relay_schema_1772681179521.png

The pulseIn() Function

While interrupts (ISRs) are the most accurate way, the simplest method is the native pulseIn() command.

  1. The High Pulse: The Arduino waits for the incoming pin to go HIGH, starts a microsecond timer, and waits for it to go LOW. That is the time_high.
  2. The Low Pulse: It does the same to measure time_low.
  3. The Math: The Duty Cycle percentage is calculated by: Duty Cycle = (time_high / (time_high + time_low)) * 100.

Visuino: Visual Programming

For those who struggle with C++ syntax, this project is commonly taught using Visuino. Visuino is a drag-and-drop graphical environment.

  • You drag a 'PulseIn' block onto the screen.
  • You draw a wire connecting it to a 'Math Divider' block.
  • You draw a wire sending the final result to a 'Serial Terminal' block. Visuino then automatically generates the complex C++ code in the background and uploads it to the board!

Required Hardware

  • Arduino Uno/Nano: The analyzer.
  • A 5V Signal Generator: This could be a 555-Timer chip, an RC car receiver, or a second Arduino generating analogWrite().
  • Visuino Software (Optional, but highly recommended for visual learners).

ข้อมูล Frontmatter ดั้งเดิม

title: "Read Duty Cycle of a PWM Signal"
description: "Analyze the waveform! Learn how to use visual programming to accurately read and measure the width of incoming Pulse Width Modulation signals."
category: "Tools & Equipment"
difficulty: "Intermediate"