Introduction: LinkIt One and PWM (Pulse Width Modulation)

About: Electronics have always been fascinating to me. Things that get my attention are clocks, lamps, motion activated devices, light activated devices, laser intruder alert systems,solar and wind power, voltage inv…

Welcome to my tutorial on the MediaTek LinkIt One and Pulse Width Modulation.

What is Pulse Width Modulation and what does it do?

The words Pulse Width Modulation are almost self explanatory. All it is an electrical signal that is pulsed (like your heart causes your blood to pulse) and can vary in width (length actually). Looking at an oscilloscope of a PWM signal shows a square wave. How wide that wave is determines the Pulse. The wider the wave the longer the pulse. This allows you to do many things, one of which is fade an LED up and down with a digital output. Digital is either on or off. A fading light is an analog function in that it is not on or off but bright, a little less bright, and then finally off (dark). You can also control motors with PWM making them run at variable speeds. Above is a picture of what an oscilloscope shows when a PWM signal is sent to it. For an in-depth explanation visit this link

Step 1: Setup

The LinkIt One has two PWM capable pins. Those are digital pins 3 and 9. Using PWM allows you to hook up an LED to either of those pins without using a current limiting resistor because the code allows you to control the brightness of the LED.

Take an LED and put the long lead (or leg) into the opening for digital pin 9 and the short LED lead into the ground pin opening 5 spots over. Spreading the leads for this distance is easy. That is all that is required!

Step 2: Upload Code

Upload the code to your LinkIt One and you will see the LED slowly fading off and on.

The sketch begins with the LED off as controlled by the line in the code - int brightness = 0;

Here is the code in the sketch that sets the number of increments it takes for the LED to go from off to full brightness. The higher the number the steps it will take to do that. - "int fadeAmount = 5;

This is the code that sets the maximum brightness of the LED at its brightest. -

if (brightness == 0 || brightness == 210) {
fadeAmount = -fadeAmount ;

If you change the number 210 to 50 the LED will be very dim at its brightest point in the cycle.

I've added a video of the LinkIt One running this code so you will know what to expect. If you decide to go much higher than the 210 be aware you might burn out your LED. But I think it will be safe to try because at 210 my LED is still petty dim so there is definitely room there to experiment.

I hope you enjoy trying some different settings in the code and that you've learned a little bit about PWM and the LinkIt One and this knowledge comes in handy someday when you're building a robot or something else exciting!