Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arduino BLINK Blueprints

You're reading from  Arduino BLINK Blueprints

Product type Book
Published in May 2016
Publisher Packt
ISBN-13 9781785284182
Pages 134 pages
Edition 1st Edition
Languages
Author (1):
Utsav Shah Utsav Shah
Profile icon Utsav Shah

LED fading


You can fade out and fade in the light of an LED using Arduino's analogWrite(pin, value) function. Before we get into using the analogWrite() function, we will understand the concept behind the analogWrite() function. To create an analog signal, Arduino uses a technique called Pulse width modulation (PWM).

Pulse width modulation (PWM)

PWM is a technique for getting an analog signal using digital means. By varying the duty cycle (duty cycle is the percentage of a period, when a signal is active.), we can mimic an "average" analog voltage. As you can see in the following image, when we want medium voltage, we will keep the duty cycle as 50%. Similarly, if we want to achieve low voltage and high voltage, we will keep the duty cycle as 10% and 90% respectively. In this application, PWM is the process to control the power sent to the LED:

Using PWM on Arduino

Arduino UNO has 14 digital I/O pins. As mentioned in Chapter 1, Getting Started with Arduino and LEDs, we can use six pins (3, 5...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}