Serial port freezes.

Hello,
I have some simple hardware circuit which looks like:

5VDC-->resistor(150)--->(button switch)--->

from button there are 3 ways

  1. --->resistor(10k)--->GND
  2. ---> LED DIODE-->GND
  3. ---> resistor(100)--->ArduinoPIn(x) on Pro Micro

In setup i doing what i must so:
I setup my Serial Port to open connection with computer.
I setup my ArduinoPin(x) as a digital INPUT. (pinMode(x, INPUT):wink:

My LOOP CODE

void loop() {
 if(digitalRead(x) == HIGH)
 {
     Serial.println("IS ON");
 } else {
     Serial.println("IS OFF");
 }
 delay(250);
}

Till i don't push my switchButtonON this code works great. I just got on Serial monitor "IS OFF" strings. But when i start pushing ButtonON Serial port hangs after a random times just in moment when button is pushed. Arduino still works but communication not.
I know that Arduino works because when i connect this to diode on otherPin then diode is blinking when i push my buttonSwitch.

I must restart Arduino to get communication works again.

Where is a problem?

Is 'x' 0 or 1? Those are the serial port pins so you can't use them for digital I/O if you want to use Serial.

I try to use PIN number 3 or 7. Both same situation.

If you are using serial do not use pin 0 or 1, I think we are ok there.

I'm wondering about your switch wiring, have a look here;

What you are building is actually this;

When I have problems, I usually create a new simple sketch to work on one problem at a time off to the side then when I figure it out I come back to the main program and keep on going. Do the button first then try DigitalReadSerial after.

Good luck and get back to us.

ok, lets do that.
So real view of that circuit looks like that:

LINK TO FULL IMG

and when i put 230v on left side of circuit the serial communication die after 1-10 tries. Arduino Pin work in that time in digital mode.

Alguien me podría ayudar?
Conecte mi arduino a mi pc y todo trabajaba normal, de repente perd√≠ mi conexi√≥n y en ning√ļn puerto usb me reconoce el arduino ni en ningun otro pc
Es un arduino leonardo
Cada vez que lo conecto me dice que no me reconoce el dispositivo usb y en la placa de arduino los leds indicadores me mantienen encendidos el de ON el de L, el de TX se mantiene apagado y el de RX parpadea y despues se mantiene encedido
Quisiera saber mi arduino se quemó o si se desconfiguró y quisiera tambien saber si me podrian decir si hay alguna manera que pudiera resolver este problema.
Gracias