App Inventor Automação com Android e Arduino EthernetShield

Olá Pessoal.

Já vi aqui no forum projectos de Automacao com arduino blueetooth e Android.

Porem ainda não encontrei nenhum projecto que invés de usar Bluetooth funcione com etherneshield.

Pesquisando um pouco na net encontrei este projecto:

---------------------------------CÓDIGO ARDUINO-------------------------------------

/*
Web Server

A simple web server that switches LED's on and off, based on input from an
Android App Inventor application

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* LED outputs attached to pins 5 and 6

created 13 Oct 2010
by Rogier van den Berg / rogiervandenberg.nl

*/

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 201 };

//Settings for the two LED's
int ledPin = 5;
int ledState = LOW;
int powerLedPin = 6;
int powerLedState = LOW;

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);

void setup()
{
//Set the LED pins as output
pinMode(ledPin, OUTPUT);
pinMode(powerLedPin, OUTPUT);

//For debugging, set the Serial Output
Serial.begin(9600);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();

//Turn one of the LED's on, to know it is ready to go!
digitalWrite(powerLedPin, HIGH);
}

void loop()
{
//Make sure requests are taken care of
handleIncomingInstruction();

//Make sure the power led stays on, when nothing happens.
if(powerLedState == LOW)
switchPowerLed();
}

void handleIncomingInstruction()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean newLine = true;
String line = "";

while (client.connected() && client.available()) {

char c = client.read();
//Serial.print(c);
switchPowerLed();

// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && newLine) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
}
if (c == '\n') {
// you're starting a new line
newLine = true;
evaluateLine(line);
line = "";
}
else if (c != '\r') {
// you've gotten a character on the current line
newLine = false;
line += c;
}

}

evaluateLine(line);

// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}

void evaluateLine(String line)
{
if (line.startsWith("tag", 0)) {
String instruction = line.substring(4, line.length());
Serial.println(instruction);
if (instruction == "TestOpdracht")
switchLed();
}
}

void switchLed()
{
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;

// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
Serial.println("We switchen de LED!");
}

void switchPowerLed()
{
// if the LED is off turn it on and vice-versa:
if (powerLedState == LOW)
powerLedState = HIGH;
else
powerLedState = LOW;

// set the LED with the ledState of the variable:
digitalWrite(powerLedPin, powerLedState);
}

------------------------------------------------ FIM ------------------------------------------

Código para app inventor para o abrir basta no app inventor fazer:

My projectos-->More Actions-->Upload Source

DOWNLOAD CODIGO APP INVENTOR

---------------------- VIDEO DE DEMONSTRAÇÃO----------------------------------

https://www.youtube.com/watch?v=r7y0IpGhk_w

Ora bem o que este projecto faz é basicamente atraves de um Android com um programa apenas com um botao faz ligar e desligar o led.

Agora eu gostaria da vossa ajuda para o seguinte:

Eu pretendo que ao ligar o Led esse botão fique com a cor VERDE e ao desligar o led fique com a cor Vermelha.

E pretendia também o seguinte: se o led tiver acesso e o botão verde, eu gostaria que ao desligar o equipamento android e voltar a ligar o programa, que ele veja o estado do led.. se ele tiver acesso aparece então a cor verde se tiver desligado, aparece vermelho.

Alguem me pode enviar o projecto já modificado com essa funcoes?

Ficaria muito grato.

Exibições: 19772

Responder esta

Respostas a este tópico

ola pessoal desculpem a demora aqui fica os codigos para voces estudarem..

esta a funcionar,..

Anexos

o código arduino,nao ta dando certo

Lucas, tentou liberar a porta?

Manda uma imagem do APP, ou manda o app para eu dar uma olhada.

Ou melhor, tenta fazer o seguinte. Percebi que você está buscando um status olhando pela imagem que vc enviou no post passado. Então tenta colocar um "Make  text > IP" no Web1.Url

Lucas B, faltou ainda o "Make Text" antes de todos os Web1.Ulr no ButtonClick1 e 2.... verifica aí depois me fala....

Se ainda tiver problema, vou dar uma relembrada de como fiz o programa... tem um tempinho já q relaxei com AI e Arduino..... rsrsrssr

Lucas B, na verdade eu fiz essa aplicação, depois abandonei e fiz de um jeito "mais simples", sem usar o Tiny. Mas, minhas duas aplicações estão funcionando, inclusive usei o No-IP. Devo ter eles salvos no computador, porém sou daqueles que gosta de dar a vara de pescar e não o peixe...rsrsrssr

Podemos ir desenvolvendo como fiz com o Rodolfo, vamos pegar o programa de onde vc parou e vamos continuar ele até funcionar. Se preferir, tenho TS, Skype etc... é só marcar um horário bom para os dois, ou quem quiser entrar tb e desenvolver.. assim todos aprendem, inclusive eu...

Claro eu também tenho interesse no aprendizado. Aliás vou fazer um TCC neste tema então sou obrigado a aprendê-lo muito bem...hahaha
Na verdade,ainda não mexi muito no código. O do Arduino por enquanto está igualzinho do Rodolfo. Estou tentando viabilizar o controle do LED primeiro via internet. Feito isso, consigo fazer qualquer coisa e começarei a desenvolver as aplicações. Só falta essa parte do no-ip mesmo que ja estou quebrando a cabeça faz um tempinho...
Me passa seu skype para conversarmos.

Abraço!

E aí Rodolfo!!! essa aplicação tá rodando ainda? ou já desfez? rsrsrsrsrs

Até agora ainda não consegui resolver a questão do no-ip Bruno. Já estou quase partindo para outras alternativas...hahahahaha
Quando vc fez, foi no mesmo modelo do Rodolfo? Ou o App é totalmente diferente? 
Usando o Tiny deu certo também?

Já fiz vários contatos a respeito e até agora ninguém conseguiu resolver.

rodolfo no seu aplicativo a parte que esta escrito sms é para que ?

poderia me diser

muito obrigado , e parabens pelo codigo

Renan, o SMS é isso mesmo que você está pensando.... através de um sms com o código certo, por exemplo "acender luz", ele acende a luz que você pediu....

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço