Go Down

Topic: problem in getting the desired output (Read 2906 times) previous topic - next topic


Make your life simple and use the internal pullup.

Connect your push button like this picture:

And then change your code to:
Code: [Select]

int switchpin=8;
int led=13;

void setup()
  pinMode(switchpin,INPUT_PULLUP);  //enables internal pull-up resistor

void loop()
  boolean button=digitalRead(switchpin);
  digitalWrite(led, !button);
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up