18-11-2015, 03:42 PM
El código, perdón.
Proyecto
|
18-11-2015, 03:42 PM
El código, perdón.
18-11-2015, 11:56 PM
Puedes depende del tutorial que utilice un código distinto. Por ejemplo para este tutorial (http://androidcontrol.blogspot.com.es/20...ntrol.html) utilizo este código y pongo los cables según el diagrama de la página, pero no se si el problema es del servo que es el 9g azul de Ebay :
#include <Servo.h> Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position int motor = 0; void setup() { Serial.begin(9600); // initialize serial: myservo.attach(9); // attaches the servo on pin 9 to the servo object Serial.print("Arduino control Servo Motor Connected OK"); Serial.print('\n'); } void loop() { // if there's any serial available, read it: while (Serial.available() > 0) { // look for the next valid integer in the incoming serial stream: motor = Serial.parseInt(); // do it again: pos = Serial.parseInt(); // look for the newline. That's the end of your sentence: if (Serial.read() == '\n') { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position // print the three numbers in one string as hexadecimal: Serial.print("Data Response : "); Serial.print(motor, DEC); Serial.print(pos, DEC); } } } //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>=1; 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 //} //val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) //val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) //myservo.write(val); // sets the servo position according to the scaled value //delay(15);
Después del 9 pon 600 y 1500 así:
myservo.attach(9,600,1500); Recuerda que en el servo azul el amarillo tiene q ir al 9, el rojo a 5V y el negro/marrón a GND. Mira este video: https://www.youtube.com/watch?v=CGlIpfgqPMM Y el de las apps q te deje en anteriores respuestas; sii no te funciona la App te la puedes hacer tú mismo.
22-11-2015, 02:56 PM
el problema del video que me has pasado es que no explica como hacer eso mismo pero mediante el modulo BT y con una APP. Vi ese video y me sirvió para coger la idea de mover el servo con un potenciometro, cosa que ya hice y funciona perfectamente, el problema es cuando intento hacer funcionar el servo mediantel el BT. No encuentro la manera de que funcione y ya he visto varios tutoriales, no se si es algo que estoy haciendo mal o que jajaja
¿Pero funciona lo del "myservo.attach(9,1500,600)"?
Si no hazte la App con el video que te puse y en vez de controlar un led controlas el servo con varios botones. (31-10-2015, 11:16 PM)Iván escribió: Si quieres controlarlo con el móvil con el modulo BT, te puedes hacer la App tu mismo en Mit App inventor la pones en el móvil y cargas el programa correspondiente. Mira estos videos: Son el 2º y el 3º
Voy a probar ahora si cambiando el código funciona.
#include <Servo.h> Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position int motor = 0; void setup() { Serial.begin(9600); // initialize serial: myservo.attach(9,1500,600); // attaches the servo on pin 9 to the servo object Serial.print("Arduino control Servo Motor Connected OK"); Serial.print('\n'); } void loop() { // if there's any serial available, read it: while (Serial.available() > 0) { // look for the next valid integer in the incoming serial stream: motor = Serial.parseInt(); // do it again: pos = Serial.parseInt(); // look for the newline. That's the end of your sentence: if (Serial.read() == '\n') { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position // print the three numbers in one string as hexadecimal: Serial.print("Data Response : "); Serial.print(motor, DEC); Serial.print(pos, DEC); } } } //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>=1; 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 //} //val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) //val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) //myservo.write(val); // sets the servo position according to the scaled value //delay(15) Sería así el código según me has dicho no? Vale, acabo de probarlo como tu me has dicho y parece que funciona, voy a testearlo bien por si hubiera algún problema, muchas gracias crack !!
23-11-2015, 04:17 PM
De nada! Para eso estamos.
Enséñanos un video o alguna foto del acabado final. |