Thanks for the direction. I ended up scraping that code and modifying another one. This one works much better. There are no sensors yet, but I imagined using some type of magnetic switch or micro-switch, which would be digital! So you are right. I can just change the pins for that.
Here is the final web server code which will run on the arduino with an ethernet shield. Has two sensor inputs A0 and A1 and two outputs, pins 2 and 3. Web buttons control the digital pins. I got it scaled correct for a android and iphone. No webserver needed, just the arduino and router. Has no auto refresh, but I think I may add it and ditch the refresh button.
Anyway, posted for someone else to use as a base for some home automation.
#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;
////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte ip[] = { 192, 168, 1, 30 }; //Manual setup only
byte gateway[] = { 192, 168, 1, 1 }; //Manual setup only
byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only
// if need to change the MAC address (Very Rare)
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xC2, 0x52 };
EthernetServer server = EthernetServer(80); //port 80
////////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(9600);
//Pins 10,11,12 & 13 are used by the ethernet shield
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
Ethernet.begin(mac, ip, gateway, subnet); //for manual setup
server.begin();
Serial.println(Ethernet.localIP());
}
void loop(){
// listen for incoming clients, and process qequest.
checkForClient();
}
void checkForClient(){
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean sentHeader = false;
while (client.connected()) {
if (client.available()) {
if(!sentHeader){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<meta name='viewport' content='width = 320' />");
client.println("<meta name='viewport' content='initial-scale=1, user-scalable=no' />");
client.println("<h2><center>Garage Door Control</h2></center>");
client.println("<center><input type=button onClick=location.href='http://192.168.1.30' value='Update Status'></center>");
client.print("<br>");
int door1status = analogRead(A0);
int door2status = analogRead(A1);
if (door1status < 10){client.println("<center>Kristen's door is closed</center>");}
if (door1status >= 10){client.println("<center>Kristen's door is <b>OPEN!</b></center>");}
client.println("<center><input type=button onClick=location.href='http://192.168.1.30/?2' value='Activate Kristen's Door'></center><br>");
if (door2status < 10){client.println("<center>Mike's door is closed</center>");}
if (door2status >= 10){client.println("<center>Mike's door is <b>OPEN!</b></center>");}
client.println("<center><input type=button onClick=location.href='http://192.168.1.30/?3' value='Activate Mike's Door'></center><br>");
client.println("<center><input type=button onClick=location.href='http://192.168.1.30/?23' value='Activate Both Doors'></center><br>");
sentHeader = true;
}
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true; //found the ?, begin reading the info
if(reading){
Serial.print(c);
switch (c) {
case '2':
//add code here to trigger on 2
triggerPin(2, client);
break;
case '3':
//add code here to trigger on 3
triggerPin(3, client);
break;
}
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n') {
currentLineIsBlank = true;
break;
}else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}
void triggerPin(int pin, EthernetClient client){
//blink a pin - Client needed just for HTML output purposes.
digitalWrite(pin, HIGH);
delay(250);
digitalWrite(pin, LOW);
}