Bonjour,
Voila enfait j'ai pour projet un genre de multiprise commander par mon portable en utilisant le wifi,
donc PC => WIFI MODEM => ETHERNET => ARDUINO
Donc jusque la tout va bien j'utilise des relais optoculté et tout, tout fonctionne nickel je clique sur un bouton dans un programme qui envoi l'info a l'arduino et allume le relai et si je rappuie il s’éteint, ça marche nickel, je peut le faire des millier de fois tout est ok MAIS dès que je branche n'importe quoi sur un prise, je peut allumer/éteindre le relai 2 ou 3 fois après l'arduino "BUG" il reçoit plus rien ... il faut le reset pour qu'il refonctionne, donc est ce que quelqu'un sait comment résoudre ce problème ?
car la je n'en peu plus, j'ai tout essayé, changer le code (je doit en avoir une dizaine différent), le câblage, l'alimentation, les relais, le modem ...
MERCI d'avance
Mon code:
#include <EtherCard.h>
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// ethernet interface ip address
static byte myip[] = { 192,168,1,5 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
// Using a Variable for the Pin, but it is not necessary
const int ledPin2 = 1;
const int ledPin4 = 2;
// Some stuff for responding to the request
char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;
// Small web page to return so the request is completed
char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Arduino 192.168.1.5"
"</title></head>"
"<body>"
"<h3>Arduino 192.168.1.5</h3>"
"</body>"
"</html>"
;
void setup(){
// Set Pin2 to be an Output
pinMode(ledPin2, OUTPUT);
// Set Pin4 to be an Output
pinMode(ledPin4, OUTPUT);
// Scary complex intializing of the EtherCard - I don't understand this stuff (yet0
ether.begin(sizeof Ethernet::buffer, mymac);
// Set IP using Static
ether.staticSetup(myip, gwip);
}
void loop(){
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
// IF LED2=ON turn it ON
if(strstr((char *)Ethernet::buffer + pos, "GET /?LED2=ON") != 0) {
Serial.println("Received ON command");
digitalWrite(ledPin2, HIGH);
}
// IF LED2=OFF turn it OFF
if(strstr((char *)Ethernet::buffer + pos, "GET /?LED2=OFF") != 0) {
Serial.println("Received OFF command");
digitalWrite(ledPin2, LOW);
}
// IF LED4=ON turn it ON
if(strstr((char *)Ethernet::buffer + pos, "GET /?LED4=ON") != 0) {
Serial.println("Received ON command");
digitalWrite(ledPin4, HIGH);
}
// IF LED4=OFF turn it OFF
if(strstr((char *)Ethernet::buffer + pos, "GET /?LED4=OFF") != 0) {
Serial.println("Received OFF command");
digitalWrite(ledPin4, LOW);
}
//Return a page so the request is completed.
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}