LED Blink

In this project, I will show you how to make a blinking LED. This is like a Hello World project for GPIO.

Hardware

Component List

  • Raspberry Pi 3 B+ x 1
  • GPIO Extension Board and GPIO Cable x 1 (If you do not have an Extension Board, connect Raspberry Pi and breadboard directly with jumper wires.)
  • Breadboard x 1
  • LED x 1
  • Resistor 220Ω x 1 (Check your LED specification for the correct resistor to use.)
  • Jumper Wire x 2

Schematic Diagram

Breadboard Diagram

Note that the longer leg of the LED needs to be connected to the positive. It is shown as bended leg in the diagram.

Program

Create a Console Project.

Add NuGet package Unosquare.Raspberry.IO.

Main Program: Program.cs

using Unosquare.RaspberryIO;
using Unosquare.RaspberryIO.Gpio;

...

GpioPin pin = Pi.Gpio.Pin25;    // pin 37, GPIO26
pin.PinMode = GpioPinDriveMode.Output;
bool onOff = true;

for (int i = 0; i < 10; i++)
{
    pin.Write(onOff);
    System.Threading.Thread.Sleep(500);
    onOff = !onOff;
}

Unosquare.Raspberry.IO uses the pin number the same as Wiring Pi. At Terminal, enter command gpio readall to see pin number mapping. Use the number in column wPi to address the pins.

Leave a Reply