Serial.begin (9600) prevents my led script from running

I have a simple script that lights up some strip leds - the script runs without any issues until I add the following lines in setup:

Serial.begin(9600);
EEBlue.begin(9600);

One I put that in, the strip LED’s don’t light up anymore - if I take it out, it runs fine.

I have that in there because I’m planning on doing some bluetooth work and need it to communicate with the HC-05 bluetooth unit.

Any idea why this is happening and how I can fix?

Here’s the whole code if it helps:

char val; // variable to receive data from the serial port
#include <Adafruit_NeoPixel.h>
#include <EEPROM.h>
#define NUM_LEDS 16
#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
#include <SoftwareSerial.h>
SoftwareSerial EEBlue(10,9); // RX | TX
const byte ledPin = 13;  // built in led
byte selectedEffect=0;

void setup() {
  
    
    strip.begin();
  strip.show();
Serial.begin(9600);
EEBlue.begin(9600);  //Default Baud for comm, it may be different for your Module.*/
   Serial.println("The bluetooth gates are open.\n Connect to HC-05 from any other bluetooth device with 1234 as pairing key!.");
}
void loop() {
Fire(55,120,15); 
   showStrip();   


//Reads the values coming from the bluetooth
 if (EEBlue.available())  // if a byte is available from BT
   {
      val = (EEBlue.read());  // val = byte read from BT
      Serial.print("[");
      Serial.print(val);
      Serial.println("]");
}

}


void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_LEDS];
  int cooldown;
  
  // Step 1.  Cool down every cell a little
  for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
    
    if(cooldown>heat[i]) {
      heat[i]=0;
    } else {
      heat[i]=heat[i]-cooldown;
    }
  }
  
  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for( int k= NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
  }
    
  // Step 3.  Randomly ignite new 'sparks' near the bottom
  if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
  }

  // Step 4.  Convert heat to LED colors
  for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }

  showStrip();
  delay(SpeedDelay);
}

void setPixelHeatColor (int Pixel, byte temperature) {
  // Scale 'heat' down from 0-255 to 0-191
  byte t192 = round((temperature/255.0)*191);
 
  // calculate ramp up from
  byte heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252
 
  // figure out which third of the spectrum we're in:
  if( t192 > 0x80) {                     // hottest
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) {             // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else {                               // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}





// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H 
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }}

  //off

#define PIN 0

Pin 0 if you are using a UNO is reserved for Serial comms.

Change it if you want to used serial and see if your code works.

Yeah you have already defined PIN as 0 which is RX of hardware serial. Change PIN to 2 and check it out.

IF it doesn't work then create another software serial for your bluetooth module at pins 3 and 4. Software Serial will work fine.

jackthom41:
IF it doesn’t work then create another software serial for your bluetooth module at pins 3 and 4. Software Serial will work fine.

Keep in mind that for sending a ledstrip signal, your interrupts will be turned off and since both swSerial & hwSerial do depend on it, in communication you may lose bytes and a blocking reception is recommended if you are trying to receive more then 1 byte at a time. (actually trying a non-blocking reception is just being silly)

Thank you, changing to Pin 2 worked

Deva_Rishi:
Keep in mind that for sending a ledstrip signal, your interrupts will be turned off and since both swSerial & hwSerial do depend on it, in communication you may lose bytes and a blocking reception is recommended if you are trying to receive more then 1 byte at a time. (actually trying a non-blocking reception is just being silly)

I have to make an extra note that if the time that it takes to transmit a complete frame of ledstrip signal is less than the time it takes to receive a complete byte, on HwSerial, even a non-blocking reception can work. iow if there is not to many leds and the BAUD rate is fairly low.