1
\$\begingroup\$

I'm new to Arduino and I have following problem:

I tried to control a servo with two buttons (left, right) and it worked perfectly. But today I tried to do the same but with some additional LED feedback. (if going left, left LED. If right, right LED)

I connected everything how it should be, but now every time I power the board the left LED is going on and off very quickly and the servo is going to the left. (I'm not pressing anything)

I disconnected the wire, going from the pin(Arduino) to the pinboard. But it's still the same thing happening. (a simple wire without anything on it connected to the Arduino and its telling me that I push the button ?)

I disconnected the LEDs, the servo and the right button and wrote an program to tell me if the button is pushed(1) or not(0). So I can see whats going on.

int pushButton = 2;

void setup() {
  Serial.begin(9600);
  pinMode(pushButton, INPUT);
}
void loop() {
  int buttonState = digitalRead(pushButton);
  Serial.println(buttonState);
  delay(5);
}

It's showing me exactly the same that the LED showed me. Like i would press the Button very quickly a several times per second.

Left Button = Pin2, Right Button = Pin3, Left LED = Pin4, Right LED = Pin5, Servo = Pin13. (all digital of course)

I used 330 Ohms for the LED and 10K Ohm for the Buttons. Everything is connected to the 5V.

The Arduino UNO is connected via USB to my laptop and to an Additional 9V for the Servo.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
2
  • 1
    \$\begingroup\$ A schematic would confirm this but I suspect you are having issues leaving your inputs floating. Try using the internal pull up resistors and have your button short the pin to ground. \$\endgroup\$
    – user28726
    Feb 10, 2014 at 12:51
  • \$\begingroup\$ I agree with @DanNixon. But you do mention using 10K resistors with the buttons. These should be used as pull-up or pull-down (reverse logic). Sparkfun has a nice tutorial. If we're off, please include the schematic. \$\endgroup\$
    – ltj
    Feb 10, 2014 at 13:42

1 Answer 1

1
\$\begingroup\$

Due to the internal pull-ups (and the explicit pull-ups in your schematic), 1 means unpushed and a 0 from tying the input to ground through a button means pushed. Your logic is reversed.

\$\endgroup\$
2
  • \$\begingroup\$ thanks.. i figured out that the button was defect. so sometimes i got wrong signal from it. Stupidest thing to be defect.. i spent a lot on finding the mistake. Thanks to everyone who helped \$\endgroup\$
    – progger
    Feb 19, 2014 at 17:53
  • \$\begingroup\$ Life's too short for wonky buttons. \$\endgroup\$ Feb 19, 2014 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.