Text Note
Text Note
Theory
Pulse Width Modulation (PWM) generates square-wave pulses of different widths. The width
of the pulse, sometimes called pulse width offset, is commonly proportional to the amplitude
of the input signal. PWM is used to control motors or to power LEDs. The main reason for
using PWM is that it allows for controlling the average amount of power delivered to a load or
the output. They are also used for voltage regulation and modulation in communications.
(a) (b)
Figure 1. (a) and (b) Pulse Width Modulation(PWM)
void setup() {
pinMode(11, OUTPUT);}
void loop()
Reset
{ USB
PB5/SCK
13
12
for (int sound=0; sound<=255; sound PB4/MISO
~ PB3/MOSI/OC2A
11 BUZZER
ARDUINO
10
++){ ~ PB2/OC1B
~ PB1/OC1A
9
8
analogWrite(11,sound);
ATMEGA328P-PU
PB0/ICP1/CLKO
1121
7
delay(8);} PD7/AIN1
6
A0 ~ PD7/AIN1 5
for (int sound=255; sound>=0; sound A1
PC0/ADC0
PC1/ADC1
~ PD5/T1/OC0B
PD4/T0/XCK
4
A2 3
++){ A3
PC2/ADC2
PC3/ADC3
~ PD3/INT1/OC2B
PD2/INT0
2
A4 1
analogWrite(11,sound); A5
PC4/ADC4/SDA
PC5/ADC5/SCL
PD1/TXD
PD0/RXD
0
delay(8);} by TEP