Program works well with USB or battery powering but works incorrctly with 9V DC

Hello, I have created a simple program - to give LED signal feedback which depends on the status of an imput switch. i have uploaded the program to an Arduino UNO + breadboard (for the LEDs and swithch). It works well while the Arduino is powered by the USB port as well it works well while the Arduino is powered by external 9V battery. BUT the program works incorrectly while I power up the Arduino by an external 9V DC adapter - the LEDs are flashing independently from the status of the imput switch.
Could you give me advice why and how does the power supply influence the running of a program?
I can send pictures about the wiring as well I can send the program to check.

Do you have a multimeter to confirm that 9V is holding up?

Try a capacitor (at least 1000uF) across the 9V supply to smooth-out any noise. Sometimes those "battery eliminators" are poorly filtered.

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 are cheap on eBay so these can be fed into the USB connector or 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.

If powering from batteries, as long as the battery pack cannot exceed 5.5 V, this must be connected to the 5 V pin.

Thanks for the answer. This might be the problem. After some trials now the same program works incorrectly - from all type of power supply. It seems that something went wrong (burned) on the Arduino panel. In this case the Arduino panel itself could be damaged or the ATMEGA328 chip (I can change this chip if it helps).

By the way:

  • the battery had cca 8,8 V
  • the external DC adapter had cca 9,2 V
  • by the technical datasheet the recommended input voltage is 7-12 V (limits are between 6-20 V).
    I wouldn't think that this power supply could cause problem.

Paul__B:
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 are cheap on eBay so these can be fed into the USB connector or 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.

If powering from batteries, as long as the battery pack cannot exceed 5.5 V, this must be connected to the 5 V pin.

I've designed many systems with 12Vdc supplying the Vin pin and never had an issue. The issue comes when adding additional circuitry to it. That being said, the onboard regulator will drive an led and a switch (assuming the switch isn't a straight short) just fine.

I'm suspecting there was no common ground, or the supply has large variations in voltage, or it was connected in reverse polarity and fried the UNO.