#include #include LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); const int Led_Lamp = 12; // choose the pin for the LED const int Led_Fan = 11; // choose the pin for the LED const int Led_Right = 3; // choose the pin for the LED const int Led_Left = 5; // choose the pin for the LED //*************************Constants - Push Button***************************************** const int buttonPin1 = 7; // The pin that the pushbutton is attached to const int buttonPin2 = 8; // The pin that the pushbutton is attached to const int buttonPin3 = 10; // The pin that the pushbutton is attached to //For Button1 int buttonLed = 0; // current state of the button_Lamp //For Button2 int buttonAir = 0; // current state of the button_Fan //For Button3 int buttonClass = 0; // current state of the button_Lesson //*************************Constants - Class Interruption*********************************** //For Sound_Sensor1 int soundsensor1 = 2; // choose the input pin (for Sound_Sensor1) //For Sound_Sensor2 int soundsensor2 = 4; // choose the input pin (for Sound_Sensor2) int StatusSize1 = 0; // choose the status (for Led_Right) int StatusSize2 = 0; // choose the status (for Led_Left) //*************************Constants - InfraRed Sensor*************************************** //For Infra_Red1 int IR1 = A1; // choose the input pin (for Infra_Red1) //For Infra_Red2 int IR2 = A2; // choose the input pin (for Infra_Red2) int count = 0; //*************************Constants - Sound Sensor****************************************** int statusSensor = 0; //*************************Constants - PIR Sensor******************************************** //For PIR_Sensor1 int PIR_Sensor1 = 6; // choose the input pin (for PIR_Sensor1) //For PIR_Sensor2 int PIR_Sensor2 = 9; // choose the input pin (for PIR_Sensor2) int pirState = LOW; int val = 0; // variable for reading the pin status //************************Constants - IF Statement********************************************** int LampState = LOW; int FanState = LOW; unsigned long previousMillis = 0; const long interval = 600000; //Time to wait after 10 minutes unsigned long previousMillis2 = 0; const long interval2 = 900000; //Time to wait after 15 minutes int NDelay = 0; //*********************************************************************************************** void ENTER_DOOR() { if( digitalRead(IR1) == HIGH ) { count++; lcd.clear(); lcd.print("Students In Class:"); lcd.setCursor(0,1); lcd.print(count); delay(2000); // count of time that you want stay in the door } } void EXIT_DOOR() { if( digitalRead(IR2) == HIGH ) { count--; lcd.clear(); lcd.print("Students In Class:"); lcd.setCursor(0,1); lcd.print(count); delay(2000); // count of time that you want stay in the door } } void Class_Interruption() { StatusSize1 = digitalRead(soundsensor1); if(StatusSize1 == LOW) { digitalWrite(Led_Right, HIGH); } else { digitalWrite(Led_Right, LOW); } StatusSize2 = digitalRead(soundsensor2); if(StatusSize2 == LOW) { digitalWrite(Led_Left, HIGH); } else { digitalWrite(Led_Left, LOW); } } void Print_Led() { lcd.clear(); lcd.setCursor(4,4); lcd.print("NOW LEARNING!"); delay(48); } void Sound_Sensor() { statusSensor = (digitalRead(soundsensor1) || digitalRead(soundsensor2)) ; // read input value if(statusSensor == LOW) { digitalWrite(Led_Lamp, HIGH); } else { digitalWrite(Led_Lamp, LOW); } } void PIR_Motion() { val = (digitalRead(PIR_Sensor1) || digitalRead(PIR_Sensor2)); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(Led_Lamp, HIGH); // turn LED ON if (pirState == LOW) { pirState = HIGH; } }else { digitalWrite(Led_Lamp, LOW); // turn LED OFF if (pirState == HIGH) { pirState = LOW; } } } //***************************************************************** void setup() { //*****************************Push Button************************* pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(Led_Lamp, OUTPUT); pinMode(Led_Fan, OUTPUT); //*****************************Class Interruption******************* pinMode(buttonPin3, INPUT); pinMode(soundsensor1, INPUT); // declare sensor as input pinMode(soundsensor2, INPUT); // declare sensor as input pinMode(Led_Right, OUTPUT); pinMode(Led_Left, OUTPUT); //******************************InfrRed Sensor********************** lcd.begin(16,2); lcd.setCursor(2,4); lcd.print("Smart Classroom"); delay(3000); pinMode(IR1, INPUT); pinMode(IR2, INPUT); lcd.clear(); lcd.print("Students In Class:"); lcd.setCursor(0,1); lcd.print(count); //******************************PIR Sensor*************************** pinMode(PIR_Sensor1, INPUT); // declare sensor as input pinMode(PIR_Sensor2, INPUT); // declare sensor as input pinMode(Led_Lamp, OUTPUT); digitalWrite(Led_Lamp, LOW); //******************************************************************* } void loop() { if ( digitalRead(IR1) == HIGH ) ENTER_DOOR(); if ( digitalRead(IR2) == HIGH ) EXIT_DOOR(); if( count <= 0 ) { lcd.clear(); lcd.setCursor(2,4); lcd.print("Nobody In Class"); delay(200); } buttonLed = digitalRead(buttonPin1); if ( buttonLed == HIGH ) { // turn LED on: digitalWrite(Led_Lamp, HIGH); } else { // turn LED off: digitalWrite(Led_Lamp, LOW); } buttonAir = digitalRead(buttonPin2); if ( buttonAir == HIGH ) { // turn LED on: digitalWrite(Led_Fan, HIGH); } else { // turn LED off: digitalWrite(Led_Fan, LOW); } buttonClass = digitalRead(buttonPin3); if ( buttonClass == HIGH ) { Print_Led(); Class_Interruption(); ENTER_DOOR(); EXIT_DOOR(); if( count <= 0 ) { lcd.clear(); delay(200); // it was 2000 } buttonLed = digitalRead(buttonPin1); if ( buttonLed == HIGH ) { // turn LED on: digitalWrite(Led_Lamp, HIGH); } else { // turn LED off: digitalWrite(Led_Lamp, LOW); } buttonAir = digitalRead(buttonPin2); if ( buttonAir == HIGH ) { // turn LED on: digitalWrite(Led_Fan, HIGH); } else { // turn LED off: digitalWrite(Led_Fan, LOW); } if ( digitalRead(Led_Lamp) == HIGH && digitalRead(Led_Fan) == HIGH ) { digitalWrite(Led_Lamp, LOW); digitalWrite(Led_Fan, LOW); //delay(48); } if ( digitalRead(buttonPin3) == LOW ) { digitalWrite(Led_Right, LOW); digitalWrite(Led_Left, LOW); digitalWrite(Led_Lamp, LOW); digitalWrite(Led_Fan, LOW); } } while ( digitalRead(Led_Lamp) == HIGH && digitalRead(Led_Fan) == HIGH && digitalRead(buttonPin3) == HIGH ) { buttonClass = digitalRead(buttonPin3); if ( buttonClass == HIGH ) { Class_Interruption(); Print_Led(); } } if (count == 0) { digitalWrite(Led_Lamp, LOW); digitalWrite(Led_Fan, LOW); } //*********************************************************************************************************************************************************************// if ( digitalRead(PIR_Sensor1) == HIGH || digitalRead(PIR_Sensor2) == HIGH || digitalRead(soundsensor1) == LOW || digitalRead(soundsensor2) == LOW) { digitalWrite(Led_Lamp, HIGH); digitalWrite(Led_Fan, HIGH); } else if ( digitalRead(PIR_Sensor1) == LOW || digitalRead(PIR_Sensor2) == LOW || digitalRead(soundsensor1) == HIGH || digitalRead(soundsensor2) == HIGH) { digitalWrite(Led_Lamp, LOW); digitalWrite(Led_Fan, LOW); } //*********************************************************************************************************************************************************************// NDelay = 0; while( ( (digitalRead(buttonPin1) == HIGH || digitalRead(buttonPin2) == HIGH || digitalRead(buttonPin3) == HIGH ) && digitalRead(PIR_Sensor1) == LOW && digitalRead(PIR_Sensor2) == LOW && digitalRead(soundsensor1) == HIGH && digitalRead(soundsensor2) == HIGH && count >= 0 ) && ( NDelay < 220 ) ) { NDelay++; if ( digitalRead(IR1) == HIGH ) { ENTER_DOOR(); } if ( digitalRead(IR2) == HIGH ) { EXIT_DOOR(); } if( count > 0 ) { buttonLed = digitalRead(buttonPin1); if ( buttonLed == HIGH ) { // turn LED on: digitalWrite(Led_Lamp, HIGH); } else { // turn LED off: digitalWrite(Led_Lamp, LOW); } buttonAir = digitalRead(buttonPin2); if ( buttonAir == HIGH ) { // turn LED on: digitalWrite(Led_Fan, HIGH); } else { // turn LED off: digitalWrite(Led_Fan, LOW); } buttonClass = digitalRead(buttonPin3); if ( buttonClass == HIGH ) { Print_Led(); Class_Interruption(); } } delay(100); if( NDelay == 200 ) { int val1 = digitalRead(Led_Lamp); if ( val1 == HIGH ) { digitalWrite(Led_Lamp, LOW); } int val2 = digitalRead(Led_Fan); if ( val2 == HIGH ) { digitalWrite(Led_Fan, LOW); } lcd.clear(); lcd.setCursor(1,4); lcd.print ("Resetting Counter"); delay(4000); //Time to wait after 4 seconds lcd.clear(); lcd.print("Students In Class:"); count = 0; lcd.setCursor(0,1); lcd.print(count); lcd.setCursor(2,4); lcd.clear(); exit; } } if ( count == 0 ) { digitalWrite(Led_Lamp, LOW); digitalWrite(Led_Fan, LOW); } //*********************************************************************************************************************************************************************// if ( digitalRead(PIR_Sensor1) == HIGH || digitalRead(PIR_Sensor2) == HIGH || digitalRead(soundsensor1) == LOW || digitalRead(soundsensor2) == LOW) { digitalWrite(Led_Lamp, HIGH); digitalWrite(Led_Fan, HIGH); } else if ( digitalRead(PIR_Sensor1) == LOW || digitalRead(PIR_Sensor2) == LOW || digitalRead(soundsensor1) == HIGH || digitalRead(soundsensor2) == HIGH) { digitalWrite(Led_Lamp, LOW); digitalWrite(Led_Fan, LOW); } //*********************************************************************************************************************************************************************// }