This week’s lab was about analog output. An example of an analog output is the change of brightness in a lamp. A digital output would merely turn the lamp on or off in this instance. A micro-controller such as an Arduino is digital and can only take digital inputs and produce digital outputs. Last week we learned that micro-controllers use an analog-to-digital converter (ADC) to take analog inputs.
For analog output, the micro-controller creates pseudo-analog voltage with pulse width modulation (PWM). This means that the micro-controller basically fakes an analog voltage by producing a series of digital voltage pulses at regular intervals that are so fast (at micro or even nano seconds) it would be perceived as a varying voltage by the output device and humans. What is really varying is the effective voltage produced by these pulses. The effective voltage changes depending on the ratio between the pulse width – the period of high pulse – and the period of low pulse.
For the lab, we changed the state of a servo motor and the tone produced by a Piezo capsule through analog output from the Arduino. The servo motor output was done through PWM, turning the motor 180 degrees each time. The tone change was through change in frequency. This is different from PWM in that the series of digital voltage pulses are not produced in regular intervals; instead the total width from low pulse to high pulse back to low changes, resulting in differing frequencies which in turn is perceived as changing tones to our ears.