• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

New Projects | Privacy Policy | About us | Contact | Disclaimer | Copyright | Videos 

You are here: Home / Arduino Engineering Projects / Arduino PWM Signal Generator Circuit

Arduino PWM Signal Generator Circuit

Last Updated on March 8, 2019 by Swagatam

In this post we elaborately study how to make an Arduino based PWM signal generator circuit, which can be set or adjusted with a potentiometer or a pot to any preferred duty cycle ratio.

By Ankit Negi 

WHAT IS PWM?

pwm or pulse width modulation as the name itself suggest is  modulation of width of the pulses  i.e. how long the pulse is high or low in a given time period. This changes duty cycle of the pulse which eventually determines the average value of pulse as duty cycle is on time divided by total time period.

And frequency plays very important role in pwm, which must be high enough to generate stable output

Pwm is done for variety of purposes like driving a device that works on low voltage or for switching purposes like in SMPS.

PWM USING ARDUINO UNO

Pwm is also one of the factors that make arduino a simplest development board, as pwm can be done by adding just one line code to your program. Note that there are separate digital pins available on arduino UNO for pwm which means these pins can give pwm output.

There are total 6 pwm pins available on arduino UNO that are 3, 5, 6,9,10 and11 out of 14 digital pins. Note that number of pwm pins vary from one type of arduino board to another.

Now there are two ways in which pwm can be performed by arduino:

1. By directly assigning an analog value to the pwm pin between 0 and 255.

Since digital pins in arduino can provide maximum of 5v that means 0 analog value is equal to 0 volts and 255 is equivalent to 5 volts.

And to perform this you have to just add this code to your program:

analogWrite( PWM pin no, value between 0 to 255);

For example:   analogWrite(10,64);// write 64 analog value to pwm pin no 10.

Now this means:: (5/255)*64 volts=  1.25volts i.e. 25% duty cycle.

2. By assigning value according to the input received from analog pins of arduino.
Input can be taken from components like an IR sensor or a potentiometer.

Note that arduino receive analog input in terms of  value between 0 to 1023 which is equivalent to 0 to 5 volts.  So to perform pwm on a pin you must convert this input value in equivalence to number between 0 to 255 and this is called mapping in arduino’s language.

There is a simple code for this:

y= map(x,0,1023:0,255);// where x is the input variable

After this you can perform pwm on a pin using:

analogWrite(PWM pin no,y);// write received mapped value to pin 10

PWM EXAMPLE:

We are going to learn both the technique with this example. For this you need:

1. A potentiometer
2. Two  leds
3. Two 100 ohm resistors

Make connections as shown in circuit diagram:

CIRCUIT DIAGRAM:

caution electricity can be dangerous

CODE:

int x;// initialise variables
int y;
void setup() {
pinMode(10,OUTPUT);//initialise pin 10 as output
pinMode(9,OUTPUT);//initialise pin 9 as output
pinMode(A0,INPUT);//initialise pin A0 as input from pot.
// put your setup code here, to run once:
}
void loop() {
analogWrite(9,125);// directly assigning value to pin 9 i.e. case1
x=analogRead(A0);// read values from potentiometer in terms of voltage
y= map(x,0,1023,0,255);// map those values from 0 to 255 // put your main code here, to run repeatedly:
analogWrite(10,y);// assigning value based on input from pot at pin A0 i.e. case 2
}

How it Works

The basic working of the proposed Arduino PWM signal generator project can be studied from the following paragraph

Pin no 9 can be assigned arbitrary pwm value whereas pin no. 10 gives pwm value in accordance to the position of the potentiometer with respect to ground. Keep changing this arbitrary value for pin 9 as well as rotate potentiometer to see different pwm output on both pins.

You'll also like:

  • 1.  Arduino RGB Flowing Sequential Light Circuit
  • 2.  Wireless Thermometer Using 433 MHz RF Link Using Arduino
  • 3.  Arduino LCD KeyPad Shield (SKU: DFR0009) Datasheet
  • 4.  Arduino Pure Sine Wave Inverter Circuit with Full Program Code
  • 5.  GSM Fire SMS Alert Project
  • 6.  Microcontroller Basics Explored

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

Primary Sidebar

Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (52)
  • 4060 IC Circuits (26)
  • 555 IC Circuits (99)
  • 741 IC Circuits (20)
  • Arduino Engineering Projects (83)
  • Audio and Amplifier Projects (115)
  • Battery Chargers (83)
  • Car and Motorcycle (95)
  • Datasheets (74)
  • Decorative Lighting (Diwali, Christmas) (33)
  • Electronic Components (101)
  • Electronic Devices and Circuit Theory (36)
  • Electronics Tutorial (120)
  • Fish Aquarium (5)
  • Free Energy (34)
  • Fun Projects (13)
  • GSM Projects (9)
  • Health Related (20)
  • Heater Controllers (29)
  • Home Electrical Circuits (104)
  • How to Articles (20)
  • Incubator Related (6)
  • Industrial Electronics (28)
  • Infrared (IR) (40)
  • Inverter Circuits (98)
  • Laser Projects (12)
  • LED and Light Effect (93)
  • LM317/LM338 (21)
  • LM3915 IC (25)
  • Meters and Testers (66)
  • Mini Projects (150)
  • Motor Controller (67)
  • MPPT (7)
  • Oscillator Circuits (26)
  • PIR (Passive Infrared) (8)
  • Power Electronics (34)
  • Power Supply Circuits (79)
  • Radio Circuits (10)
  • Remote Control (48)
  • Security and Alarm (62)
  • Sensors and Detectors (121)
  • SG3525 IC (5)
  • Simple Circuits (75)
  • SMPS (29)
  • Solar Controllers (61)
  • Timer and Delay Relay (53)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (41)
  • Ultrasonic Projects (16)
  • Water Level Controller (45)

Calculators

  • AWG to Millimeter Converter
  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator

© 2023 · Swagatam Innovations