PWM Pins


Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of “on time” is called the pulse width. To get varying analog values, you change or modulate, that pulse width. If you repeat this on-off pattern fast enough, the result is as if the signal is a steady voltage between 0 and 5v controlling the speed of the motor.

evive PWM Pins

How to use PWM Pins in Arduino IDE


Generally, Arduino’s PWM frequency is about 500Hz. In Arduino IDE, we use PWM concept through analogWrite() function. We give a value ranging on a scale of 0 – 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.

Syntax: analogWrite(pin, value)

Where pin is the pin to write to and value is the duty cycle between 0 (always off) and 255 (always on).


How to use PWM Pins in Scratch

Set PWM pin output block is a Robot block and a stack block. This block set PWM output on evive PWM pins. The user can select the output from a range of 0 to 255.  If the PWM output is 128, then half the time output will be High and for rest, output will be Low.

set pwm

Available  pins in evive:

  • 12 PWM pins available in evive: 2 to 13
  • Buzzer pin (46)

You can select the pin using drop down menu.

This block can be used in Arduino Mode as well as in Scratch Mode.


Controlling Pin 13 LED brightness using Potentiometer 2 in Arduino Mode:

Controlling Pin 13 LED brightness using Potentiometer 2 in Arduino Mode

Share this Page Facebook Twitter Google+ Pinterest Reddit Print Related Tutorials Featured Projects

Leave a Reply

Close Menu


STEMpedia Starter Package is now on Indiegogo!
Get 41% OFF with Super Early Bird discounts!