GOAL:
I am making a web controlled gate/garage opener, and it is working: user goes to a web page, "pushes" the button, and the Arduino triggers the opener button for one second, as indicated on the handheld opener. (We are using web security cameras to verify state of gate)
HARDWARE:
Arduino Uno R3
Arduino Ethernet Shield 2 (IP 192.168.0.48)
J-Deal 4-channel Relay Module
Garage door opener with open button soldered to Relay
PROBLEM:
My issue is when the Arduino has been powered off, and then comes back on (using my laptop USB), the "button" is in a constant closed state, i.e. is being pushed -the LED on the opener is just getting hammered.
To stop this, I load up the web page, "push" the button, and then the button circuit goes to open state and from then on the project all works as intended.
I need to make sure if the power goes off out at the location that when it comes back one, the gate doesn't open!
SETUP:
The code is from this site:
and shown below, modified by me at lines 96,99.
I reversed the HIGH and LOW because when shown as listed, the system worked in reverse. The button was being pushed the whole time.
Separate hosted web page with button
<a href="http://192.168.0.48/?flashgarage"><input type="button" value="Push Gate Button" class="classname"></a>
Web code on Arduino
//
#include <Ethernet2.h>
#include <SPI.h>
// NETWORK SETTINGS
//MAC ADDRESS
int port = 84;byte mac[] =
{ 0x90, 0xA2, 0xDA, 0x10, 0x30, 0xE7 };
// DEVICE IP ADDRESS
byte ip[] = { 192, 168, 0, 48};
// code from site
// byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x30, 0xE7 };
// byte gateway[] = { 192, 168, 0, 1 };
// byte subnet[] = { 255, 255, 255, 0 };
// IPAddress ip(192, 168, 0, 48); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
// SET ETHERNET PROPERTIES
//EthernetServer server(port);
EthernetClient client;
// VARIABLES
// READSTRING FOR ETHERNET READ
String readString;
int garageDoor = 2; // RELAY PIN
// ********** START CODE **********
void setup(){
// SET RELAY PIN AS OUTPUT
pinMode(garageDoor, OUTPUT);
// ETHERNET CONNECTION
Ethernet.begin(mac, ip);
server.begin();
//PRINT TO SERIAL
Serial.begin(9600);
// PROJECT NAME
Serial.println("GARAGE CONTROLLER");
// IP ADDRESS
Serial.print("IP Address: ");
// IP ADDRESS
Serial.print(Ethernet.localIP());
Serial.print(":");
Serial.println(port); // PORT
// EVERYTHING IS LOADED - WAIT FOR REQUESTS
Serial.println("Ready for requests...");
Serial.println();
}
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 UNTIL FINISHED
if (readString.length() < 100) {
// SAVE EACH CHAR TO STRING
readString += c;
}
// WHEN END OF READ IS REACHED, PARSE
if (c == '\n') {
// DISPLAY NEW PAGE
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE html>");
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Garage Control</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
// CHECK TO SEE IF GARAGE DOOR REQUEST
// WAS SENT
if(readString.indexOf("flashgarage") >0) {
// "flashgarage" IS QUERY STRING KEYWARD
// SET RELAY PIN TO HIGH toddlg: I changed the value below to LOW
digitalWrite(garageDoor, LOW);
delay(1000); // WAIT
// SET RELAY PIN TO LOW toddlg: I changed the value below to HIGH
digitalWrite(garageDoor, HIGH);
// PRINT TO SERIAL
Serial.println("Garage Door Opened.");
}
// END PAGE
client.println("
<center><h1>Button Pushed</h1>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
client.stop();
Serial.println ("------------------------- -------------------------");
//clearing string for next read
readString="";
}
}
}
}
}
I suspect there is some element missing at startup that says "Arudino, keep this circuit open until you get instructions otherwise" but I do not know what this would look like - is it Arduino, or some HTML querystring.
Let me know if there is any more information needed to troubleshoot.
Thanks,
Todd
P.S. This is my first Arduino project. I have a background in IT but low voltage electronics are new, and I am having fun using my my multimeter and testing it out.