PWM - Arduino Nano 33 BLE Rev 2: Not working

Hello!

Relatively new to the Arduino ecosystem here. I'm working on a project using an Arduino Nano 3 BLE Rev2 driving a series of IRLZ44N MOSFET transistors which are switching on and off groups of LEDs (66 LEDs in total). The desired result is a form of the Larson Scanner, except without the bounce - I want the "wave" to go in one direction only, then start over at the beginning.

I have all this wired up on bread boards and, with the help of Microsoft Copilot, managed to create a software-driven PWM solution that pretty closely looks like what I envisioned it.

However, during my development process I noted that PWM only works when I'm powering 4 pins. When I add the fifth, the whole system breaks and I have to use the bootloader mode to recover the Arduino. I have done lots and lots of debugging on this - using different pins, different hardware, adjusting the code, etc. It seems to be a limitation in the Arduino itself. Is this true?

For reference, I'm using the digital pins D2, D3, D4, D5, D6, D9, D10, D11 and D12. I have set the system up to be powered by two 9V batteries in parallel - one 9V powering the Arduino, the other powering the LEDs / MOSFETs with a common ground. (I don't have a schematic yet as I'm also trying to learn to use Fritzing). I have 10K Ohm pull-down resistors between the gate pins of the MOSFETs and ground, 2K Ohm resistor between the gate pins of the MOSFETs and the digital pins of the Arduino and a 220 Ohm resistor on the long legs of each group of three LEDs. Six MOSFETs are driving three groups of three LEDs and three MOSFETs are driving two groups of three LEDs.

Here is the code I have to trying to do the dimming with PWM - this code does NOT work on the setup unless I only have 4 MOSFET's connected to the Arduino.

// Sequential LED Lighting with Dimming - Arduino Nano 33 BLE Rev2

const byte pins[] = {2, 3, 4, 5, 6, 9, 10, 11, 12}; // LED pins
const byte numPins = sizeof(pins);                  // Number of LEDs/pins
byte brightness[numPins] = {0};                     // Brightness levels for LEDs
const byte dimmingStep = 51;                        // 20% dimming per step (255/5)
const unsigned long delayTime = 200;                // Delay between steps (ms)

void setup() {
  // Set all pins as outputs and initialize brightness to 0
  for (byte i = 0; i < numPins; i++) {
    pinMode(pins[i], OUTPUT);
    analogWrite(pins[i], brightness[i]); // Initialize all LEDs to off
  }
}

void loop() {
  // Sequentially light up LEDs with dimming
  for (byte currentLED = 0; currentLED < numPins; currentLED++) {
    // Update brightness for the current LED
    brightness[currentLED] = 255; // Set current LED to full brightness

    // Gradually dim previous LEDs
    for (byte i = 0; i < currentLED; i++) {
      if (brightness[i] > 0) {
        brightness[i] -= dimmingStep; // Reduce brightness by 20%
        if (brightness[i] < 0) brightness[i] = 0; // Ensure it doesn't go negative
      }
    }

    // Apply brightness levels to all LEDs
    updateLEDs();
    delay(delayTime);
  }

  // Reset all LEDs to off once the sequence finishes
  for (byte i = 0; i < numPins; i++) {
    brightness[i] = 0;
  }
  updateLEDs();
}

void updateLEDs() {
  // Write the brightness levels to each pin
  for (byte i = 0; i < numPins; i++) {
    analogWrite(pins[i], brightness[i]);
  }
}

Just open the tech specs:

PWM Pins All digital pins (4 at once)

So that's the best that board can do.
Whatabout using addressable LEDs, WS2812B ?

Hey, thanks! I don't know where you saw that - I've been using Arduino Nano 33 BLE Rev2 datasheet and could not find that limitation there. But when I look at the datasheet for the chip itself, I do (now) see "4x 4-channel pulse width modulator (PWM) unit with EasyDMA".

So that answers my question.

I'm unfamiliar with the addressable LEDs - but when I look at the form factor for WS2812B, I see they're not compatible for the effect I'm going for.

Thanks for the information! Very helpful!

I don't know what you mean with form factor.

My project is to use 1.8mm / 2mm Round Top Red LED - Ultra Bright LEDs in a Warhammer 40K model to replace "dome shaped" details in the model. I need the dome to maintain the effect. I have a software solution, that's been tested on breadboards, that I'm 99% happy with. :slight_smile:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.