Reading time: 3 min.

How to control motor speed? How to dim and brighten LEDs? In this article we answer these questions. This knowledge will be useful in many projects.

What is PWM and fill?

PWM stands for Pulse-Width Modulation. It is a method of controlling a current or voltage signal by changing the filling of the signal. The amplitude and frequency of the signal remain constant, but the so-called filling changes.

Imagine a simple circuit in which an LED is installed that turns on and off alternately by software. From the moment the LED is switched on, through its switching off, until it is switched on again, the time period is equal to 1 millisecond. The moment when the logical signal “1” is applied to the diode, i.e. power supply with an appropriate voltage value is applied to its output, can be regarded as “on”. Turning off, on the other hand, is the moment when the diode receives a logical “0”, i.e. it is deprived of power. The diode lights up for half a millisecond, and for the second half millisecond it is off, and this process repeats itself over and over again. This is what every millisecond looks like. From the perspective of the human eye, you can’t even see the blinking – the change is too quick for us to notice, which gives the illusory effect that the LED simply dimmer than if it were permanently on.

elecronic circuit with LEDs
An electronic circuit with LEDs is one of the simplest circuits to build.

By changing the fill factor, you are actually changing the duration of the high state (the LED’s light) during a certain period (in this case 1 millisecond). For example, if the fill factor is increased, the diode can be on for 0.8 milliseconds and off for 0.2 milliseconds. As a result, to the human eye the diode will simply glow brighter than it would with a fill allowing it to glow for only 50% of the period. The percentage of the period in which the logic state is high is called the fill factor. So, in simple terms, the principle of a PWM signal is a way of modulating a rectangular signal by adjusting the pulse width (i.e. adjusting the fill factor over a given time interval).

PWM with Arduino and Raspberry Pi

PWM is a commonly used signal in microprocessor technology. It can be easily implemented by software, but on boards such as Arduino or Raspberry Pi there are suitable ports prepared for this purpose. In this case, the PWM signal is generated by hardware, which can significantly reduce the load on the program and makes it unnecessary for the programmer to write the code themselves, using the microprocessor interrupts. For example, there are channels in Arduino UNO, which are able to generate PWM signal in hardware – usually in this type of devices, the full period is 1/490 of a second, and the fill can be from 0 to 255 (8 bits).

Raspberry Pi 4

CHECK AT STORE

Arduino UNO

CHECK AT STORE

What can PWM be used for?

The most obvious use of a PWM signal is of course to control the brightness of an LED, but it is commonly used for a much wider range of applications. A good example is controlling the operation of a DC motor. By changing the fill value you can easily limit or increase the speed of the motor shaft.

With this kind of control you can sensibly control, for example, the speed of your mobile robot. You can easily check the operation of such a system. All you need for this is a contact board, a motor, some connection wires, an H-bridge and, for example, an Arduino and a potentiometer. Once the components are properly connected, you can control the potentiometer by changing the fill of the PWM signal fed to the DC motor.

You can get a similar effect instead of a motor by connecting a buzzer. By changing the filling you will be able to control the volume of the sound emitted. Another practical application of this signal can be for example a servomechanism. By changing the gain you can precisely adjust the position of the servo. The higher the resolution of the PWM signal, the more accurately you can determine the position.

The simplest circuit will suffice to learn and test the operation of the PWM syng.

This is an excellent solution that will work well for robots that require high precision in their movements, for example. If you try to achieve the same effect with a set of ordinary DC motor and encoder, you will unfortunately get a much less accurate result.

There are still a virtually infinite number of other practical applications for the PWM signal. It is worthwhile to practice and see for yourself how this phenomenon works, in order to be able to use it efficiently in your future projects.

How useful was this post?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 6

No votes so far! Be the first to rate this post.

Share:

Picture of Maciej Figiel

Maciej Figiel

Versatile, he is eager to take on challenges because he thinks it is the fastest way to progress. He values contact with nature and an active rest. Automotive and new technologies enthusiast.

See more:

Leave a Reply

Your email address will not be published. Required fields are marked *

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.