Should I use 1K resister for switch on arduino?

Hi all,

I know this is basic question but not sure if I did it right? I use the switch as picture shown below. Do I need to connect 1K ohm in digital pin in order to get digitalread() "1" or "0" in result?

IMAG1226.jpg

The result I got looks funny. I have 3 of those switchs in MEGA board. The result seems delay or sometime it trigger the pin beside it as well. It's a bit hard to debug unstable result. Hope anyone could help me. Thanks!

If you wire this switch to

If you wire this switch to ground so that it connects one pin to ground when activated and disconnects it when not activated then you can use the internal pull ups

 

#define switch (pin# goes here)

void setup(){

pinMode(switch, INPUT);

digitalWrite(switch, HIGH);

}

 

Now the switch should read “1” when not activated and “0” when activated. 

Interesting! it works~~~

Interesting! it works~~~ thanks!!