PWM Motor Control
In the Analog Outputs tutorial, we mentioned that PWM is particularly useful for controlling motor speed. We will now put this into practice using the Motor_Control_MX1508 example, which drives a small DC motor with an MX1508 dual H-bridge driver.
What You'll Need
- A board supported by Node Blue (the example uses the ElectroSeed SamD21 WB)
- An MX1508 motor driver module (or any other H-bridge driver that accepts a PWM input — see below)
- A small DC motor (typically 3–6 V)
- An external power supply for the motor if needed
If you use the ElectroSeed Tiny Pedal Board, no external motor driver module is needed — the board already integrates a dual H-bridge with 4 half-bridges, capable of driving two DC motors independently. Simply connect your motors directly to the board's motor output pins.
The MX1508 — and Other Compatible Drivers
The MX1508 is a compact dual H-bridge motor driver. Each channel has two input pins (IN1/IN2 for motor A, IN3/IN4 for motor B) and two output pins that connect directly to the motor terminals.
By applying a PWM signal to one input and holding the other LOW, you control both the speed and the direction of the motor:
| IN1 | IN2 | Motor A |
|---|---|---|
| PWM | LOW | Forward at variable speed |
| LOW | PWM | Reverse at variable speed |
| HIGH | HIGH | Braking |
| LOW | LOW | Free-wheeling (motor coasts) |
The example uses the MX1508, but the same principle applies to any H-bridge driver that accepts a PWM input — for example the L298N, the VNH5019, or any driver board with an EN (enable) or IN pin. Simply connect the PWM output pin of your board to the appropriate IN pin of your driver.
Loading the Example
In the Node Blue menu, click Open Example, then navigate to 05-Control → Motor_Control_MX1508 and click Open.
The project loads with two tabs: Flow 1 (the logic) and Wiring (the wiring diagram).
The Wiring Tab
Click on the Wiring tab. You should see the physical connections between the board, the MX1508, and the DC motor:

The board's PWM output pin (pin 12 in this example) connects to IN1 of the MX1508. The MX1508 outputs (OUT1, OUT2) connect to the two terminals of the DC motor. The MX1508 also requires a motor power supply and a shared GND with the board.
Connect your hardware according to this diagram before uploading the firmware.
Always disconnect the board from USB before making physical connections. Motors can draw significant current — make sure your power supply can deliver it. Never connect a motor directly to a microcontroller pin.
The 5V pin on the board comes directly from the USB port, which is limited to 500 mA on USB 2.0 ports (900 mA on USB 3.0). If your motor can draw more than that, you must power the motor driver from a dedicated external power supply rather than from the board's 5V pin. Only the GND should remain shared between the board and the external supply. Exceeding the USB current limit can damage your board or your computer's USB port.
The Flow Tab
Switch to the Flow 1 tab. You will see three modules: HID1, NodeBlueInterface, and AnalogOut1.

The Analog Out Module
Open the AnalogOut1 properties (click on the module to show them in the sidebar). Notice three key settings:

- Pin: the PWM output pin connected to IN1 of the MX1508 (pin 12 in the example)
- Resolution: 11 bits — this gives 2048 speed levels (0 to 2047) for very smooth control
- Frequency: 23437.5 Hz — intentionally set above the 20 kHz human hearing threshold, so the motor runs silently
On the ElectroSeed SamD21 WB, 23437.5 Hz is obtained by dividing the 48 MHz clock by 2¹¹ (2048). This is why 11-bit resolution and 23437.5 Hz go hand in hand on this board.
Under the hood, the Analog Out module uses the hardware PWM peripheral of the microcontroller when connected to a digital pin that supports it. This is the same analogWrite() mechanism used in the Arduino environment.
Do not use the Analog Out module on pins that have a real DAC (Digital-to-Analog Converter). On boards like the ElectroSeed SamD21 WB, some pins are labeled A0 and have a true DAC output. These pins should only be used with a dedicated DAC module, not with Analog Out. Driving a DAC pin with a PWM signal will produce incorrect results.
The PWM Module — an Alternative with More Options
Node Blue also provides a dedicated PWM module (found in the Output group). It uses the same hardware PWM peripheral as Analog Out, but offers additional modes useful in advanced motor control scenarios:
- Complementary PWM: generates two opposite PWM signals on two pins simultaneously, which is required by some gate drivers and H-bridge ICs.
- PWM + Dir: generates a single PWM signal together with a separate direction signal, which is the control scheme used by drivers like the VNH5019.
- Synchronized PWM: lets you synchronize the PWM signal across several output pins so that they all switch at exactly the same moment.
For simple speed control with a driver like the MX1508, the Analog Out module is the easiest choice. Switch to the PWM module when your driver requires one of these more advanced configurations.
The HID and NodeBlueInterface Modules
We will cover the HID and NodeBlueInterface modules in detail in a later tutorial. For now, just know that they establish a real-time USB link between the Node Blue GUI and your board. This link enables a very practical feature: when the AnalogOut1 input is not connected to anything in the flow, you can click directly on it in the Node Blue interface to open a slider and control the motor speed live — without uploading new code.

Uploading and Testing
Upload the project. Once the board is programmed:
- Keep the USB cable connected.
- In the Node Blue GUI, click on the input of the AnalogOut1 module. A slider appears.
- Move the slider — the motor speed changes in real time.
This direct control is very practical for testing and tuning without having to upload new code each time.
Going Further
Once you have confirmed that everything works, you can replace the live slider with any module that generates a value:
- Analog In (reading a potentiometer) for manual speed control
- Generator (Sine or other waveform) to automate speed cycles
- Any other signal source in your flow