Let's Make Robots!

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?

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!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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~~~ thanks!!