Connecting a switch to Arduino

This sketch is just a switch connected to Arduino Uno, the voltage is 3.3v, the LED act like a resistor (else the circuit will be short), pin 2 is the INPUT pin which tell the MCU if the switch is close(HIGH) or open(LOW).

The circuit is also connected to the serial monitor via pin 2. If the switch is close, the LED will light up and the serial monitor will record as 1.

switch is open
No data logging as switch is open
switch is closed, LED lights up.
switch is closed, serial monitor records the buttonState which is 1 (HIGH).

Also note that I have written 2 lines of code in the setup function, which is to off the pin 13 LED. This is optional.

changing the buttonState to 1 instead of HIGH (line 23) will also do the same job