Remarks

Uln2003
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Motors.Stepper.Uln2003

ULN2003 is a high voltage, high current Darlington array containing seven open collector Darlington pairs. The ULN2003 is often packaged on board used to control stepper motors.

Code Example

Uln2003 stepperController;

public override Task Initialize()
{
    stepperController = new Uln2003(
        device: Device,
        pin1: Device.Pins.D01,
        pin2: Device.Pins.D02,
        pin3: Device.Pins.D03,
        pin4: Device.Pins.D04);

    return base.Initialize();
}

public override Task Run()
{
    stepperController.Step(1024);

    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Step forward {i}");
        stepperController.Step(50);
        Thread.Sleep(10);
    }

    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Step backwards {i}");
        stepperController.Step(-50);
        Thread.Sleep(10);
    }

    return base.Run();
}

Sample project(s) available on GitHub

Wiring Example

To wire a ULN2003 to your Meadow board, connect the following:

ULN2003 Meadow Pin
GND GND
VCC 3V3
INT1 D01
INT2 D02
INT3 D03
INT4 D04

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object > Uln2003
Namespace Meadow.Foundation.Motors.Stepper
Assembly Uln2003.dll

Syntax

public class Uln2003 : object

Constructors

Uln2003(IDigitalOutputController, IPin, IPin, IPin, IPin)

Initialize a Uln2003 class

Declaration
public Uln2003(IDigitalOutputController device, IPin pin1, IPin pin2, IPin pin3, IPin pin4)

Parameters

Type Name Description
IDigitalOutputController device

The digital input controller to create the output ports (usually Meadow)

IPin pin1

The GPIO pin number which corresponds pin A on ULN2003 driver board

IPin pin2

The GPIO pin number which corresponds pin B on ULN2003 driver board

IPin pin3

The GPIO pin number which corresponds pin C on ULN2003 driver board

IPin pin4

The GPIO pin number which corresponds pin D on ULN2003 driver board

Uln2003(IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort)

Initialize a Uln2003 class

Declaration
public Uln2003(IDigitalOutputPort outputPort1, IDigitalOutputPort outputPort2, IDigitalOutputPort outputPort3, IDigitalOutputPort outputPort4)

Parameters

Type Name Description
IDigitalOutputPort outputPort1

The output port for pin A on ULN2003 driver board

IDigitalOutputPort outputPort2

The output port for pin B on ULN2003 driver board

IDigitalOutputPort outputPort3

The output port for pin C on ULN2003 driver board

IDigitalOutputPort outputPort4

The output port for pin D on ULN2003 driver board

Properties

AngularVelocity

Sets the motor speed to revolutions per minute.

Declaration
public Units.AngularVelocity AngularVelocity { get; set; }

Property Value

Type Description
Units.AngularVelocity

Remarks

Default revolutions per minute for 28BYJ-48 is approximately 15.

Mode

Sets the stepper's mode.

Declaration
public Uln2003.StepperMode Mode { get; set; }

Property Value

Type Description
Uln2003.StepperMode

Methods

Step(Int32)

Moves the motor - If the number is negative, the motor moves in the reverse direction

Declaration
public void Step(int steps)

Parameters

Type Name Description
System.Int32 steps

Number of steps

Stop()

Stop the motor

Declaration
public void Stop()