// zoomkat 10-14-11 serial servo test
// use a microseconds value like 1500 in serial monitor
// for IDE 0022 and later
// Powering a servo from the arduino usually DOES NOT WORK.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(115200);
myservo.attach(10); //the pin for the servo control
Serial.println("servo-test-22"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); // allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
myservo.writeMicroseconds(readString.toInt()); //convert readString to number for servo
readString=""; //empty for next input
}
}
El servomotor puesto en referencia no deja de girar en una sola direccion. No importa el valor entrado en el puerto Serial.
La alimentacion del servomotor es ELI-2500 de Steren. Comparto el ground con el arduino. Lo tengo sobre 6V. El PWM usado es el 10.
No entiendo lo que estoy haciendo mal. Alguien ya a logrado usar ese mismo servomotor ?
Hi,
Segun las especificaciones del fabricante dicen que el voltaje del servo es de 3 a 6 voltios. Dices que lo alimentas con un voltaje sobre los 6 voltios. Cuanto mas de los 6 voltios lo estas alimentando. Otra cosa que arduino usas pues hay varios modelos.Segundo ceo que ese sketch no es correcto. Adjunto un sketch para que lo corras para ver si te trabaja.Tienes que cambiar el pin que tu estas usando.
[code]
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Una cosa es el código y otra el pin utilizado.
Tu código luce como mínimo raro, porque debieras usar directamente esto
String inString = ""; // string to hold input
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// send an intro:
Serial.println("\n\nString toInt():");
Serial.println();
}
void loop() {
// Read serial input:
while (Serial.available() > 0) {
int inChar = Serial.read();
if (isDigit(inChar)) {
// convert the incoming byte to a char and add it to the string:
inString += (char)inChar;
}
// if you get a newline, print the string, then the string's value:
if (inChar == '\n') {
Serial.print("Value:");
Serial.println(inString.toInt());
Serial.print("String: ");
Serial.println(inString);
// clear the string for new input:
inString = "";
}
}
}
Ahi leerás un entero y con dicho entero lo vuelcas a la posición del Servo.
Los pines del UNO con PWM son 3, 5, 6, 9, 10, 11 de modo que nada cambia entre usar 9 o 10. Seguirá funcionando.