Você está na página 1de 17

Android Arduino

Control
Android Arduino ESP8266 IoT Control Hardware Devices ,Development Developer
30 .. 2557

Arduino y Matlab I Blink!


Posted on January 12, 2014 by Tr4nsduc7or

[Inicio de explicacin]
El holamundo por excelencia de Arduino es el Blink, que consiste simplemente en apagar y
encender el LED que lleva incorporado de fbrica en el pin digital 13. As que para no romper
con la tradicin, vamos a crear un pequeo programa con Matlab que encender y apagrar
este LED de distintas maneras.
Si no lo has hecho ya, debers configurar Matlab y Arduino para que puedan interaccionar.
Descubre cmo en mi ltimo tutorial.
Conecta Arduino al ordenador y abre Matlab. Primero, deberemos iniciar la conexin por
USB de Matlab y Arduino, escribiendo

1 arduino = arduino('/dev/ttyS101')
e intentar conectarse.
Si todo ha salido bien, aparecer un mensaje kilomtrico con una lista de todos los
pines habidos y por haber. Si en lugar de esto te sale error, intenta desconectar el
USB y volverlo a conectar. Tambin es posible que debas volver a crear el enlace
simblico, tal y cmo expliqu en el tutorial de configuracin.
Configuramos el pin digital nmero 13 para que sea una salida

1 arduino.pinMode(13,'output')
Podemos apagar y encender el LED con los comandos:

1 arduino.digitalWrite(13,1) %Para encender


2
3 arduino.digitalWrite(13,0) %Para apagar
Cuando te canses de encender y apagar el LED a mano, puedes crear un bucle para
automatizarlo. Vamos a encenderlo y apagarlo en intervalos de un segundo doscientas veces.

1 for x=1:200
2 arduino.digitalWrite(13,1)
3 pause(1) %Ntese que el comando delay aqu es pause. delay(1000) = pause(1)
4 arduino.digitalWrite(13,0)
pause(1)
5
En cualquier momento puedes parar el programa con Ctrl+C
El siguiente cdigo va a utilizar algunas de las funciones propias de Matlab. Va a encender y a
apagar el LED en intervalos de tiempo que van a seguir una funcin seno hasta 90 grados,
o hasta PI/2 si lo mesuramos en radianes, que es la unidad que utiliza el Matlab.
Ejemplo de onda sinusoidal

Veremos que el LED se va encendiendo y apagando cada vez ms despacio, siguiendo la


forma de una onda sinusoidal.

1
y=0 %Varaible que almacenar los radianes
2 for x=1:90
3 y=y+0.01745 %0.01745 es el resultado de dividir PI entre 180
4 arduino.digitalWrite(13,1)
5 pause(sin(y))
arduino.digitalWrite(13,0)
6 pause(sin(y))
7 end
8
No dudes en comentar si tienes algn problema.

Arduino Bluetooth Servo Motor Control


Arduino Bluetooth Servo Motor
Control
Arduino Bluetooth Servo Motor Control Application is allow you to control Servo Motor position.( 0 -
180 degree )
This App must connect to Arduino Board and Bluetooth Module then control Servo Motor.

The Application Features


Control 0 - 180 Degree of Servo Motor position with progress bar , knob and Fixed degree.(
PWM Output )
Auto Control Function and can adjust timing to control.
Show Bluetooth Connection Status and Serial Data monitor. When not connect Arduino
Board yet.(User Interface Disable.) When Bluetooth connected already. Then enable UI. and
ready to Control.
Free Version with Ad.
External Hardware
1. Arduino Board or compatible Board.
2. Serial TTL Bluetooth Module
3. Servo Motor ( We use FUTABA Model S3003 or other)

Wiring Diagram

Arduino Source Code ( same USB Version )


Arduino Code ( You need to program into Arduino Board. )

Visit Hardware page at http://microcontrollerkits.blogspot.com/2014/01/arduino-usb-control-servo-


motor.html

Android App on Google Play.

https://play.google.com/store/apps/details?id=arduino.bluetooth.servo

App Manual.
Enable Bluetooth Setting First.
Then if you are not pairing your bluetooth module yet.
Must pairing in the bluetooth settings.

Open App. Click Connect Bluetooth Button.


When Bluetooth Connected. Show "Connected to : YOUR BLUETOOTH NAME OK"
and Change Connect Bluetooth Button to Knob.
Ready to control your Servo Motor.

Use Knob
Fixed Position Button
Auto Control ON/OFF
Option Menu
Setting ( for future use )
Hardware Diagram
About Developer
Exit
Arduino USB Control Servo Motor
Use Arduino Board to control Servo Motor.

Hardware
1. Arduino Board or compatible Board.

2. USB Cable ( A to B Male/Male )

3. Servo Motor ( We use FUTABA Model S3003 or other)

Wiring Diagram
Use Arduino PWM Output pin 9

Arduino Code Download code Link


#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);

Download Arduino code

Program Arduino Code to Arduino


Board
Video : How to upload Arduino Code
Open Arduino Program.
File Menu - Open

Select ServoControl.ino code


Verify code

Upload to Arduino Board

Command Control Testing


Command Control a,bbb < Enter> (a = Servo Motor = 1 , bbb = degree = 0-180 )

If you to control position to 90 degree.


Sent 1,90 <Enter> to Arduino Board.

Use Tools - Serial Monitor on Arduino Program.


Tools - Serial Monitor

If connect to Arduino Board.


Serial Monitor response "Arduino control Servo Motor Connected OK"
Sent Command 1,90 <Enter> to set Servo Position to 90 degree.
Data Response : 15A

Use Android + Arduino controls Servo Motor


http://androidcontrol.blogspot.com/2014/01/arduino-servo-motor-control.html

https://play.google.com/store/apps/details?id=arduino.control.servo

Você também pode gostar