Go Down

Topic: webserver for 5 relays (Read 4 times) previous topic - next topic

GaryP

How did you connect it, how did you test it? Please add your code using #-button, should look like this:

Code: [Select]

void setup()
{
}

void loop()
{
//your code
}


By the way, I'm not sure if I can help, I use 0023 IDE. Sorry about that...

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

GaryP

I tried to look at your code, but all the HTML-stuff inside...
You should try to minimize that part, I don't think all that is needed at this point.

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

winkleink

Hi,

I was doing something similar but controlling from a PC based webserver.
The Arduino is running a web server sketch as well and reading the HTTP Request details for the actions.
With this you can control 5 relays

Below is the link to the details:
http://winkleink.blogspot.co.uk/2012/08/arduino-ethernet-ethercard-xamp-web.html

Look at the Arduino Code to see how it's done.

I have since modified the PC server PHP code so it can control any number of Arduinos and Pins by storing the details in a mySQL database.

Hopefully, this helps.

Winkleink.

seanz2003

#8
Sep 20, 2012, 11:03 am Last Edit: Sep 20, 2012, 11:19 am by seanz2003 Reason: 1
I made a similar sketch a few months ago and took forever to figure out how the example really worked so Included a few notes on this incomplete sketch that may make it a little more understandable.
Code: [Select]
#include "etherShield.h"
#include "ETHER_28J60.h"

const int fanPin = 6;
const int ledPin = 7;
//                         Relay pins go here

const int ethernet_cs = 10;

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};  //   Something unique to your network  
static uint8_t ip[4] = {192, 168, 1, 15};                           //        unique to your network
static uint16_t port = 80;
ETHER_28J60 e;

void setup()
{

 
 e.setup(mac, ip, port);
 pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  // relay pins here
}

void loop()
{
processClient();

}
void processClient(){
char* params;
 if (params = e.serviceRequest())
 {
     
   e.print("<h1><a href='/?relay1=off'>Arduino Web Remote</a></h1>");                     // **take note of: <a href='/?relay1=off'> that is the important bit that the arduino looks at and decides what do **
   e.print("<button type='button' onclick=location.href='?relay1=off'>RELAY1</button>");              // a button for relay1, notice: href='?relay1=off'
   e.print("<button type='button' onclick=location.href='?fan=off'>FAN</button>");                 // copy for more buttons to control more relays...
   ...
   ...
   ...
   if (strcmp(params, "?relay1=on") == 0)             // this statement looks at what comes directly after this bit from above:  <a href='/... then you setup else if's to control pins
   {
    digitalWrite(relay1, HIGH);              // set your relay high
     
     e.print("<a href='?relay1=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>relay1 IS ON</button></a>");
       e.print("<br>");
   }
   else if (strcmp(params, "?relay1=off") == 0)
   {
     digitalWrite(relay1, LOW);
     e.print("<a href='?relay1=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>relay1 IS OFF</button></a>");
   }
   else if (strcmp(params, "?fan=on") == 0)
   {
     digitalWrite(fanPin, HIGH);
     e.print("<a href='?fan=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>FAN IS ON</button></a>");
   }
   else if (strcmp(params, "?fan=off") == 0)
   {
     digitalWrite(fanPin, LOW);
     e.print("<a href='?fan=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>FAN IS OFF</button></a>");
   }
   
   /* copy and paste else if's (2 for each relay- one to turn it on, the other alse if turns it off) so for 5 relays that should be one if statement followed
   by 9 else if's */
   e.respond();
 }
}
}

simisv

Thank you all  !!!

I solved . The problem is low memory on mega328 . I can't use button's , only links . Is working fine now , but i need to save status of the relays on internal eeprom  and not working so far .
I tested the examples from arduino and serial monitor show that eeprom program is working fine ,but i can't connect data from eeprom to relay status .

Go Up