Netduino Pulse-Width-Modulation LED Project
About the project
Try Netduino.Foundation, a powerful platform to build connected things quickly and easily with the.NetMicroFramework and Netduino.
Project info
Difficulty: Easy
Platforms: Microsoft, Netduino
Estimated time: 1 hour
License: GNU General Public License, version 3 or later (GPL3+)
Items used in this project
Hardware components
Story
This project shows you how to control the brightness of a generic LED using Pulse Width Modulation. We'll use the Pulse Width Modulation library included in Netduino.Foundation to make driving an LED quick and easy.
Pulse With Modulation is a way of controlling voltage digitally to emulate an analog signal. Netduino boards generate this signal as a square wave. The two key parameters under the control of the developer are the frequency and duty cycle. You can read more here.
![](https://www.electromaker.io/uploads/images/projects/332/story/medium/Wilderness_Labs_story_image_1525395170290138.jpeg)
In the above diagram, the time where the signal is high is the same as the time where the signal is low. The percentage of time the signal is on (high) is called the duty cycle. So, in the above, the signal is high 50% of the one cycle and so the duty cycle is 50%.
Netduino.Foundation is a platform for quickly and easily build connected things using the.NET MicroFramework on Netduino. Created by Wilderness Labs, it's completely open source and maintained by the Netduino community.
If you're new in Netduino development, I suggest you go to the Getting started with Netduino project to properly set up your development environment.
Assemble the circuit
For this project, simply connect the LED's cathode (short pin) to the GND, and the anode (long pin) to the pin 11 on your Netduino.
![](https://www.electromaker.io/uploads/images/projects/332/story/medium/Wilderness_Labs_story_image_1525395170750190.png)
Create a Netduino project
Create a Netduino project in Visual Studio 2015 for Windows or the latest Visual Studio for Mac; name the project PwmLed.
Add the Netduino.Foundation NuGet Package
Windows
Right-click on your PwmLed project and click Manage Nuget Packages . In the Browse tab, search for Netduino.Foundation; it should be the first search result. Click the Install button.
![](https://www.electromaker.io/uploads/images/projects/332/story/medium/Wilderness_Labs_story_image_1525395171692774.jpeg)
Adding Netduino.Foundation nuget package
MacOS
Alt-click on your PwmLed project in the Solution Explorer , and click Add => Add Nuget Package to open the NuGet Package window. Search for the Netduino.Foundation package and click Add Package to add it to your project.
![](https://www.electromaker.io/uploads/images/projects/332/story/medium/Wilderness_Labs_story_image_1525395172958359.png)
Adding Netduino.Foundation nuget package
Control the LED
You'll use the Pulse Width Modulation library contained in Netduino.Foundation to control the brightness of your LED. Add the Netduino.Foundation namepace: add a using statement for SecretLabs.NETMF.Hardware.Netduino. The code below uses an Alias named N.
In the Main method, create a new PwmLed object named pwdLed. In the constructor, specify the pin you're using to control the LED (pin 11) and the color of the LED (to select an appropriate voltage).
Using pwmLed, you can now invoke different APIs to light up your LED, such as StartBlink, StartPulse, or SetBrightness. These methods include parameters to control the LED behavior such as duration, high brightness and low brightness.
using System.Threading;
using N = SecretLabs.NETMF.Hardware.Netduino;
using Netduino.Foundation.LEDs;
namespace Blinky
{
public class Program
{
public static void Main()
{
var pwmLed = new PwmLed
(
N.PWMChannels.PWM_PIN_D11,
TypicalForwardVoltage.Green
);
// pulse the LED
pwmLed.StartPulse();
// keep the app running
Thread.Sleep(Timeout.Infinite);
}
}
}
Run the project
Click the run button in Visual Studio to see your LED pulse! It should be similar to the following gif:
![](https://www.electromaker.io/uploads/images/projects/332/story/medium/Wilderness_Labs_story_image_1525395207597870.gif)
White LED in a Pulse animation with PWM
Check out Netduino.Foundation!
This project is only the tip of the iceberg in terms of the extensive exciting things you can do with Netduino.Foundation.
-
It comes with a Huge Peripheral Driver Library with drivers for the most common sensors and peripherals available in the market.
-
All the peripheral drivers are simplified with built-in functionality, exposed by a clean, modern API.
- This project is backed by a growing community that is constantly working on building cool connected things and always excited to help new-comers and discuss new projects.
Leave your feedback...