Please help with Modified ZoomKat

HI,
I have modified zoomkat code to my needs. Thank you Zoomkat.

what I have problem with is that when the code is loaded to arduino uno (attached to RElays) all lights comes on and I have to turn them off.

I know i’m missing a simple thing, but what should I do to this code that when loaded to Arduino, lights remain off when Arduino is turned on they are turned on by me.

I appreciate your input and guide.

//zoomkat 12-08-12
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a ’
//address will look like http://192.168.1.70:80 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605

#include <SPI.h>
#include <Ethernet.h>

byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip = { 192, 168, 1, 77 }; // ip in lan
byte gateway = { 192, 168, 1, 1 }; // internet access via router
byte subnet = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80);; //server port

String readString;

//////////////////////

void setup(){

pinMode(5, OUTPUT); //pin selected to control
pinMode(6, OUTPUT); //pin selected to control
pinMode(7, OUTPUT); //pin selected to control
pinMode(8, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println(“server text box test1”); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
if (c == ‘\n’) {

///////////////
Serial.println(readString); //see what was captured

//now output HTML data header

client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();

client.println("");
client.println("");
client.println("");
client.println("");
client.println(“My Page”);
client.println("");
client.println("");
client.println(“

Control

”);
client.println("
");
client.println("
“);
client.println(”"); //uses IP/port of web page

client.println(“Enter Code:
“);
client.println(”
“);
client.print(”<input type=submit value=‘5 ON’ style=width:100px;height:45px onClick=location.href=’/?on8;’>”);
client.print("<input type=submit value=‘5 OFF’ style=width:100px;height:45px onClick=location.href=’/?off9;’>");
client.println("
“);
client.print(”<input type=submit value=‘6 ON’ style=width:100px;height:45px onClick=location.href=’/?on8;’>");
client.print("<input type=submit value=‘6 OFF’ style=width:100px;height:45px onClick=location.href=’/?off9;’>");
client.println("
“);
client.print(”<input type=submit value=‘7 ON’ style=width:100px;height:45px onClick=location.href=’/?on8;’>");
client.print("<input type=submit value=‘7 OFF’ style=width:100px;height:45px onClick=location.href=’/?off9;’>");
client.println("
“);
client.print(”<input type=submit value=‘8 ON’ style=width:100px;height:45px onClick=location.href=’/?on8;’>");
client.print("<input type=submit value=‘8 OFF’ style=width:100px;height:45px onClick=location.href=’/?off9;’>");
client.println("
“);
client.println(”");
client.println("");
client.println("");

delay(1);
//stopping client
client.stop();

/////////////////////
if(readString.indexOf(“5”) >0)//checks for on
{
digitalWrite(5, HIGH); // set pin 5 high
Serial.println(“Led On”);
}
if(readString.indexOf(“50”) >0)//checks for off
{
digitalWrite(5, LOW); // set pin 5 low
Serial.println(“Led Off”);
}

if(readString.indexOf(“6”) >0)//checks for on
{
digitalWrite(6, HIGH); // set pin 6 high
Serial.println(“Led 6 On”);
}
if(readString.indexOf(“60”) >0)//checks for off
{
digitalWrite(6, LOW); // set pin 6 low
Serial.println(“Led 6 Off”);
}

if(readString.indexOf(“7”) >0)//checks for on
{
digitalWrite(7, HIGH); // set pin 7 high
Serial.println(“Led On”);
}
if(readString.indexOf(“70”) >0)//checks for off
{
digitalWrite(7, LOW); // set pin 7 low
Serial.println(“Led Off”);
}

if(readString.indexOf(“8”) >0)//checks for on
{
digitalWrite(8, HIGH); // set pin 8 high
Serial.println(“Led On”);
}
if(readString.indexOf(“80”) >0)//checks for off
{
digitalWrite(8, LOW); // set pin 8 low
Serial.println(“Led Off”);
}
//clearing string for next read
readString="";

}
}
}
}
}

Oooo..., you appear to have copy/pasted from several code examples and jumbled the code up some, so you may need to take a close look at what you have done.

  1. the IP address in the first info is different from the IP address in the code.
  2. all your on buttons send the same thing, and all the off buttons send the same thing.
  3. You send commands like "?on8" but look for characters like "5" and "50".
  4. The readString.indexOf logic is flawed as looking for a "5" will also be valid if "50" is received.
  5. maybe more issues

YES.
you are right. I have done alot of copying and pasting...
but even the original one that you had posted on my different post, the very original one, does the same thing, meaning
when loaded to the Uno the LED is automatically ON.

I want it to be off when Arduino is starting initially.

any idea?
thanks

This was the very basic one that I was pointed to

//zoomkat 12-08-12
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a ’
//address will look like http://192.168.1.77:80 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605

#include <SPI.h>
#include <Ethernet.h>

byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip = { 192, 168, 1, 77 }; // ip in lan
byte gateway = { 192, 168, 1, 1 }; // internet access via router
byte subnet = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80);; //server port

String readString;

//////////////////////

void setup(){

pinMode(5, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println(“server text box test1”); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
if (c == ‘\n’) {

///////////////
Serial.println(readString); //see what was captured

//now output HTML data header

client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();

client.println("");
client.println("");
client.println("");
client.println("");
client.println(“Page”);
client.println("");
client.println("");
client.println(“

head

”);
client.println("
");
client.println("
“);
client.println(”"); //uses IP/port of web page

client.println(“Enter Code:
“);
client.println(”
“);
client.println(””);
client.println("
“);
client.println(”");
client.println("");
client.println("");

delay(1);
//stopping client
client.stop();

/////////////////////
if(readString.indexOf(“TurnOn”) >0)//checks for on
{
digitalWrite(5, HIGH); // set pin 5 high
Serial.println(“Led On”);
}
if(readString.indexOf(“TurnOff”) >0)//checks for off
{
digitalWrite(5, LOW); // set pin 5 low
Serial.println(“Led Off”);
}
//clearing string for next read
readString="";

}
}
}
}
}

I just wanted it to have the LED off when it starts.
with this code it’s on when ARduino starts.

This was the very basic one that I was pointed to

That appears to be another of your copy/paste jobs (I’ve never put “apple-mobile-web-app-capable” in any code I’ve ever posted). Do you have a link to the code I actually posted? Also please read #7 below.

http://forum.arduino.cc/index.php/topic,148850.0.html

I got it from where you'd posted it:

number 6.

I got it from where you’d posted it:

And that is text box code which you have added in poor button code. In reply #1 in this discussion I told you some of the major flaws in your button code that you need to correct. If you can’t do some correction on the button code (and learn how to paste code in code tags), then your project is probably beyond your current capabilities.

+1 to zoomcat for patience above and beyond the call of duty :slight_smile: