 Hi, today we're going to talk about analog, digital and PWM signals. When it comes to signals, all signals are either analog or digital signals. A great example is video signals. HDMI signals are digital signals while something like a composite signal is an analog signal. Both signals are similar in the sense that they use voltages to carry information, but how they use voltages to carry the information is how they're different. Firstly, let's talk about analog signals. These were commonly used in the 1900s before microcontrollers and microprocessors were invented. They're still used today, but the reason they were used so often back then is because the way analog signals work is that they carry information through different voltages. So let's look at an analog signal here. As you can see, the analog signal here is a voltage over time graph. This means that a 0 volt signal versus a 1 volt signal versus a 2 volt signal all carry different information. Now, the advantage to this is it's very easy to change the information you're sending just by changing the voltage. So if we feed one of these analog signals into our microcontroller or microprocessor such as, you know, our Arduino or Raspberry Pi, then what these devices do is that they break down the analog signal into 1024 bits. That means imagine we're working with a 0 to 5 volt range. It'll break that down into a range from 0 to 1024. That means roughly 512 will be 2.5 volts, 0 will be 0 volts and 1023 will be 5 volts. If your range is from 0 to 3 volts, then you know your 0 to 1023 will appropriately be cropped to that manner. So that's how digital devices understand analog signals. Next, let's talk about digital signals. Digital signals became mainstream ever since the invention of transistors, microprocessors and microcontrollers. Digital signals originates from the term digits which is discrete integers. And unlike analog signals which rely on smooth voltage graphs to communicate information, digital signals communicate information through discrete values. A good way to think of the difference between digital and analog signals is to think of a slide ruler and an abacus. An abacus has strict digits and positions for these digits while a slide ruler has a smooth transition between the different values. Computers use digital signals in the form of binary. Binary is different from our regular base 10 number system in that it's a base 2 number system. That means binary only has the digits 0 and 1 which are off for 0 and on for 1. So if you wanted to represent binary signals or digital signals through an analog curve, what we could do is actually assign the 0 volts to 0 and 5 volts to 1 in the case of Arduino or Raspberry Pi. Now, you might be thinking analog voltages can carry any signal from 0 to 5 volts. That means they can carry 1024 increments of this voltage while digital signals can only carry 2 increments either an off or an on value. So why don't we use analog signals when they can carry so much more information? Well, digital signals work around this limitation by using clever timing techniques such as PWM pulse with modulation to carry a lot of data. PWM works by basically injecting these tiny little gaps of 0 or off digital signals into a digital signal and by injecting these off signals at a very high rate it can effectively emulate something like an analog voltage graph. So as you can see here over here you have a peak voltage and as you can see the very little gaps where the digital signals turned off. As you can see here the voltage kind of drops a little bit so there are more gaps and as you can see here the analog voltage that's emulated is even lower you know the gaps the physical gaps between the digital high signals are greater in length. So basically in injecting these gaps at a very high rate what happens is that you flip the digital signal on and off very quickly that you can emulate an analog voltage signal like this. Servos like these are one great example of a device that uses a PWM signal to function. Let's do a very quick demo to actually understand how PWM signals like these can emulate analog signals. So all we need for this demo is an LED and a Raspberry Pi and an Arduino with a PWM compatible pen. I'll just use the Arduino since it's convenient for a simple demo such as this. What I'm going to do is actually wire up the LED to a PWM compatible pen and then I'm going to use this code. In fact this code is available on the examples tab of the Arduino. So what this code over here does is uses PWM signals to emulate an analog right that means emulate the voltages going up and down that means fading the light on fading the light up and then fading the light down using different voltages but we're going to emulate that using PWM signals. So let's actually flash this code and actually test out what it looks like. So I'm going to plug it in as you can see the brightness goes up and then comes back down goes up comes back down. It's very straightforward as you can see when the brightness is very high the PWM signal looks something like this that means very few gaps between the the high voltage and then when the brightness is very low something like now then the gaps between the PWM signals are quite high. So by basically flicking the light switch on and off very quickly you can vary the brightness of the LED. Now this has to be done fast enough so it looks like a continuous motion. If you slow this down using a slow motion camera you will actually see that it's flickering and it's not smooth like it looks like to our eyes. Just like PWM signals there are other digital signals such as SPI and I2C that also use these delays or time gaps to you know standardize what the information means and lastly. The reason why the Arduino and the Raspberry Pi work so well and seamlessly with both analog and digital signals is because of this little device called the analog to digital converter. This device allows the Arduino and the Raspberry Pi to receive analog signals convert them into digital signals to be processed and in the case of outputting an analog signal they can output a digital signal to the analog to digital converter and the analog to digital converter will convert it into an analog signal to be outputted to a different device. Now if you enjoyed this tutorial and want to watch more tutorials like this do subscribe down below. If you have any questions or comments you can leave them down in the comment section and if you like this video do drop me a like. Thanks for watching.