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