Hey guys, so basically im doing this simple thing with the Arduino Uno, push button and 1 servo motor, the problem is that i just bought this push button and it isn't working properly. For example, when i pressed the button it doesn't do anything except when i push the button itself into the pins.
Here is my code:
- #include <Servo.h>;
- const int buttonPin = 12;
- Servo servoMotor;
- const int LED = 13;
- int buttonState = 0;
- void setup(){
- Serial.begin(9600);
- pinMode(buttonPin,INPUT_PULLUP);
- pinMode (LED,OUTPUT);
- servoMotor.attach(2);
- servoMotor.write(0);
- }
- void loop()
- {
- buttonState = digitalRead(buttonPin);
- if(buttonState == HIGH) {
- servoMotor.write(125);
- digitalWrite(LED,HIGH);
- delay(25);
- }
- else{
- servoMotor.write(0);
- digitalWrite(LED,LOW);
- delay(25);
- }
- }