Olá!

Esse é meu primeiro tópico aqui no fórum, então já peço desculpa se estiver violando alguma regra.

Estou montando meu primeiro projeto de automação residencial com arduino, e gostaria de controlar alguns reles tanto pelo Ethernet ( botão html ) como pelo infravermelho, através de um receptor IR e um controle remoto. Consigo fazer eles funcionarem separadamente, mas não consigo fazer os dois funcionarem no mesmo código.

Estou começando a programar agora, mas qualquer ajuda é bem vinda!

Obs.:Tentei usar a biblioteca padrão do arduino e a biblioteca EthernetSup

Abraços!

Exibições: 1437

Responder esta

Respostas a este tópico

será que não é porque vc não juntou os códigos da maneira correta?

Esse é meu problema estou começando a mexer com aduino agora. sera que alguém não tem um exemplo desse código?

cola aí pra nós os códigos que vc disse que funcionam separadamante e também o código onde vc tentou juntar tudo e deu zebra

qual ethernet shield vc esta usando?

Estou usando o  Ethernet Shield W5100, ele funciona normal, o problema realmente ta sendo na hora de juntar os códigos. Meu conhecimento é bem fraco em programação, acho que por isso estou empacado nisso.

Entao posta ai os codigos

código do IR:

#include <IRremote.h>

int RECV_PIN = 11;
const int led1 = 4;
int led2 = 5;
int led3 = 6;
int va1 = 0;
int va2 = 0;
int va3 = 0;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
va1 = digitalRead(led1);// lendo o status da porta de acionamento
va2 = digitalRead(led2);
va3 = digitalRead(led3);

if(results.value == 0xFF30CF and va1 == LOW) {
digitalWrite(led1, HIGH);
}
if(results.value == 0xFF30CF and va1 == HIGH) {
digitalWrite(led1, LOW);
}
if (results.value == 0xFF18E7 and va2 == LOW) {
digitalWrite(led2, HIGH);
}
if (results.value == 0xFF18E7 and va2 == HIGH) {
digitalWrite(led2, LOW);
}
if (results.value == 0xFF7A85 and va3 == HIGH) {
digitalWrite(led3, LOW);
}
if (results.value == 0xFF7A85 and va3 == LOW) {
digitalWrite(led3, HIGH);
}
irrecv.resume();
}
}

Código do Ethernet :

#include <SPI.h>
#include "EthernetSupW5100.h"

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);

int portaledvermelho = 5;
int portaledverde = 6;
int portaledazul = 7;
int portaledalarme = 8;
int portao = 9;

void setup()
{
EthernetSupW5100.begin(mac, ip);
server.begin();

// Configurando portas dos botoes
pinMode(portaledvermelho, OUTPUT);
pinMode(portaledverde, OUTPUT);
pinMode(portaledazul, OUTPUT);
pinMode(portaledalarme, OUTPUT);
pinMode(portao, OUTPUT);

// Estado incial das portas
digitalWrite(portaledvermelho, LOW);
digitalWrite(portaledverde, LOW);
digitalWrite(portaledazul, LOW);
digitalWrite(portaledalarme, LOW);
digitalWrite(portao, LOW);

// Registrando botoes
//EthernetSupW5100.addButton(button pin, text on, text off, button type);
EthernetSupW5100.addButton(portaledvermelho, "Liga Led Vermelho", "Desliga Led Vermelho", FLIP_BUTTON);
EthernetSupW5100.addButton(portaledverde, "Liga Led Verde", "Desliga Led Verde", FLIP_BUTTON);
EthernetSupW5100.addButton(portaledazul, "Liga Led Azul", "Desliga Led Azul", FLIP_BUTTON);
EthernetSupW5100.addButton(portaledalarme, "Liga o Alarme", "Desliga Alarme", FLIP_BUTTON);
EthernetSupW5100.addButton(portao, "Abre Porta", "", SWITCH_BUTTON);
}

