PWM Pins

June 2, 2017

Introduction

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

analogWrite()

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).

Example

How to use PWM Pins in Scratch

Set PWM pin () output as () block is an evive extension 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, the output will be Low.

set pwm pin output as

Available  pins in evive:

  • 12 PWM pins available in evive: 2 to 13

You can select the pin using the drop-down menu.

Example

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

set pwm output example

Share this Documentation
Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Tutorials & Projects
set pwm pin output as

set PWM pin () output as ()

The 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, the output will be Low.
Featured Projects

Leave a Reply