HI
I am using the arduino uno and enc28j60 . tested and is ok . i want to control 5 relays but am stuck .
i used this example .
Thank you
webserver2relays.ino (2.48 KB)
HI
I am using the arduino uno and enc28j60 . tested and is ok . i want to control 5 relays but am stuck .
i used this example .
Thank you
webserver2relays.ino (2.48 KB)
What is the problem? Little more specific would help.
Cheers,
Kari
Hi GaryP
Thank you for response
I do not know how to modify the program to work with 5 relays . I tried unsuccessfully .
Ok, show the code you tried, but didn't work. Maybe there's something we can fix?
You must have tried something, and it failed, right?
Cheers,
Kari
this is the program . When i tried to connect the result is : web page not available
simisv_webserver_3led.ino (3.32 KB)
How did you connect it, how did you test it? Please add your code using #-button, should look like this:
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
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
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:
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.
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.
#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("
");
}
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();
}
}
}
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 .
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 .// A simple web server to turn 5 LED on or off
#include "etherShield.h"
#include "ETHER_28J60.h"
#include <EEPROM.h>
int outPin0 = 0; // relay1 to pin 4
int outPin1 = 1; // relay2 to pin 3
int outPin2 = 2; // relay3 to pin 2
int outPin3 = 3; // relay4 to pin 1
int outPin4 = 4; // relay5 to pin 0
const int ledPin = 9; // led status pin 9
byte value0;
byte value1;
byte value2;
byte value3;
byte value4;
int ledState = LOW;
long previousMillis = 0;
long interval = 1000;
static uint8_t mac[6] = {
0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {
192, 168, 0, 2}; // IP address for the webserver
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
void setup()
{
e.setup(mac, ip, port);
pinMode(outPin0, OUTPUT);
pinMode(outPin1, OUTPUT);
pinMode(outPin2, OUTPUT);
pinMode(outPin3, OUTPUT);
pinMode(outPin4, OUTPUT);
pinMode(ledPin, OUTPUT);
value0 = EEPROM.read(0x00);
value1 = EEPROM.read(0x01);
value2 = EEPROM.read(0x02);
value3 = EEPROM.read(0x03);
value4 = EEPROM.read(0x04);
if (byte value0=0)
{
digitalWrite(outPin0, LOW);
}
else if (byte value0=1)
{
digitalWrite(outPin0, HIGH);
}
if (byte value1=0)
{
digitalWrite(outPin1, LOW);
}
else if (byte value1=1)
{
digitalWrite(outPin1, HIGH);
}
if (byte value2=0)
{
digitalWrite(outPin2, LOW);
}
else if (byte value2=1)
{
digitalWrite(outPin2, HIGH);
}
if (byte value3=0)
{
digitalWrite(outPin3, LOW);
}
else if (byte value3=1)
{
digitalWrite(outPin3, HIGH);
}
if (byte value4=0)
{
digitalWrite(outPin4, LOW);
}
else if (byte value4=1)
{
digitalWrite(outPin4, HIGH);
}
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print("
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// 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);}
}
}