void loop()
{
// Carrega HTML
EthernetSupW5100.loadHtml(server);

// Verifica se algum botao foi pressionado
int lastButton = EthernetSupW5100.getLastClickedButton();
byte state = EthernetSupW5100.getButtonState(lastButton);

// Executa o comando conforme o botao clicado
if (lastButton == portaledvermelho)
{
digitalWrite(portaledvermelho, state);
}
else if (lastButton == portaledverde)
{
digitalWrite(portaledverde, state);
}
else if (lastButton == portaledazul)
{
digitalWrite(portaledazul, state);
}
else if (lastButton == portaledalarme)
{
digitalWrite(portaledalarme, state);
}
else if (lastButton == portao)
{
digitalWrite(portao, HIGH);
delay(1000);
digitalWrite(portao, LOW);
}

// Delay
delay(10);
}

tente assim

#include <SPI.h>
#include "EthernetSupW5100.h"
#include <IRremote.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);
int portaledvermelho = 5;
int portaledverde = 6;
int portaledazul = 7;
int portaledalarme = 8;
int portao = 9;
int RECV_PIN = 11;
const int led1 = 4;
int led2 = 5;
int led3 = 6;
int va1 = 0;
int va2 = 0;
int va3 = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
irrecv.enableIRIn(); // Start the receiver

EthernetSupW5100.begin(mac, ip);
server.begin();

// Configurando portas dos botoes
pinMode(portaledvermelho, OUTPUT);
pinMode(portaledverde, OUTPUT);
pinMode(portaledazul, OUTPUT);
pinMode(portaledalarme, OUTPUT);
pinMode(portao, OUTPUT);

// Estado incial das portas
digitalWrite(portaledvermelho, LOW);
digitalWrite(portaledverde, LOW);
digitalWrite(portaledazul, LOW);
digitalWrite(portaledalarme, LOW);
digitalWrite(portao, LOW);

// Registrando botoes
//EthernetSupW5100.addButton(button pin, text on, text off, button type);
EthernetSupW5100.addButton(portaledvermelho, "Liga Led Vermelho", "Desliga Led Vermelho", FLIP_BUTTON);
EthernetSupW5100.addButton(portaledverde, "Liga Led Verde", "Desliga Led Verde", FLIP_BUTTON);
EthernetSupW5100.addButton(portaledazul, "Liga Led Azul", "Desliga Led Azul", FLIP_BUTTON);
EthernetSupW5100.addButton(portaledalarme, "Liga o Alarme", "Desliga Alarme", FLIP_BUTTON);
EthernetSupW5100.addButton(portao, "Abre Porta", "", SWITCH_BUTTON);
}
void loop()
{if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
va1 = digitalRead(led1);// lendo o status da porta de acionamento
va2 = digitalRead(led2);
va3 = digitalRead(led3);

if(results.value == 0xFF30CF and va1 == LOW) {
digitalWrite(led1, HIGH);
}
if(results.value == 0xFF30CF and va1 == HIGH) {
digitalWrite(led1, LOW);
}
if (results.value == 0xFF18E7 and va2 == LOW) {
digitalWrite(led2, HIGH);
}
if (results.value == 0xFF18E7 and va2 == HIGH) {
digitalWrite(led2, LOW);
}
if (results.value == 0xFF7A85 and va3 == HIGH) {
digitalWrite(led3, LOW);
}
if (results.value == 0xFF7A85 and va3 == LOW) {
digitalWrite(led3, HIGH);
}
irrecv.resume();
}
}
// Carrega HTML
EthernetSupW5100.loadHtml(server);

// Verifica se algum botao foi pressionado
int lastButton = EthernetSupW5100.getLastClickedButton();
byte state = EthernetSupW5100.getButtonState(lastButton);

// Executa o comando conforme o botao clicado
if (lastButton == portaledvermelho)
{
digitalWrite(portaledvermelho, state);
}
else if (lastButton == portaledverde)
{
digitalWrite(portaledverde, state);
}
else if (lastButton == portaledazul)
{
digitalWrite(portaledazul, state);
}
else if (lastButton == portaledalarme)
{
digitalWrite(portaledalarme, state);
}
else if (lastButton == portao)
{
digitalWrite(portao, HIGH);
delay(1000);
digitalWrite(portao, LOW);
}

