User:Swaters3452/enes100/KnockKnockCode

// set pin numbers: const int ledPin = 13;           // the number of the LED pin const int relayPin= 12;          // the number of the Realy pin const int AnalogInputPin = A0;   // Sensor analog input pin

void setup { pinMode(ledPin, OUTPUT);        //set digital pin LED OUTPUT pinMode(relayPin, OUTPUT);     //set digital pin RELAY OUTPUT Serial.begin(9600);            //for checking input of voltage sensor when connected to PC }//end void setup

void loop { float sensorValue =0; sensorValue = analogRead(AnalogInputPin);       //Reads analog input A0 and returns value from 0 to 1023 (10 bit AD converter). //float sensorRatio= ((5*5)/1023);              //This one should have worked but didn't (5v max analog input * 5 times ratio of output to input of DC voltage sensor / 1023 max of A0 ) float sensorRatio= 22.646/1000;                 //!!!!Checking with serial monitor and using 2 batteries(1,2V & 9V) I measured their voltage with voltmeter I made this correction ratio. Before connection the diode bridge. float voltIs = (sensorValue * sensorRatio)+ 0.6; // 0.6v is a diode's bridge average threshold voltage when there is no rectifier such as this case. Serial.println(voltIs);                         // for checking voltage with serial monitor of arduino 1.0 software. delay(200);                                     // delay for 0,2 second to keep processor cool

//When push button of door is pressed a 4,5V voltage is appearing in the speaker of doorphone.

if ( voltIs > 3.95 && voltIs < 08.05)            //Speaker voltage = 6,5 volts  (yes I could have been more precise but had to make sure that door opens) { digitalWrite(ledPin,   HIGH);              //LED indication that relay circuit is closed digitalWrite(relayPin, HIGH);             //relay circuits is closed so door mechanism is on         delay (3500);                                   //Delay door opening magnetic mechanism for 3,5 seconds so that patient passes through entrance. digitalWrite(ledPin,  LOW);              // turn off Led digitalWrite(relayPin, LOW);             // relay back to NO         delay (20);                               // precaution delay } else {      sensorValue=0;                              //precaution just in case there is anomaly not to open door. voltIs = 0;                                //precaution just in case there is anomaly not to open door. } //end if voltIs

}//end void loop