Arduino Uno doesn't start sketch when it it disconnected from USB

I have written a sketch, an all is function well.
But when i disconnect the USB cable, and put it on later, the sketch doesn’t work.
I have to upload the sketch again, and then it is working again.

Is this an error in my sketch or must i do something else to correct this problem?

I have connected the RX pin with a resistor to ground but doesn’t work.
Also connected the RX and TX pin

Does it work after you press the reset button?

Perhaps if you show your sketch we can figure out why it might be getting stuck.

What model of Arduino are you running on?

Even when i press the reset button, the arduino doesn’t start.

#include <SPI.h>
#include "hsv2rgb.h"

const int ShiftPWM_latchPin=8;
const bool ShiftPWM_invertOutputs = 0; // if invertOutputs is 1, outputs will be active low. Usefull for common anode RGB led's.

#include <ShiftPWM.h>   // include ShiftPWM.h after setting the pins!

int potPin = 0; // Potentiometer output connected to analog pin 0
int buttonPin = 2;  // Butto output connected to digital pin 2

unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
unsigned char red, green, blue;
int numRegisters = 3;
int buttonState = 0;         
int hue;
int val = 15;
int sat = 255;
int potValHue = 0; // Variable to store the input from the potentiometer
int delbright = 2; // delay of the brightnes in milliseconds
int delstrip = 300; // delay of the brightnes in milliseconds
 
void setup()   {                
  pinMode(ShiftPWM_latchPin, OUTPUT);  
  pinMode(buttonPin, INPUT);     
  
  SPI.setBitOrder(LSBFIRST);
  // SPI_CLOCK_DIV2 is only a tiny bit faster in sending out the last byte. 
  // SPI transfer and calculations overlap for the other bytes.
  SPI.setClockDivider(SPI_CLOCK_DIV2); 
  SPI.begin(); 

  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.Start(pwmFrequency,maxBrightness);  
}



void loop()
{
  ShiftPWM.SetAll(0);
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {     
  rgbledup();
} 
  else {
    ShiftPWM.SetAll(0);
  }
  
}


void rgbledup()
{    
    for(int ledstrip=0; ledstrip<6; ledstrip++){
    hue = analogRead(potPin)/2.85; //Read the potentiometer, convert it to 0 - 360
      for(int brightnes=0; brightnes<255; brightnes++){
        hsv2rgb(hue, sat, val, &red, &green, &blue, brightnes); // convert hsv to rgb values
        ShiftPWM.SetGroupOf3(ledstrip, blue, green, red);
        delay(delbright);}  //delay of Brightnes
        delay(delstrip);} //delay between strips


    delay(1000); //delay between on and off


    for(int ledstrip=0; ledstrip<6; ledstrip++){
      for(int brightnes=255; brightnes>0; brightnes--){
        hsv2rgb(hue, sat, val, &red, &green, &blue, brightnes); // convert hsv to rgb values
        ShiftPWM.SetGroupOf3(ledstrip, blue, green, red);
        delay(delbright);}  //delay of Brightnes
        delay(delstrip);} //delay between strips
} 

void rgbleddown()
{    
    for(int ledstrip=6; ledstrip>0; ledstrip--){
    hue = analogRead(potPin)/2.85; //Read the potentiometer, convert it to 0 - 360
      for(int brightnes=0; brightnes<255; brightnes++){
        hsv2rgb(hue, sat, val, &red, &green, &blue, brightnes); // convert hsv to rgb values
        ShiftPWM.SetGroupOf3(ledstrip, blue, green, red);
        delay(delbright);}  //delay of Brightnes
        delay(delstrip);} //delay between strips


    delay(1000); //delay between on and off


    for(int ledstrip=6; ledstrip>0; ledstrip--){
      for(int brightnes=255; brightnes>0; brightnes--){
        hsv2rgb(hue, sat, val, &red, &green, &blue, brightnes); // convert hsv to rgb values
        ShiftPWM.SetGroupOf3(ledstrip, blue, green, red);
        delay(delbright);}  //delay of Brightnes
        delay(delstrip);} //delay between strips
}

This is the code i am using.
The Arduino is an Arduino Uno R3

I have an Uno R1 that does the same thing, but only with some sketches. If I load blink, it runs when powered, but with the TFT (adafruit) paint program, it will not start unless I reload it. Could it be a power drain problem? I had a similar one with a CSTAMP until I got a bigger power cube. What is connected to the Uno (any shields?). Maybe you should try a separate power supply. (I just remembered this and have not tried it on my Uno)

I have build the Photoduino, and all was working properly.
Now i am building a starway lightning, and with this sketch i have this problem. other sketches are working great.

I use a seperate powersupply of 24VDC for powering the RGB Ledstrips.
I send the schematic of the electronics with this reply.

Does nobody know what the problem can be? :astonished:

The problem only happens with this particular sketch? Does it still happen if you disconnect everything from the board but try the same sketch (if you can tell)? It sounds like the components you're trying to drive are using too much power when they all get turned on at once. You might need more capacitors or a better power supply, or separate ones for various parts of the circuit.

So far, it only happened with this sketch.

I don’t know when i disconnect everything of the sketch wil work, because i cannot see the Ledstrips lightning up.
The capicitors that are now in the schematic are not yet installed, because they are only for flickering.

The ledstrips are powered with an external powersupply of 24VDC

On this moment in experimental fase, the arduino is powering only 3 shiftregisters and 3 ULN2003 ic’s
I think that that must be possible.
But i shall try it with an external powersupply.

Just tried with an external power supply, but doesn't matter.
The sketch won't start.
when i upload the sketch again, then it all works again.

Somebody with another suggestion?

the arduino doesn't start with any sketch.

Can it be a bootloader problem?

Well than i guess it could be, Did you try to re-burn one?

Sounds like a power issue to me.