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]);
}
}

