Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Arduino BLINK Blueprints

You're reading from   Arduino BLINK Blueprints Get the most out of your Arduino to develop exciting and creative LED-based projects

Arrow left icon
Product type Paperback
Published in May 2016
Publisher Packt
ISBN-13 9781785284182
Length 134 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Utsav Shah Utsav Shah
Author Profile Icon Utsav Shah
Utsav Shah
Samarth Shah Samarth Shah
Author Profile Icon Samarth Shah
Samarth Shah
Arrow right icon
View More author details
Toc

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:

Pulse width modulation (PWM)

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...

You have been reading a chapter from
Arduino BLINK Blueprints
Published in: May 2016
Publisher: Packt
ISBN-13: 9781785284182
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 $19.99/month. Cancel anytime