/
Analog Output

Analog Output

Analog vs. Digital

  • Arduinos are digital devices – ON or OFF. Also called discrete

  • Analog signals are anything that can be a full range of values. Examples?

Digital Signal

Analog Signal

Digital Signal

Analog Signal

  • Arduino does not generate true analog outputs. The instantaneous output is always 0V or 5V.

  • How do we generate the effect of analog using digital?

Pulse Width Modulation (PWM)

  • To create (mimic) an analog signal, the Arduino uses a technique called Pulse Width Modulation (PWM). By varying the duty cycle, we can mimic an “average” analog voltage

analogWrite()

C++

Blocks

C++

Blocks

Using a variable val

analogWrite(pin, val);

Note : The example above shows pin 11 being used. We can't use a variable for pin number with Blocks

Using a constant (hard-coded) val

analogWrite(3, 128);

 

pin – refers to the OUTPUT pin (limited to pins 3, 5, 6, 9, 10, 11.) – denoted by a ~ symbol

val – 8 bit value (0 – 255). 

0 => 0V

255 => 5V