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 - Arduino Tutorial
From the course: Learning Arduino: Interfacing with Analog Devices
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.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
How Arduino generates analog output1m 4s
-
(Locked)
Understanding pulse-width modulation (PWM)2m 8s
-
(Locked)
Understanding the analogWrite function with PWM1m 19s
-
(Locked)
Wire up an LED1m 5s
-
(Locked)
Write code to use PWM with the LED1m 56s
-
(Locked)
Understanding the map() function1m 45s
-
(Locked)
Wiring a potentiometer to control LED1m 13s
-
(Locked)
Coding to control the LED with a potentiometer3m 42s
-
(Locked)
-
-
-