Eli5: So apparently Arduino Uno cannot output analog signals and so it uses pulse width modulation to mimic an analog signal output. So then, how can a square wave with varrying width mimic an analog signal’s sine wave?

218 views

Eli5: So apparently Arduino Uno cannot output analog signals and so it uses pulse width modulation to mimic an analog signal output. So then, how can a square wave with varrying width mimic an analog signal’s sine wave?

In: 34

18 Answers

Anonymous 0 Comments

The important factor is that the percentage of the cycle for which the output is high can be varied. This is the pulse width in the name, and is more commonly referred to as the duty cycle, with 100% being high all the time, 50% being high 50% of the time and low 50% of the time.

For PWM to work perfectly you need a load that will smooth the output slightly. This is true if the load has some capacitance or inductance, which most do. If you just set your output to a fast 50% duty cycle square wave then the load would experience that as a smooth output at half the supply voltage.

This is the key point; the cycles are fast enough that the load experiences them as merely the average voltage from a couple of cycles. This average voltage depends on the duty cycle – 100% duty cycle means the average voltage over the cycle is 100% of supply voltage, and so on.

So start with a 100% duty cycle, and slowly reduce to 0%. The load will experience this as a slowly reducing voltage, just like you would get out of an analogue supply. Now ramp the duty cycle up and down and hey presto you have a sine wave!

Anonymous 0 Comments

It can’t. It outputs a square wave, the idea is that for some applications they don’t care about voltage, they care about average voltage, if the voltage outputted is a square wave which is 5 volts 20% of the time and 0 80% of the time you can average this to 1 volt. For some things like say LEDs or lightbulbs, this works pretty well to control their brightness.

But for other applications it just won’t work. You might be able to achieve some better results by using a capacitor, this can smooth out the output (in the industry we call this a low pass filter) but it still will be hard to make a perfect sign wave out of this.

Anonymous 0 Comments

The important factor is that the percentage of the cycle for which the output is high can be varied. This is the pulse width in the name, and is more commonly referred to as the duty cycle, with 100% being high all the time, 50% being high 50% of the time and low 50% of the time.

For PWM to work perfectly you need a load that will smooth the output slightly. This is true if the load has some capacitance or inductance, which most do. If you just set your output to a fast 50% duty cycle square wave then the load would experience that as a smooth output at half the supply voltage.

This is the key point; the cycles are fast enough that the load experiences them as merely the average voltage from a couple of cycles. This average voltage depends on the duty cycle – 100% duty cycle means the average voltage over the cycle is 100% of supply voltage, and so on.

So start with a 100% duty cycle, and slowly reduce to 0%. The load will experience this as a slowly reducing voltage, just like you would get out of an analogue supply. Now ramp the duty cycle up and down and hey presto you have a sine wave!

Anonymous 0 Comments

Can I use the title of this as an Eli5?

Anonymous 0 Comments

It can’t. It outputs a square wave, the idea is that for some applications they don’t care about voltage, they care about average voltage, if the voltage outputted is a square wave which is 5 volts 20% of the time and 0 80% of the time you can average this to 1 volt. For some things like say LEDs or lightbulbs, this works pretty well to control their brightness.

But for other applications it just won’t work. You might be able to achieve some better results by using a capacitor, this can smooth out the output (in the industry we call this a low pass filter) but it still will be hard to make a perfect sign wave out of this.

Anonymous 0 Comments

Can I use the title of this as an Eli5?

Anonymous 0 Comments

First, an analog signal does not mean it is a sine wave. Analog just means it has a continuous range of output between it’s values. The Uno does not have a built in digital to analog converter built in, so it only outputs discrete binary values.

The Arduino Uno also only deals with positive DC voltage. Most applications of wave signals specifically want to have part of the wave below reference ground, which requires additional circuitry to divide your voltage.

The Uno intentionally uses a basic microcontroller for learning and doing small projects. Any useful circuit is going to require more components. If your project needs an analog output, get an digital to analog converter.

Directly to your question: Arduino Uno does not have the ability to directly mimic a sine wave. It’s PWM is only positive. At best, it can mimic the absolute values (rectified) of a sine wave. Other answers explain how it does this very well.

Anonymous 0 Comments

First, an analog signal does not mean it is a sine wave. Analog just means it has a continuous range of output between it’s values. The Uno does not have a built in digital to analog converter built in, so it only outputs discrete binary values.

The Arduino Uno also only deals with positive DC voltage. Most applications of wave signals specifically want to have part of the wave below reference ground, which requires additional circuitry to divide your voltage.

The Uno intentionally uses a basic microcontroller for learning and doing small projects. Any useful circuit is going to require more components. If your project needs an analog output, get an digital to analog converter.

Directly to your question: Arduino Uno does not have the ability to directly mimic a sine wave. It’s PWM is only positive. At best, it can mimic the absolute values (rectified) of a sine wave. Other answers explain how it does this very well.

Anonymous 0 Comments

The trick is that the real world is analog.

If you use PWM on a LED light, the LED will blink really really fast. But your eyes can’t *see* really fast blinking: they will average out all those tiny pulses! A LED which blinks at 25 microseconds on & 75 microseconds off will *look* identical to an analog light which is at 25% brightness. A high-speed camera could see the difference, but your *eyes* can’t.

You can use a similar thing with a speaker. The speaker coil itself has physical mass and takes a while to move, so if your pulses are fast enough it’ll move to the *average* value of them because it simply can’t respond fast enough for each individual pulse.

This principle can also be exploited to convert a PWM signal to a true analog signal: simply use a low-pass filter! In reality there is no such thing as a perfect square wave, and it can also be seen as a sum of sine waves of an [increasingly higher frequency](https://en.wikipedia.org/wiki/Square_wave#Fourier_analysis). If we filter out the higher frequencies, we’ll be left with a good old regular analog signal.

Anonymous 0 Comments

The trick is that the real world is analog.

If you use PWM on a LED light, the LED will blink really really fast. But your eyes can’t *see* really fast blinking: they will average out all those tiny pulses! A LED which blinks at 25 microseconds on & 75 microseconds off will *look* identical to an analog light which is at 25% brightness. A high-speed camera could see the difference, but your *eyes* can’t.

You can use a similar thing with a speaker. The speaker coil itself has physical mass and takes a while to move, so if your pulses are fast enough it’ll move to the *average* value of them because it simply can’t respond fast enough for each individual pulse.

This principle can also be exploited to convert a PWM signal to a true analog signal: simply use a low-pass filter! In reality there is no such thing as a perfect square wave, and it can also be seen as a sum of sine waves of an [increasingly higher frequency](https://en.wikipedia.org/wiki/Square_wave#Fourier_analysis). If we filter out the higher frequencies, we’ll be left with a good old regular analog signal.