Youtube video

Things you need

Let's code

First we set the LED pin witch I’ve chosen pin 9 because I like  !
We also create an int named pot to store the analog value in it

and at last we also set the potentiometer pin as A0 why you ask ?

well we should use a ADC pin to convert analog to digital

Then in void loop we get the analog value of pin A0 and save it in pot

After that, we create a PWM signal to fade the LED

How to build

What's PWM?

Simply it just turns the pin on and off very fast, and we can change the duration of it being on or off

More info:
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between the full Vcc of the board (e.g., 5 V on Uno, 3.3 V on a MKR board) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of “on time” is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and Vcc controlling the brightness of the LED.

What's ADC

An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number (most of the time 5V = 1023) .

Thanks for reading and watching, please give us a star and comment down bellow
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments