Arduino still on

Hello .
I have Arduino mega and one of I/O digital pins (pin 33) is connected to an on/off switch .
When I turn off the Arduino ( unplug the Serial cable ) if the switch is off the Arduino turn off , and if the switch is on the Arduino does not turn off and stays on .
The on/off switch is connected to external 5V power supply an pull-up resistor .
please help .

The Arduino is getting "phantom power" from the IO pin, 5V is going thru the protection diode that is on each IO pin.

Post a diagram of how you have the switch and resistor connected. Perhaps a diode could be used to isolate the Arduino so that external power can be stopped.

What made you think that your question has anything to do with the working of this Website and Forum? I have suggested to the Moderator to move it to the Project Guidance section.

This sort of carelessness makes unnecessary work for the Moderators.

...R

Here is a simple diagram .
What causes this And Is there a way to solve this problem .
And does it dammege the Arduino .

Thank CrossRoads .

@moad_kahal

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future

I moved your post from the wrong section to its current location.

I will be thankful if u read my post and help me with my problem.
I'm new and this is my first post .

That's why I provided those links for you. :wink:

Simple way to prevent power from external is to use

pinMode (yourPin, INPUT_PULLUP);

and wire it like so and change the code to look for a Low.

if (digitalRead(yourPin) == LOW){
// button pressed, do something
}

Thank you CrossRoads that was very helpful .

But if I may ask for the reason that the Arduino still on .
And does it dammege the Arduino .
And how to overcome this phenomenal.

moad_kahal:
But if I may ask for the reason that the Arduino still on .

Crossroads explained that in post #1.

Chips can be easily damaged in transport, handling and storage by static electricity. To make them more durable, the chip designers include what are called "protection diodes" or "clamp diodes" to guide any ESD away from the most delicate parts of the chip. The side effect of these diodes is that the chip can then be "phantom powered" when in a circuit, if any of the chip's pins are at a higher voltage than the Vcc pin.

moad_kahal:
And does it dammege the Arduino .

Yes, it can cause damage and should be avoided. The chip's data sheet will specify that no input pin should be higher than Vcc by about 0.5V. In your circuit, the input pin can be 5V more than Vcc (which is zero).

moad_kahal:
And how to overcome this phenomenal.

Power the whole circuit from the same supply, so that the situation cannot happen. Where this is cannot be done, there are ways to isolate the two parts of the circuit that have separate power supplies, so that they are not electrically connected, such as using relays or opto-isolators.

Thank you everybody for all the useful information .