Tutorial 6: Analog Outputs

Alright that's enough about inputs. Let's revisit outputs. In this tutorial I show you how to create an analog output using an Arduino.

Now it's important to mention that this isn't a true analog output. The Arduino is a digital device and is only capable of providing a digital output. However, if you pulse a digital output on and off very quickly, it can 'appear' like an analog output, depending on the response time of the rest of your circuit. This method to create an 'analog output' is also known as Pulse Width Modulation (PWM). In this tutorial I show you how to dim a LED using this PWM analog output.


DIFFICULTY
EASY
CIRCUITRY KNOWLEDGE
LITTLE
C++ PROGRAMMING
LITTLE
ABOUT
0
MINUTES
  • What a PWM output is
  • How to identify and connect to the PWM pins on an Arduino Uno
  • How create a PWM signal using an Arduino
You can copy / paste the code below if you’re having issues with typos or want a shortcut. However I recommend that you follow along in the tutorial to understand what is going on!


int PWMPin = 9 ;
int intensity = 0 ;

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

void loop() {
  intensity += 1 ;
  if (intensity > 255){
    intensity = 0 ;
  }
  analogWrite(PWMPin, intensity) ;
  delay(10) ;
}