Pulse Width Modulation (PWM), is a technique that can be used to create analogue from digital! Using digital electronics to create a square wave, a signal can be created that repeatedly alternates between an ON and OFF state. This pattern can range between 0V and the supply voltage. This is achieved by varying the period of time that the signal spends in the ON and OFF state. The duration of time that signal is in the ON state is called the pulse width.

PWM has many uses, including controlling the brightness of LEDs, generating audio and controlling the speed of motors.

You can use PWM with an Arduino by using the analogWrite(pin, dutyCycle) function. You can use pins 3, 5, 6, 9, 10 or 11 for PWM. dutyCycle needs to be a number between 0 and 255. The result will be a square wave.

There is actually another way of generating PWM signals on an Arduino – by using a technique called bit-banging. Bit-banging involves ‘manually’ turning a pin ON and OFF. You may wonder why you would do this when an Arduino has PWM pins! One reason is that you can use any digital pin! Also, you have control over the frequency and duty cycle.