Sketch stops working when switching to external power supply

I am relatively new at this but pretty decent with electronics and troubleshooting. Kids and I building a rig to control a solar hot water pump based on sunshine/no sunshine. It works beautifly when plugged into USB power. as soon as i plug in the accessory power unit, it stops working (if USB is plugged in or not).

we are pretty excited to have started from scratch on this and have it working, but now hit a wall. Any help would be appreciated!

The power supply is 9v 1500ma, bought for this purpose. All of the board, relay and light resistor unit LEDs come on as expected when it is plugged in. but the actions stop working. I tried commenting out the serial print functions and anything related to the computer connection but still no luck. (side questions, do I need to do that if not using a computer for final implementation?)

yes, read the FAQ on the topic and tried both solutions

Using an Uno I bought a few years back. I have tried the reset button also.

The code below has the serial/computer stuff commented out but same issue when it wasn’t.

Thanks!

-Damon

int light = 0; // store the current light value

void setup() {
    // put your setup code here, to run once:
    //Serial.begin(9600); //configure serial to talk to computer
    pinMode(6, OUTPUT); // configure digital pin 6 as an output
    pinMode(7, OUTPUT); // configure digital pin 7 as an output
}

void loop() {
    // put your main code here, to run repeatedly:
    light = analogRead(A0); // read and save value from PR
    
    //Serial.println(light); // print current light value
 
    if(light < 9) { // If it is direct sun...
        //Serial.println("Run pump!");
        digitalWrite(6,HIGH); //Turn on pump!
        digitalWrite(7,HIGH); //turn on LED
    }
    
    else { // If it's cloudy or dark...
        //Serial.println("Turn off pump!");
        digitalWrite(6,LOW); // Turn off pump
        digitalWrite(7,LOW); //turn off LED
    }
    delay(1000); // don't spam the computer!
}

Anyone have ideas here? This has been a fun projects to do w my kids but feels like we will have to abandon it if I can’t get the board to work independent of USB power.... I will try to find another power supply, but with LEDs all it up and things looking as they should I don’t expect that to help.

Would love to hear ideas on how to resolve it! Thanks!

Assumption: you connected the 9V to either the barrel jack or the Vin, not to the 5V.

What happens when it is connected like that? Does the power led come on? Is there 5V on the 5V pin? Is there 3.3V on the 3.3V pin.

Relays draw a lot of current. Assumption: the power for the relays is directly connected to the 5V pin of the Arduino.

In which case you might be overloading the onboard voltage regulator. It would be advised that their power is independent of the Arduino.
Side note: please provide a link to the relays. If they are not relay boards, please provide a schematic (photo of hand-drawn one will be fine); all wiring must be there including power etc.

Awesome, thank you.

Got it working! Your suggestion of external power source did the trick. I then gave more thought and gave the relay (a HiLetgo relay with a board made for Arduino stuf) exclusive access to the Uno's 5v pin and it worked. One thing I realized I needed to do with the independent power source was also grounding the relay back to the Arduino.

Anyway, thanks again for getting me unstuck.

Damon

One thing I realized I needed to do with the independent power source was also grounding the relay back to the Arduino.

That depends on the relay board. The HiLetGo side is terribly slow so I can't check. Well designed boards with optocouplers don't have that requirement; they have a JD/Vcc jumper.

5V from Arduino to relay board, 'activation' pin back to Arduino.
2)
5V from independent power source to relay coil, other side of relay coil back to GND of independent power source.