boolean check_garage_door_status(char ccc) { boolean avoidance_sensor_status = false; // garage door close is false, true is open boolean distance_status = false; // garage door close is false, true is open // we are adding the distance snsor here 06.12.2014 The pins used are 4 and 8 // black is echo pin to pin 3 // brown is trig pin to pin 8 float daverage = 0.0000; long distance_value = 0; float distance_total = 0.0; int ii = 0; for(ii=0;ii<50;ii++) { distance_value = avg_loop(); if (distance_value == 0) ii--; distance_total += distance_value; delay(1); } // Serial << "number of sample collected was " << ii << endl; daverage = distance_total / ii; Serial << "The average was " << daverage << endl; if (daverage < 156) {distance_status = true;} /* // check 5 times the reading from A5 float average = 0.0000; boolean statusA5 = false; // open is true close is false boolean statusA4 = false; // open is true close is false average = check_average(A4); if (average > 0.04) statusA4 = true; else statusA4 = false; average = check_average(A5); if (average <= 0.04) statusA5 = true; else statusA5 = false; */ // check the reading from avoidance sensor if (ls_val = digitalRead(Ls)) avoidance_sensor_status = false; // closed else avoidance_sensor_status = true; //open // Serial << "Avoidance Sensor 1=open 0 =close " << avoidance_sensor_status; if (avoidance_sensor_status) Serial << "Garage is Open. " << avoidance_sensor_status << endl; else Serial << "Garage is Closed. " << avoidance_sensor_status << endl; // end of avoidance check // if ((statusA5 != statusA4) || (statusA5 != distance_status) || (statusA5 != avoidance_sensor_status)) // if they do not agree we got problem if (distance_status != avoidance_sensor_status) { String error_system = "Are we having positioning error? Two sensors do not agree. But I will go with distance_status. "; // for test only we will not send email error_system = error_system + daverage + "avoidance_sensor_status " + avoidance_sensor_status; Serial << error_system << endl; Serial << "daverage " << daverage << "distance_status " << distance_status << endl; Serial << "avoidance_sensor_status " << avoidance_sensor_status << endl; Serial << "Please investigate ..." << endl; // do not email error if they do not agree // set_body(error_system); // } // if (statusA5) // door is open if (distance_status) // was if (statusA5) // door is open { //current_status = true; Serial << "The average reading is " << daverage << endl; Serial.println(F("Your Garage door is Open ... daverage < 156")); if(ccc == '0'){ // check status only return true; } if(ccc == '1'){ Serial.println(F("Your Garage door is already Open ..."));} else {Serial.println(F("I will CLOSE Garage door later ...")); action_to_Open_or_Close(); // last_open_time = 0; } // for now // pinMode(relayPin6, INPUT); // check to see if this will resolve the other remote oissues. // send_a_page(); return true; } else // statusA5 is false door is closed { //current_status = false; // the door is closed last_open_time = 0; // the door is currently closed ???? // Serial << " last_open_time was set to 0 here." << millis() << endl; if(ccc == '0'){ // check status only return false; } Serial.println(F("Your Garage door is Closed ! daverage > 156")); if(ccc == '2'){ Serial.println(F("Your Garage door is already Closed ..."));} else {Serial.println(F("I will OPEN Garage door later ...")); action_to_Open_or_Close(); } // for now // pinMode(relayPin6, INPUT); // check to see if this will resolve the other remote oissues. //send_a_page(); return false; // we must return saying the door is closed even if we will open it } } void action_to_Open_or_Close() { // last_open_time = 0; // Serial << " last_open_time was set to 0 here." << millis() << endl; if (!check_garage_door_status('0')) // garage door is currently closed and we will open it { last_open_time = millis(); Serial << " last_open_time was set to current time here. " << last_open_time << endl; set_body("Arduino Email: I will open it. Reset last_open_time to current time. "); } else // the door is open we are closing it. { Serial << " last_open_time was set to 0 here since I am going to close it." << last_open_time << endl; last_open_time = 0; set_body("Arduino Email: I will close it. Reset last_open_time to 0. "); } Serial.println(millis()); pinMode(relayPin6, OUTPUT); digitalWrite(relayPin6, HIGH); delay(1000); digitalWrite(relayPin6, LOW); delay(5000); pinMode(relayPin6, INPUT); // check to see if this will resolve the other remote oissues. // send_a_page(); }