Go Down

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

cmiyc

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
  pinMode(led,OUTPUT);
  digitalWrite(led,HIGH);
}

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