RobotGeek 101: Pulse Width Modulation (PWM) Introduction

This lesson is part of the RobotGeek 101 Learning Series. If you haven't already, please download the example sketches, and follow through the Geekduino Getting Started Guide to handle the foundations of using the Arduino IDE in conjunction with the Geekduino.

Welcome to RobotGeek 101 : Pulse Width Modulation. This lesson will show you how to use PWM to fade an LED. The following video for this lesson will walk you through everything you need to do to get started with PWM.

Parts used in this lesson:

These parts and everything you need to complete chapters 1-7 in RobotGeek 101 are available in the RobotGeek Basic Experimenter's Kit.

Contents:

Introduction

Pulse Width Modulation (PWM) is a fancy way of saying turning a pin on and off at an incredibly fast, controlled rate. We are using a true Digital Output in a clever way that outputs different voltages using only the HIGH and LOW states. Depending on how long a pin is on or off, you can vary the amount of voltage that goes out to a device, approximating an Analog Output. Certainly interesting, useful for sure. To demonstrate this, we show how to fade an LED with PWM. For a better understanding of this concept, watch the video above, and follow along in the examples below.

Back to Contents

A-manualPWM

video.png Click here to expand the video

code.png Click here to expand the code

diagram.png Click here to expand the diagram

Let's use the Arduino IDE to set a PWM cycle using only delays. Open the following sketch in your Arduino IDE

File > Sketchbook > RobotGeek sketches > RG101 > 04 - PWM > A-manualPWM

Back to Contents

A2-hardwarePWM

video.png Click here to expand the video

code.png Click here to expand the code

diagram.png Click here to expand the diagram

Let's use the Arduino IDE to set a PWM cycle analgoWrite(). Open the following sketch in your Arduino IDE

File > Sketchbook > RobotGeek sketches > RG101 > 04 - PWM > A2-hardwarePWM

Back to Contents

B-fadeUp

video.png Click here to expand the video

code.png Click here to expand the code

diagram.png Click here to expand the diagram

Let's use the Arduino IDE to fade an LED using Pulse-width modulation. Open the following sketch in your Arduino IDE

File > Sketchbook > RobotGeek sketches > RG101 > 04 - PWM > B-fadeUp

Back to Contents

C-analogInPWMOut

video.png Click here to expand the video

code.png Click here to expand the code

diagram.png Click here to expand the diagram

Let's use the Arduino IDE to set the brightness of an LED based on an analog input. Open the following sketch in your Arduino IDE

File > Sketchbook > RobotGeek sketches > RG101 > 04 - PWM > C-analogInPWMOut

Back to Contents

D-analogInPWMOutSerial

video.png Click here to expand the video

code.png Click here to expand the code

diagram.png Click here to expand the diagram

Let's use the Arduino IDE to set the brightness of an LED based on analog input, as well as output the values to the serial port. Open the following sketch in your Arduino IDE

File > Sketchbook > RobotGeek sketches > RG101 > 04 - PWM > D-analogInPWMOutSerial

Back to Contents

PWM Reference

Now that you've completed the RG101 PWM Introduction, you're ready to go onto the next topic : 7.1 Servo Centering .

If you are interested in learning more about PWM, check out our PWM Reference Lesson. In this lesson we will look at the remaining RG101 examples and provide you with links to advanced PWM topics.

Back to Contents

Feedback Form


Search