From the course: Learning Arduino: Interfacing with Analog Devices

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Understanding the analogWrite function with PWM

Understanding the analogWrite function with PWM - Arduino Tutorial

From the course: Learning Arduino: Interfacing with Analog Devices

Start my 1-month free trial

Understanding the analogWrite function with PWM

- [Instructor] The function to use the pulse width modulation is analogWrite. analogWrite writes an analog value, which is the pulse width modulation wave, to a pin. The pin parameter specifies the digital interface number to use, the value parameter specifies the amount of time the digital pulse is set to high. The duty cycle is now the percentage, its value is between zero and 255. So when sending the values to the analog devices, you write values between zero and 255, where 255 value is 100% duty cycle, generating a five-volt analog voltage from the digital interface. And the zero is for the zero duty cycle, generating zero volts. And the values in between zero and 100% duty cycle is between zero and 255 scale, so the output voltage is multiplying the duty cycle percentage by the 255. You can read more about pulse width modulation by going to the Arduino website to further understand the concept.

Contents