UK
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« on: September 01, 2012, 10:23:27 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Espoo, Finland
Offline
God Member
Karma: 6
Posts: 581
"Oops, try again..."
|
 |
« Reply #1 on: September 01, 2012, 12:11:41 pm » |
What is the problem? Little more specific would help.
Cheers, Kari
|
|
|
|
|
Logged
|
The only law for me; Ohms Law: U=R*I P=U*I Note to self: "Damn! Why don't you just fix it!!!"
|
|
|
|
UK
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #2 on: September 01, 2012, 02:26:57 pm » |
Hi GaryP Thank you for response I do not know how to modify the program to work with 5 relays . I tried unsuccessfully .
|
|
|
|
|
Logged
|
|
|
|
|
Espoo, Finland
Offline
God Member
Karma: 6
Posts: 581
"Oops, try again..."
|
 |
« Reply #3 on: September 01, 2012, 03:24:10 pm » |
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
|
|
|
|
|
Logged
|
The only law for me; Ohms Law: U=R*I P=U*I Note to self: "Damn! Why don't you just fix it!!!"
|
|
|
|
UK
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #4 on: September 01, 2012, 03:47:20 pm » |
this is the program . When i tried to connect the result is : web page not available
|
|
|
|
|
Logged
|
|
|
|
|
Espoo, Finland
Offline
God Member
Karma: 6
Posts: 581
"Oops, try again..."
|
 |
« Reply #5 on: September 02, 2012, 03:26:39 am » |
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
|
|
|
|
|
Logged
|
The only law for me; Ohms Law: U=R*I P=U*I Note to self: "Damn! Why don't you just fix it!!!"
|
|
|
|
Espoo, Finland
Offline
God Member
Karma: 6
Posts: 581
"Oops, try again..."
|
 |
« Reply #6 on: September 02, 2012, 03:29:32 am » |
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
|
|
|
|
|
Logged
|
The only law for me; Ohms Law: U=R*I P=U*I Note to self: "Damn! Why don't you just fix it!!!"
|
|
|
|
UK
Offline
Newbie
Karma: 0
Posts: 18
Arduino rocks
|
 |
« Reply #7 on: September 18, 2012, 06:08:13 am » |
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.htmlLook 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.
|
|
|
|
|
Logged
|
|
|
|
|
Inland Empire, California, US
Offline
Full Member
Karma: 1
Posts: 181
|
 |
« Reply #8 on: September 20, 2012, 04:03:42 am » |
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("<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(); } } }
|
|
|
|
« Last Edit: September 20, 2012, 04:19:58 am by seanz2003 »
|
Logged
|
|
|
|
|
UK
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #9 on: September 29, 2012, 07:18:12 am » |
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 .
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #10 on: September 29, 2012, 07:24:28 am » |
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("<h1>Simielk WRemote<h1>"); e.print("<h2><a href='/?d1=of'>out1off</a></h2>"); e.print("<h2><a href='/?d1=on'>out1on</a></h2>"); e.print("<h2><a href='/?d2=of'>out2off</a></h2>"); e.print("<h2><a href='/?d2=on'>out2on</a></h2>"); e.print("<h2><a href='/?d3=of'>out3off</a></h2>"); e.print("<h2><a href='/?d3=on'>out3on</a></h2>"); e.print("<h2><a href='/?d4=of'>out4off</a></h2>"); e.print("<h2><a href='/?d4=on'>out4on</a></h2>"); e.print("<h2><a href='/?d5=of'>out5off</a></h2>"); e.print("<h2><a href='/?d5=on'>out5on</a></h2>"); if (strcmp(params, "?d1=on") == 0) { byte value0=1; digitalWrite(outPin0, HIGH); e.print("<h1><a href='?d1=of'></a>1 is ON</h1>"); } else if (strcmp(params, "?d1=of") == 0) { byte value0=0; digitalWrite(outPin0, LOW); e.print("<h1><a href='?d1=on'></a>1 is OFF</h1>"); } if (strcmp(params, "?d2=on") == 0) { byte value1=1; digitalWrite(outPin1, HIGH); e.print("<h1><a href='?d2=of'></a>2 is ON</h1>"); } else if (strcmp(params, "?d2=of") == 0) { byte value1=0; digitalWrite(outPin1, LOW); e.print("<h1><a href='?d2=on'></a>2 is OFF</h1>"); } if (strcmp(params, "?d3=on") == 0) { byte value2=1; digitalWrite(outPin2, HIGH); e.print("<h1><a href='?d3=of'></a>3 is ON</h1>"); } else if (strcmp(params, "?d3=of") == 0) { byte value2=0; digitalWrite(outPin2, LOW); e.print("<h1><a href='?d3=on'></a>3 is OFF</h1>"); } if (strcmp(params, "?d4=on") == 0) { byte value3=1; digitalWrite(outPin3, HIGH); e.print("<h1><a href='?d4=of'></a>4 is ON</h1>"); } else if (strcmp(params, "?d4=of") == 0) { byte value3=0; digitalWrite(outPin3, LOW); e.print("<h1><a href='?d4=on'></a>4 is OFF</h1>"); } if (strcmp(params, "?d5=on") == 0) { byte value4=1; digitalWrite(outPin4, HIGH); e.print("<h1><a href='?d5=of'></a>5 is ON</h1>"); } else if (strcmp(params, "?d5=of") == 0) { byte value4=0; digitalWrite(outPin4, LOW); e.print("<h1><a href='?d5=on'></a>5 is OFF</h1>"); } e.respond(); } { EEPROM.write(0x00, value0); EEPROM.write(0x01, value1); EEPROM.write(0x02, value2); EEPROM.write(0x03, value3); EEPROM.write(0x04, value4); } // blink the LED. { unsigned long currentMillis = millis(); 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);} } }
|
|
|
|
« Last Edit: September 29, 2012, 07:28:24 am by simisv »
|
Logged
|
|
|
|
|
|