# Arduino servos (Spanish and English language)

**URL:** <https://forum.arduino.cc/t/arduino-servos-spanish-and-english-language/1109240>\
**Category:** General Electronics\
**Created:** [March 31, 2023, 12:17pm UTC](https://forum.arduino.cc/t/arduino-servos-spanish-and-english-language/1109240 "2023-03-31T12:17:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nounlag](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@nounlag](https://forum.arduino.cc/u/nounlag)\
**Post date:** [March 31, 2023, 12:17pm UTC](https://forum.arduino.cc/t/arduino-servos-spanish-and-english-language/1109240/1 "2023-03-31T12:17:30Z")

</div>

Guys how can i action a servo with only one button.  
The servo move 90° and after 1 second go back to the original state.  
Srry if my english is bad, my original lenguaje is spanish.  
//  
Chicos como puedo accionar un servomotor con un pulsador o boton,el servomotor se mueve 90 grados y despues retrocede y vuelve al estado original.

(Could anyone send me a schematic that matches with this code)

```cpp
#include <Servo.h> 

Servo myservo;

const int buttonPin = 2;
int val;
int buttonState = 0;

void setup() 
{ 
  myservo.attach(9);
  pinMode(buttonPin, INPUT);       
} 

void loop() 
{ 
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {     
    val = 90;  
  } 
  else {
    val = 0;
  }
  myservo.write(val);
  delay(15);
}

```

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [March 31, 2023, 9:51pm UTC](https://forum.arduino.cc/t/arduino-servos-spanish-and-english-language/1109240/2 "2023-03-31T21:51:35Z")

</div>

Hello @nounlag - Tu codigo necesita algunos cambios para hacer el boton y hacer un temporizador. Aquí está el código con los cambios:

(I made a mistake before... here is the better sketch)

```cpp
#include <Servo.h>
Servo myservo;
const int servoPin = 9;
const int buttonPin = 2;
int buttonState = 0;
int val;

unsigned long currentMillis; // "now" time
unsigned long previousMillis = 0; // "last" time
const long interval = 1000; // one second

void setup()
{
  myservo.attach(servoPin);
  pinMode(buttonPin, INPUT);
  myservo.write(0); // move servo to 0
}

void loop()
{
  buttonState = digitalRead(buttonPin); // read the button
  if (buttonState == HIGH) { // button was pushed
    myservo.write(90); // tell servo to move
    previousMillis = millis(); // set button press time
  }
  currentMillis = millis(); // now!
  if (currentMillis - previousMillis >= interval) { // difference of now and button press
    myservo.write(0); // move servo home
  }
}

```

And [here is a simulation link](https://wokwi.com/projects/360749608843812865). Press green "play" button to start, then red button to move servo.

---

<div class="post-metadata">

**Author:** ![JCA34F](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jca34f/32/340148_2.png) [@JCA34F](https://forum.arduino.cc/u/JCA34F)\
**Post date:** [March 31, 2023, 11:14pm UTC](https://forum.arduino.cc/t/arduino-servos-spanish-and-english-language/1109240/3 "2023-03-31T23:14:11Z")

</div>

Do you have a 10k pulldown resistor connected from pin 2 to GND?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 27, 2023, 11:14pm UTC](https://forum.arduino.cc/t/arduino-servos-spanish-and-english-language/1109240/4 "2023-09-27T23:14:42Z")

</div>

Closed on September 27, 2023, 11:14pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
