you are right , I have noticed it just now and fix it.
now it is almost working like I want to.
2 more things I want to know how to do
- I want the redLED will be on from 5 sec. where do I need to put the delay?
now the led is not stable when there is a movement. - I want that the error message will be written in the side - I need to get the RTC next week and I want to when ever there is a movement it will "save" me the time .
this is the code so far :
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,0,0,155); // ip in lan
EthernetServer server(80); //server is using port 80
int PIRChannel=4;
int GreenLED=7;
int RedLED=9
;
int d;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
pinMode(GreenLED,OUTPUT);
pinMode(RedLED,OUTPUT);
pinMode(PIRChannel,INPUT);
}
void loop()
{
pir_cheak();
if (d==0)
{
digitalWrite(GreenLED,HIGH); // No Movement - green LED
digitalWrite(RedLED,LOW);
}
else
{
digitalWrite(RedLED, HIGH);
digitalWrite(GreenLED,LOW);
}
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// see if HTTP request has ended with blank line
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//meta-refresh page every 1 seconds
client.println("<HTML>");
client.print("<HEAD>");
client.print("<meta http-equiv=\"refresh\" content=\"1\">");
client.print("<TITLE /> Test</title>");
client.print("</head>");
client.println("<BODY>");
client.print("autorefresh test ");
client.println("
");
// printing the message
if
(d==0)
{
client.print("All Good - No Movement");
client.print("
");
}
else
{
client.print("Warning - Movement");
client.print("
");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
int pir_cheak()
{
if (digitalRead(PIRChannel) ==HIGH) // no movement - Green LED
{
digitalWrite(RedLED, LOW);
digitalWrite(GreenLED,HIGH);
Serial.println ("no move!!!");
d=0;
// Serial.println(d);
}
else
{
digitalWrite(GreenLED,LOW); // Movement - Red LED
digitalWrite(RedLED,HIGH);
Serial.println ("Move!!!");
d=1;
return d;
}
}
thanks