I am doing smart room automation system. I am getting this error when I tried to compile the code and also just for the test I tried to ping one LED when I switch ON it LED is becoming on but when I try to off it does not work.
#include <SPI.h>
#include <Ethernet.h>
#include<Servo.h>
//new #include<Servo.h>
// new Servo myServo
Servo myServo;
//light pin9
//fan pi22
//garage door pin24
// Set the MAC address
int pos=0;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
//78-31-C1-C5-3D-C8
// Set the IP address
IPAddress ip(192, 168, 1, 14);
// Start a server at port 80 (http)
EthernetServer server(80);
void setup() {
// Open serial communications
Serial.begin(9600);
// start the Ethernet connection and the server
Ethernet.begin(mac, ip);
server.begin();
// Pin 22 - 24 output (leds)
pinMode(22, OUTPUT);
pinMode(9, OUTPUT);
myServo.attach(24);
//new myServo.attach(24);
}
void loop() {
// Check if client connected
EthernetClient client = server.available();
if (client) { // If there is a client...
boolean currentLineIsBlank = true;
String buffer = ""; // A buffer for the GET request
while (client.connected()) {
if (client.available()) {
char c = client.read();// Read the data of the client
buffer += c; // Store the data in a buffer
if (c == '\n' && currentLineIsBlank) {// if 2x new line ==> Request ended
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println(); // Blank line ==> end response
break;
}
if (c == '\n') { // if New line
currentLineIsBlank = true;
buffer = ""; // Clear buffer
}
else if (c == '\r') { // If cariage return...
if(buffer.indexOf("GET /?led2=1")>=0) { // If led2 = 1
digitalWrite(22, HIGH); // led 2 > on
}
if(buffer.indexOf("GET /?led2=0")>=0) { // If led2 = 0
digitalWrite(22, LOW); // led 2 > off
}
if(buffer.indexOf("GET /?led3=1")>=0) { // If led3 = 1 for light
digitalWrite(9, HIGH); // led 3 > on
}
if(buffer.indexOf("GET /?led3=0")>=0) { // If led3 = 0
digitalWrite(9, LOW); // led 3 > off
}
//new
if (buffer.indexOf("GET /?led1=1")>=0) {
for (pos = 0; pos < 105; pos += 3) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myServo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (buffer.indexOf("GET /?led1=0")>=0) {
for (pos = 105; pos >= 0; pos -= 3) // goes from 180 degrees to 0 degrees
{
myServo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
// end new
//Read in the buffer if there was send "GET /?message=..."
if(buffer.indexOf("GET /?message=")>=0) {
if(buffer.indexOf("switch on the light")>=0) {
digitalWrite(9, HIGH);
}
if(buffer.indexOf("switch on the fan")>=0) {
digitalWrite(22, HIGH);
}
if(buffer.indexOf("open the garage")>=0){
for (pos = 0; pos < 105; pos += 3) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myServo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if(buffer.indexOf("switch off the light")>=0) {
digitalWrite(9, LOW);
}
if(buffer.indexOf("switch off the fan")>=0) {
digitalWrite(22, LOW);
}
if(buffer.indexOf("close the garage")>=0){
for (pos = 105; pos >= 0; pos -= 3) // goes from 180 degrees to 0 degrees
{
myServo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
} //else closed
else {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}