Vous êtes sur la page 1sur 4

FORMATO DE INFORME DE PRÁCTICA DE LABORATORIO /

TALLERES / CENTROS DE SIMULACIÓN – PARA ESTUDIANTES

CARRERA: Ingeniería Electrónica ASIGNATURA: Lab. Comunicaciones (SI)


NRO. PRÁCTICA: 010 TÍTULO PRÁCTICA: Aplicación con Ethernet y Arduino
OBJETIVO ALCANZADO:
- Conocer los tipos de sensores de conexión para usar ethernet
- Determinar experimentalmente la conexión del módulo ethernet con Arduino
- Realizar la conexión con el modulo ethernet de una página web
- Controlar desde un smarthphone el apagado y encendido de un led desde la página web
Equipos, instrumentos y software
Descripción Cantidad Marca Identificación / serie
Computadora S.O. Windows 7, 1 - -
64 bits
Software UPS-BS-02 1 - -
Modulo Ethernet 1 - -
Arduino UNO 1 - -
Cable de conexión serial 1 - -
Protoboard 1 - -
Luces Led 1 - -
Resistencias 1 - -
Potenciometro 1 - -
Proceso

ACTIVIDADES DESARROLLADAS
1. Configuración del Arduino
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,50);
EthernetServer server(80);
int led=7;
String estado="OFF";
void setup() {
Ethernet.begin(mac, ip);
server.begin();
pinMode(led,OUTPUT);
}
void loop() {
EthernetClient cliente = server.available();
if (cliente) {
boolean currentLineIsBlank = true;
String cadena="";
while (cliente.connected()) {
if (cliente.available()) {
char c = cliente.read();
cadena.concat(c);
int posicion=cadena.indexOf("LED=");
if(cadena.substring(posicion)=="LED=ON")
{
digitalWrite(led,HIGH);
estado="ON";
}
if(cadena.substring(posicion)=="LED=OFF")
{
digitalWrite(led,LOW);
estado="OFF";
}
if (c == '\n' && currentLineIsBlank) {
cliente.println("HTTP/1.1 200 OK");
cliente.println("Content-Type: text/html");
cliente.println("Connection: close");
//cliente.println("Refresh: 3");
cliente.println();
cliente.println("<!DOCTYPE HTML>");
cliente.println("<html>");
cliente.println("<HEAD>");
cliente.println("<TITLE>Ethernet Monitor</TITLE>");
cliente.println("</HEAD>");
cliente.println("<BODY>");
cliente.println("<hr />");
cliente.println("<H1>Lab. Comunicaciones (SI)</H1>");
cliente.println("<br />");
cliente.println("<H2>AUTOR: Luis Zhingri</H2>");
cliente.println("<br />");
cliente.println("Practica 10: Ethernet");
cliente.println("<br />");
cliente.println("<br />");
cliente.println("<div style='text-align:center;'>");
cliente.println("<button onClick=location.href='./?LED=ON\' style='margin:auto;background-color: #FE2E2E;color:
snow;padding: 10px;border: 1px solid ##FE2E2E;width:65px;'>");
cliente.println("<H2>ON<H2>");
cliente.println("</button>");
cliente.println("<button onClick=location.href='./?LED=OFF\' style='margin:auto;background-color: #84B1FF;color:
snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>");
cliente.println("<H2>OFF<H2>");
cliente.println("</button>");
cliente.println("<br /><br />");
cliente.println("<H2> <b>LED = <H2>");
cliente.print(estado);
cliente.println("</b><br />");
int lecturaSensor = analogRead(0);
cliente.print("<H2>Valor Analogico es: <H2>");
cliente.print(lecturaSensor);
cliente.println("<br />");
cliente.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(15);
cliente.stop();
}
}
2. Código HTML
- EthernetServer server(80);
Creamos un servidor Web con el Puerto 80 que es el puerto HTTP por defecto
- EthernetClient client = server.available();
Creamos un cliente Web el mismo que lo detectara a través de una petición HTTP
- cliente.println("<button onClick=location.href='./?LED=ON\' style='margin:auto;background-color: #FE2E2E;color:
snow;padding: 10px;border: 1px solid ##FE2E2E;width:65px;'>");
Crea los botones. Para enviar parámetros a través de HTML se utiliza el método URL encode. Los parámetros se envían a
través del símbolo ‘?’.

RESULTADO(S) OBTENIDO(S):
- Interfaz de la página web

Fig2. Interfaz con el led encendido y apagado


- Conexión
Fig3. Arduino con Sheld FastEthernet
CONCLUSIONS:
A faster response can be determined than when handling a Led with another type of element for a communication.
Its connection is faster and does not require as much configuration as other devices, so it is more comfortable to use in more
familiar or comfortable environments where it can be used with a person who does not have high knowledge in the subject.
RECOMMENDATIONS:
Check the Ethernet module used since depending on the module used its connection pins will vary. In addition, if a page is
going to be used, an HTTP or HTTPS port must be used.

Nombre: Luis Fernando Zhingri Torres

Firma: _________________________

Vous aimerez peut-être aussi