Arduino loose connection when using Rotary Encoder


I attempt to complete this tutorial: Digital Read Serial

It is a basic tutorial from the arduino uno.
Here is the link

Here is my issue:
When I boot my uno, it spills out a ton of ints in the serial monitor with values between about 200 - 550

This is weird as the rotary encoder is not being used yet.
When I rotate it it triggers a windows sound like if I plugged in a usb but with nothing else.
This stops the program right away with a final int in the log by example 44.

Finally to work again on the arduino I must disconnect it from the pc then reconnect it because even if it is displayed in my "Device Manager" I fail to upload the code.

Thanks for your help, I am really troubled by this.

Are you trying to read a potentiometer, or a rotary encoder? They are completely different things.

Assuming a potentiometer, it sounds like you have a loose connection. Solder one end of each of the three wires to the potentiometer terminals and make secure connections at the other end to the Arduino.

ok that might be the issue, im totally new to this and cant find the potentiometer at all in my starter kit, I guess I assumed they were the same. I figured that the piece I use now is a rotary encoder as I had to find why my potentiometer had 5 branch instead of 3...

Ill look harder for the potentiometer and give the feedback here after just to make sure everything is fine before closing.

The code is for a potentiometer, not for a rotary encoder (big difference).

You must connect the pin to the pot, otherwise the unconnected pin will result in random values from the A/D.
Make sure you connect the center pin of the pot to the analogue input, otherwise you could short out the 5volt USB supply (the windows sound?).

delay(1); makes the Arduino print every 1 millisecond (stupid).
Changing that to delay(250); or so will calm that down to four readings per second.

Ok to show the principle, but the code should have been written to only print when there is a change in value.

Great now I feel really bad for spending a few hours trying to make a rotary encoder work as a potentiometer...

Well problem solved and the tutorial got completed right away. Im closing this, sorry for the waste of time.