// Delay
delay(10);
}

Código compila e sobe, mas nao funciona nem o acesso a ethernet nem com o IR;

To apanhando igual menino novo ...kk

To usando o esse cod. nada de rodar, sera que é pouco memoria? estou usando arduino Uno

#include <SPI.h>
#include "EthernetSupW5100.h"
#include <IRremote.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
EthernetServer server(80);

int led1 = 5;
int led2 = 6;
int led3 = 7;
int alarme = 8;
int porta = 9;
int RECV_PIN = 2;

int va1 = 0;
int va2 = 0;
int va3 = 0;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{



irrecv.enableIRIn(); // Start the receiver

EthernetSupW5100.begin(mac, ip);
server.begin();

// Configurando portas dos botoes
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(alarme, OUTPUT);
pinMode(porta, OUTPUT);

// Estado incial das portas
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(alarme, LOW);
digitalWrite(porta, LOW);

// Registrando botoes
//EthernetSupW5100.addButton(button pin, text on, text off, button type);
EthernetSupW5100.addButton(led1, "Liga Led Vermelho", "Desliga Led Vermelho", FLIP_BUTTON);
EthernetSupW5100.addButton(led2, "Liga Led Verde", "Desliga Led Verde", FLIP_BUTTON);
EthernetSupW5100.addButton(led3, "Liga Led Azul", "Desliga Led Azul", FLIP_BUTTON);
EthernetSupW5100.addButton(alarme, "Liga o Alarme", "Desliga Alarme", FLIP_BUTTON);
EthernetSupW5100.addButton(porta, "Abre Porta", "", SWITCH_BUTTON);
}

void loop()
{

if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
va1 = digitalRead(led1);// lendo o status da porta de acionamento
va2 = digitalRead(led2);
va3 = digitalRead(led3);

if(results.value == 0xFF30CF and va1 == LOW) {
digitalWrite(led1, HIGH);
}
if(results.value == 0xFF30CF and va1 == HIGH) {
digitalWrite(led1, LOW);
}
if (results.value == 0xFF18E7 and va2 == LOW) {
digitalWrite(led2, HIGH);
}
if (results.value == 0xFF18E7 and va2 == HIGH) {
digitalWrite(led2, LOW);
}
if (results.value == 0xFF7A85 and va3 == HIGH) {
digitalWrite(led3, LOW);
}
if (results.value == 0xFF7A85 and va3 == LOW) {
digitalWrite(led3, HIGH);
}
irrecv.resume(); // Receive the next value
}

// Carrega HTML
EthernetSupW5100.loadHtml(server);

// Verifica se algum botao foi pressionado
int lastButton = EthernetSupW5100.getLastClickedButton();
byte state = EthernetSupW5100.getButtonState(lastButton);

// Executa o comando conforme o botao clicado
if (lastButton == led1)
{
digitalWrite(led1, state);
}
else if (lastButton == led2)
{
digitalWrite(led2, state);
}
else if (lastButton == led3)
{
digitalWrite(led3, state);
}
else if (lastButton == alarme)
{
digitalWrite(alarme, state);
}
else if (lastButton == porta)
{
digitalWrite(porta, HIGH);
delay(1000);
digitalWrite(porta, LOW);
}

// Delay
delay(10);
}

Anexos

Galera eu descobri por que os códigos do IR + Ethernet não funcionam simultaneamente. O problema é a biblioteca Ethernet SUP 5100, após vários testes e a ajuda de um amigo, descobri que o código funciona 100% com outras biblioteca. Apesar da biblioteca SUP5100 ser mais esteticamente agradável ela tem muitas incompatibilidades ainda.

Agradeço a todo mundo que tentou ajudar!

qual foi a biblioteca que funcionou

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço