Sunteți pe pagina 1din 13

UNIVERSIDAD NACIONAL SAN ANTONIO

ABAD DEL CUSCO



TEORA GENERAL DE SISTEMAS
TEMA:


ALUMNOS :
BROTHYAM HUAMN CASAFRANCA 093167
DAVID CCAHUANA AGUILAR 083188


SEMESTRE : 2014 I
Docente : ING. JOS MAURO PILLCO QUISPE


Cusco Per
2014

PRCTICA LEDS
Resumen Terico
Proyecto de comunicacin entre un Arduino UNO, una aplicacin de escritorio y una aplicacin mvil
en Android, utilizando un entorno de programacin Multiplataforma, que nos permita ejecutar la
aplicacin en diferentes sistemas operativos.
La realizacin de un ejemplo de comunicacin USB entre un PC y un Arduino, la podemos dividir en
varios apartados, que son:
Desarrollo del circuito en un entorno simulado como Proteus y realizacin de la Proto-Board.
Instalacin del IDE de Arduino.
Desarrollo de la aplicacin de escritorio que servir de interfaz de comunicacin entre el
usuario y el microcontrolador (Lenguaje de programacin utilizado C#).
Desarrollo de la Aplicacin Mvil en Android que servir de interfaz de comunicacin entre el
usuario y el microcontrolador haciendo uso del bluetooth.

Placa Arduino Uno
Caractersticas tcnicas de Arduino Uno r3
Voltage: 5V
Voltage entrada (recomendado): 7-12V
Voltage entrada (limites): 6-20V
Digital I/O Pins: 14 (de los cuales 6 son salida PWM)
Entradas Analogicas: 6
DC Current per I/O Pin: 40 mA
DC Current parar 3.3V Pin: 50 mA
Flash Memory: 32 KB (ATmega328) de los cuales 0.5 KB son utilizados para el arranque
SRAM: 2 KB (ATmega328)
EEPROM: 1 KB (ATmega328)
Clock Speed: 16 MHz


Diagrama del control

Empezando segn las agujas del reloj:
Terminal de referencia analgica (naranja)
Tierra digital (verde claro)
Terminales digitales 2-13 (verde)
Terminales digitales 0-1/ E/S serie - TX/RX (verde oscuro) - Estos pines no se pueden utilizar
como e/s digitales (digitalRead() y digitalWrite()) si ests utilizando comunicacin serie (por
ejemplo Serial.begin).
Botn de reinicio - S1 (azul oscuro)
Programador serie en circuito "In-circuit Serial Programmer" o "ICSP" (azul celeste).
Terminales de entrada analgica 0-5 (azul claro)
Terminales de alimentacin y tierra (alimentacin: naranja, tierras: naranja claro)
Entrada de alimentacin externa (9-12VDC) - X1 (rosa)
Selector de alimentacin externa o por USB (coloca un jumper en los dos pines ms cercanos
de la alimentacin que quieras) - SV1 (prpura). En las versiones nuevas de Arduino la
seleccin de alimentacin es automtica por lo que puede que no tengas este selector.
USB (utilizado para subir programas a la placa y para comunicaciones serie entre la placa y el
ordenador; puede utilizarse como alimentacin de la placa) (amarillo)
Diagrama

Materiales y Costo


COMPONENTE IMAGEN COSTO DESCRIPCION
Arduino UNO r3

50.00 1 unidad
Protoboard

13.00 1 unidad
Leds

0.30
1Naranja,
1Verde, 2Rojo y
1Blanco
Resistencias

0.10
7 unidades
5-220k, 2-10k
Cables

0.20 5 unidades
CDIGO FUENTE
Programa y cdigo del Arduino Uno


Programa y cdigo en C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using EncenderLedArduino.Properties;
using System.Threading;
using System.Timers;

namespace EncenderLedArduino
{
public partial class Arduino : Form
{
private System.Timers.Timer timer;

public Arduino()
{
InitializeComponent();
DesactivarBotones();

//Nombramos puerto
PuertoSerial.PortName = "COM3";

//Definimos velocidad de comunicacin
PuertoSerial.BaudRate = 9600;

//Abrimos comunicacin con puerto
PuertoSerial.Open();
}

private void LimpiarTextos()
{
tb_TempAzul.Text = tb_tiempoAzul.Text = tb_TempAmarillo.Text =
tb_tiempoAmarillo.Text = tb_TempRojo.Text = tb_tiempoRojo.Text = "";
}
private void DesactivarBotones()
{
bu_off_amarillo.Enabled = bu_off_azul.Enabled = bu_off_rojo.Enabled = false;
}

private void Arduino_FormClosing(object sender, FormClosingEventArgs e)
{
//Apagamos todos los Leds
PuertoSerial.Write("4");
PuertoSerial.Write("5");
PuertoSerial.Write("6");

//Cerramos comunicacin con Puerto Serie
if (PuertoSerial.IsOpen) PuertoSerial.Close();
}

//Encender Led con tiempo
private void EncenderTiempo(string led, int tiempo)
{
//1 encender rojo, 2, encender amarillo, 3 encender azul
//4 apagar rojo, 5, apagar amarillo, 6 apagar azul
if (led == "Rojo") { PuertoSerial.Write("1"); Thread.Sleep(tiempo * 1000);
PuertoSerial.Write("4"); };
if (led == "Amarillo") { PuertoSerial.Write("2"); Thread.Sleep(tiempo * 1000);
PuertoSerial.Write("5"); };
if (led == "Azul") { PuertoSerial.Write("3"); Thread.Sleep(tiempo * 1000);
PuertoSerial.Write("6"); };
}

//Temporizador para prender
private void EncenderEnTiempo(string led, int tiempo)
{
//1 encender rojo, 2, encender amarillo, 3 encender azul
//4 apagar rojo, 5, apagar amarillo, 6 apagar azul
if (led == "Rojo") { Thread.Sleep(tiempo * 1000); PuertoSerial.Write("1"); };
if (led == "Amarillo") { Thread.Sleep(tiempo * 1000); PuertoSerial.Write("2");
};
if (led == "Azul") { Thread.Sleep(tiempo * 1000); PuertoSerial.Write("3"); };

}

//Prender Leds
private void On_Rojo(object sender, EventArgs e)
{
PuertoSerial.Write("1"); //Encender LED
bu_on_rojo.Enabled = false;
bu_off_rojo.Enabled = true;
pb_rojo.Image = Resources.Led_Rojo;
}
private void On_Amarrillo(object sender, EventArgs e)
{
PuertoSerial.Write("2"); //Encender LED
bu_on_amarillo.Enabled = false;
bu_off_amarillo.Enabled = true;
pb_amarillo.Image = Resources.Led_Ama;
}
private void On_Azul(object sender, EventArgs e)
{
PuertoSerial.Write("3"); //Encender LED
bu_on_azul.Enabled = false;
bu_off_azul.Enabled = true;
pb_azul.Image = Resources.Led_Azul;
}

//Apagar Leds
private void Off_Rojo(object sender, EventArgs e)
{
PuertoSerial.Write("4"); //Apagar LED
bu_on_rojo.Enabled = true;
bu_off_rojo.Enabled = false;
pb_rojo.Image = Resources.Led_Off;
}
private void Off_Amarrillo(object sender, EventArgs e)
{
PuertoSerial.Write("5"); //Apagar LED
bu_on_amarillo.Enabled = true;
bu_off_amarillo.Enabled = false;
pb_amarillo.Image = Resources.Led_Off;
}
private void Off_Azul(object sender, EventArgs e)
{
PuertoSerial.Write("6"); //Apagar LED
bu_on_azul.Enabled = true;
bu_off_azul.Enabled = false;
pb_azul.Image = Resources.Led_Off;
}

private void SoloNumeros(object sender, KeyPressEventArgs e)
{
//Para obligar a que slo se introduzcan nmeros
if (Char.IsDigit(e.KeyChar))
{
e.Handled = false;
}
else
if (Char.IsControl(e.KeyChar)) //permitir teclas de control como retroceso
{
e.Handled = false;
}
else
{
//el resto de teclas pulsadas se desactivan
e.Handled = true;
}
}

//Encender Leds con tiempo
private void TiempoRojo(object sender, EventArgs e)
{
int tiempo = int.Parse(tb_tiempoRojo.Text);
LimpiarTextos();
EncenderTiempo("Rojo", tiempo);
}

private void TiempoAzul(object sender, EventArgs e)
{
int tiempo = int.Parse(tb_tiempoAzul.Text);
LimpiarTextos();
EncenderTiempo("Azul", tiempo);
}

private void TiempoAmarillo(object sender, EventArgs e)
{
int tiempo = int.Parse(tb_tiempoAmarillo.Text);
LimpiarTextos();
EncenderTiempo("Amarillo", tiempo);
}

//Temporizador Leds
private void ParpadeoRojo(object sender, EventArgs e)
{
int tiempo = int.Parse(tb_TempRojo.Text);
LimpiarTextos();
EncenderEnTiempo("Rojo", tiempo);
}

private void ParpadeoAzul(object sender, EventArgs e)
{
int tiempo = int.Parse(tb_TempAzul.Text);
LimpiarTextos();
EncenderEnTiempo("Azul", tiempo);
}

private void ParpadeoAmarillo(object sender, EventArgs e)
{
int tiempo = int.Parse(tb_TempAmarillo.Text);
LimpiarTextos();
EncenderEnTiempo("Amarillo", tiempo);
}

private void Off_RojoTemp(object sender, EventArgs e)
{
PuertoSerial.Write("4"); //Apagar LED
bu_on_rojo.Enabled = true;
bu_off_rojo.Enabled = false;
pb_rojo.Image = Resources.Led_Off;
}

private void Off_AzulTemp(object sender, EventArgs e)
{
PuertoSerial.Write("5"); //Apagar LED
bu_on_rojo.Enabled = true;
bu_off_rojo.Enabled = false;
pb_rojo.Image = Resources.Led_Off;
}

private void Off_AmarilloTemp(object sender, EventArgs e)
{
PuertoSerial.Write("6"); //Apagar LED
bu_on_rojo.Enabled = true;
bu_off_rojo.Enabled = false;
pb_rojo.Image = Resources.Led_Off;
}

private void IniciaTemporizador(object sender, EventArgs e)
{
int TAz = int.Parse(tb_TempAzul.Text);
int TAm = int.Parse(tb_TempAmarillo.Text);
int TRo = int.Parse(tb_TempRojo.Text);
LimpiarTextos();
EncenderEnTiempo("Rojo", TRo);
EncenderEnTiempo("Azul", TAz);
EncenderEnTiempo("Amarillo", TAm);

}

}
}





Programa y cdigo del Android con MIT App Inventor 2








Anexos



Bibliografa
1. http://www.youtube.com/watch?v=wUBtcWy250k
2. http://www.arduteka.com/2011/11/tutorial-arduino-0004-sensor-ldr/
3. http://diymakers.es/crear-app-para-arduino-con-app-inventor/

S-ar putea să vă placă și