What Is PWM? How To Use It In IoT Projects?

Electronics devices change the electric current into different forms of energy for powering appliances or encoding information for transferring them.  This encoded message is known as an Electronics signal. The electronics world consists of two types of signals namely: Analog and Digital Signal. An Analog signal is often known as a natural signal.

therefore, which uses continuous signals varying with magnitude and time using sine waves whereas a Digital signal is a discrete signal as an on/off signal or 0/1 in binary which uses square waves. A processor uses digital signals for processing and its functioning but it requires Analog signals to telemeter data from the physical. Both Analog and Digital signals are utilized by a processor and for this purpose, DAC(Digital-to-analog converters) and ADC(Analog-to-digital converters) come into the picture.

Analog Signals

An Analog Signal is a continuous signal which is obtained by varying one of the signal’s characteristics such as amplitude, frequency, current, voltage, phase, etc. Analog signals interact with the physical world such as measuring temperature, pressure, Light intensity, etc. which is further processed to decide the appropriate course of action. This signal records waves in their original form without any modification providing a continuous set of values.

The Analog signal is used in radio broadcasts in two forms of modulation namely: FM( Frequency Modulation) and AM(Amplitude Modulation). Both FM & AM play a vital role in the transmission of data. But the Digital signal was introduced to overcome some disadvantages of Analog signals such as data corruption, loss of quality, and high cost. To enjoy the features of both. Analog and Digital Signal the Pulse-Width Modulation (PWM) was introduced.

PWM & Its use 

Pulse Width Modulation (PWM) is a process of reducing distortion in a communication system. It is in use for encoding the amplitude of a signal into the tim of another signal for transmission. Although This is a technique in use for communications, It can also be use in power management as its main purpose is to control the voltage or current supplied to the various electrical devices. One of the biggest benefits of PWM is that power loss is minimal compare to that of those using regulate power supply such as a potentiometer.

The basic principle behind PWM is turning off the output power instead of limiting it. The PWM technique can also be in use in microcontrollers/microprocessors for getting Analog results using digital means. Digital signals are ply to create a square wave with On/Off or binary 0/1 output. This on/off can switch voltages patterns between 5V and 0V respectively. The time when the signal is high i.e. 5V is refer to as ON time.

Similarly, When the signal is low i.e. 0V refer to as OFF time and the sum of both ON and OFF time is refer to as Period. The Duty Cycle is the percentage of the ON time during a period. Now, by controlling the duty cycle the desire Analog results can be achieve as the period must be less.

PWM in Project

So for 50% duty cycle and the period frequency of 1 kHz, the LED will be ON (high) for half a second and it will be OFF (low) for the rest of the second. Now, if we increase the frequency to 100 kHz it will appear to the naked human eye that the LED is glowing at half of its brightness. The other levels can be also be achieve by carrying the duty cycle and period.

Thus, achieving the purpose without using regulated voltages. This technique can be easily implement in some microcontrollers like Arduino, NodeMCU, and others. An example of the source code for Arduino Uno with 70% duty cycle and 50kHz frequency is below:

Summary

So, in this PWM tutorial, we went through the basics of signals used in Electronics. We understood the definition of Analog signal and getting Analog output using digital means. We also went through the definitions of PWM and its implementation.  As an embedded systems enthusiast, knowing this technique can help you in the power management of your project.

PWM is a technique for reducing distortion by controlling the power output of the system. This is the right time to implement the PWM technique in your project and it may give rise to creative ideas.

Hope the tutorial was helpful. If there is anything we are missing out on, do let us know in the comments section.

Written by: Harshit Goel

Reviewed by: Batta Pruthvi

If you are Interested In Machine Learning You Can Check Machine Learning Internship Program
Also Check Other Technical And Non Technical Internship Programs

Leave a Comment

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