Thunder and lightning project


This is my first post here, and perhaps you can help me.

Im trying to make a thunder and lightning simulation that combines, sound and a 12v led strip. The problem is that while sound seems to be working fine when the led strip isnt connected, when i connect the led strip, the whole thing stops working (sometimes the l light on the nano board stays on). If i disconnect the leds and i reset it, it goes on as it should (as long as the led strip is disconnected). If i connect a piece of led strip (5cm), it seems to work fine. How can i use a larger strip?

parts used:
Arduino nano
df player mini
micro sd card
mosfet 1xirfz44n
resistors 2x1k
led strip 12v 2.5m
power supply 12v 5A

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

int ledPin = 9;    // LEDs (via MOSFET) connected to pin 9
int rxPin = 10;    // DFplayer RX to Arduino pin 10
int txPin = 11;    // DFplayer TX toArduinopin 11
int busyPin = 12;  // DFplayer BUSY connected to pin 12

SoftwareSerial mySoftwareSerial(rxPin, txPin);
DFRobotDFPlayerMini myDFPlayer;

void setup()

  pinMode(ledPin, OUTPUT);
  pinMode(busyPin, INPUT);

  Serial.println(F("Initializing DFPlayer..."));

  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin. Check connection and SD card, or reset the Arduino."));
    while (true);

  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.setTimeOut(500);                   // Set serial communictaion time out 500ms
  myDFPlayer.volume(30);                        // Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_BASS);              // Set EQ to BASS (normal/pop/rock/jazz/classic/bass)
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);  // Set device we use SD as default
  myDFPlayer.enableDAC();                       // Enable On-chip DAC

void loop()
  int flashCount = random (3, 15);        // Min. and max. number of flashes each loop
  int flashBrightnessMin =  10;           // LED flash min. brightness (0-255)
  int flashBrightnessMax =  255;          // LED flash max. brightness (0-255)

  int flashDurationMin = 1;               // Min. duration of each seperate flash
  int flashDurationMax = 50;              // Max. duration of each seperate flash

  int nextFlashDelayMin = 1;              // Min, delay between each flash and the next
  int nextFlashDelayMax = 150;            // Max, delay between each flash and the next

  int thunderDelay = random (500, 3000);  // Min. and max. delay between flashing and playing sound
  int thunderFile = random (1, 17);       // There are 17 soundfiles: 0001.mp3 ... 0017.mp3
  int loopDelay = random (5000, 30000);   // Min. and max. delay between each loop

  Serial.print(F("Flashing, count: "));
  Serial.println( flashCount );

  for (int flash = 0 ; flash <= flashCount; flash += 1) { // Flashing LED strip in a loop, random count

    analogWrite(ledPin, random (flashBrightnessMin, flashBrightnessMax)); // Turn LED strip on, random brightness
    delay(random(flashDurationMin, flashDurationMax)); // Keep it tured on, random duration

    analogWrite(ledPin, 0); // Turn the LED strip off
    delay(random(nextFlashDelayMin, nextFlashDelayMax)); // Random delay before next flash

  Serial.print(F("Pausing before playing thunder sound, milliseconds: "));

  Serial.print(F("Playing thunder sound, file number: "));
  delay(1000); // Give the DFPlayer some time

  while (digitalRead(busyPin) == LOW) { // Wait for the DFPlayer to finish playing the MP3 file

  Serial.print(F("Pausing before next loop, milliseconds: "));


I'm guessing your LED strip is drawing too much power from you supply and that's browning out your arduino and causing some issues. How much current can your power supply give and are your LED's on full? If you hook it up to a different supply that would tell you if that was the problem, just make sure to keep all the ground from each supply connected. Make sure that your LED strip isn't shorted by checking for continuity or checking the diodes with a multi-meter. some good videos on Youtube about that if you need them.

Hooking the led strip up to a different power supply like you suggested, seems to make it work ok, but i wonder how can it be a power supply problem when the main power supply is 5A which should be more than enough.The led strip is about 2 meters and they are go on and off ranging from low to full depending on the sound.

I wonder how can it be a power supply problem when the main power supply is 5A which should be more than enough.

Is the power to the LED strip fed as shown in your photo? Through the entire length of the breadboard power strip? Those strips are not capable of carrying anything like 5A. Connect the LEDs directly to the PSU without going through the breadboard, this applies to both connections.

The clear blunder is not comprehending what the "Vin" or "RAW" terminal is. The regulator on the Arduino UNO/ Nano/ Pro Mini/ Mega2560/ Leonardo/ Pro Micro has very little heatsink, so will not pass very much current (depending on the input voltage and thus, how much voltage it has to drop) before it overheats and (hopefully reversibly) shuts down. It is essentially a novelty provided in the very beginning of the Arduino project when "9V" power packs were common and this was a practical way to power a lone Arduino board for initial demonstration purposes. And even then it was limited because an unloaded 9 V transformer-rectifier-capacitor supply would generally provide over 12 V which the regulator could barely handle.

Nowadays, 5 V regulated switchmode packs are arguably the most readily available in the form of "Phone chargers" and switchmode "buck" regulators to regulate down from 12 V or other available voltages are cheap on eBay so these can be fed into the USB connector or (more appropriately) 5 V pin to provide adequate power for most applications. Unfortunately, many tutorials or "instructables" are seriously outdated or misleading and have not been updated to reflect the contemporary situation.

In your case, you need a 5 V power supply for the Nano and your audio system, There is an anomaly in your wiring where you show two different ground connections. That also suggests part of the problem (if you thought you needed to decouple the audio supply from the LED supply, that is not the way to do it! :astonished: ).