hye guys, i dont event know what am i typing here but seems like i got prob with my arduino its either the board itself or the programming.. ok im now trying to develop the home controller which can control the light the fan and adding the additional feature for security which is PIR sensor and buzzer as alarm controll directly from web page using the html code. im using the Arduino uno r3 + Ethernet shield w5200 v1.0 . when ever i tried to compiled i got the error such as 'Ethernet' was not declared in this scope is it because i change the libraries from arduino ide w5100 to 5200.blur
#include <SPI.h>
#include <Ethernet.h>
//ethernet configuration
byte ip[] = { 192, 168, 0, 13};
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(27);
//initial
int LED=8; //led is connected to digital pin 4
int PIR=3; //PIR sensor is connected to digital pin 3
int LDR=5; //LDR sensor is connected to analog in 5
int LAMP=4; //LAMP is conected to digital pin 2
int FAN=9; //FAN is connected to digital pin 9
int BUZZER=2; //BUZZER is connected to digital pin 8
int PIRstate=0; //ariable for PIR sensor status
int lampstate=0; //variable for LAMP status
int fanstate=0; //ariable for FAN status
float photocell=0; //variable for photocell (LDR) analog value
char c=0; //received data
char command[2]= "\0"; //command
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
pinMode(LED,OUTPUT);
pinMode(LAMP,OUTPUT);
pinMode(PIR,INPUT);
pinMode(FAN,OUTPUT);
pinMode(BUZZER,OUTPUT);
}
void loop()
{
EthernetClient client=server.available();
//detect if current is the first line
boolean current_line_is_first=true;
if(client)
{
//an http request ends with a blank line
boolean current_line_is_blank= true;
while (client.connected())
{
if (client.available())
{
char c=client.read();
//if we've gotten to the end of the line(receive a newline character)
//and the line is blank, the http request has ended,
//so we can send a reply
if(c=='\n'&¤t_line_is_blank)
{
//send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("");
//auto reload webpage every 5 second
client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");
//webpage title
client.println("");
client.println("
client.println("
WELCOME HOME!!
"); //read analog pin 1 for the alue of photocell photocell=analogRead(LDR); if(photocell<40) { digitalWrite(LED,HIGH); } else { digitalWrite (LED,LOW); } client.print("LDR SENSOR:
Light Intensity= "); client.println(photocell,2); client.println("
"); //read digital pin 13 for the state of PIR sensor client.println("SECURITY SYSTEM:"); client.println(""); client.println("PIR On"); client.println("PIR Off"); client.println(" ");
client.println("intruder detection=");
if(PIRstate==HIGH)//PIR sensor detected movement
{
client.println("Motion Detected!");
}
else //No movement is detected
{
client.println("No Movement");
}
if(PIRstate==HIGH)
{
//PIR sensor detected movement
unsigned char i;
for(i=0;i<25;i++)
{
digitalWrite(BUZZER,HIGH);
delay(100); //Delay 1ms
digitalWrite(BUZZER,LOW);
delay(100); //Delay 1ms
}
}
else // NO MOVEMENT IS DETECTED
{
digitalWrite(BUZZER,LOW);
}
client.println("
");
//button functions
client.println("APPLIANCES:
");
client.println("");
client.println("LAMP On");
client.println("LAMP Off");
client.println("");
client.println("FAN high");
client.println("FAN low");
client.println("FAN off");
client.println("
"); client.println("APPLIANCES CONDITION:"); lampstate=digitalRead(2); client.print("
LAMP:"); if(lampstate==HIGH) { client.println("ON "); } else { client.println("OFF "); } client.print("FAN :"); if (!strcmp(command, "5")) { analogWrite(FAN,244); client.println("ON
"); } else if(!strcmp(command, "6")) { analogWrite(FAN,57); client.println("ON "); } else if (!strcmp(command, "7")) { analogWrite(FAN,0); client.println("OFF ");}
else if(fanstate==0)
{
client.println("OFF
break;
}
if(c== '\n')
{
//we're starting a new line
current_line_is_first= false;
current_line_is_blank= true;
}
else if(c != '\r')
{
//we'e gotten a character on the current line
current_line_is_blank = false;
}
//get the first http request
if(current_line_is_first && c == '=')
{
for(int i=0;i<1;i++)
{
c=client.read();
command*=c;*
-
}*
-
//LED control*
-
if(!strcmp(command,"3"))*
-
{*
-
digitalWrite(LAMP,HIGH);*
-
}*
-
else if(!strcmp(command,"4"))*
-
{*
-
digitalWrite(LAMP,LOW);*
-
}*
-
if(!strcmp(command,"1"))*
-
{*
-
PIRstate=digitalRead(PIR);*
-
}*
-
else if(!strcmp(command,"2"))*
-
{*
-
PIRstate=0;*
-
}*
-
}*
-
}*
-
}*
-
//give the web browser time to receive the data*
-
delay(1);*
-
client.stop();*
-
}*
-
}*