#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 Sound_Sensor1 = 2; // choose the input pin (for Sound_Sensor1) //For Sound_Sensor2 int Sound_Sensor2 = 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; int NDelay1 = 0; int NDelay2 = 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(Sound_Sensor1); if (StatusSize1 == LOW) { digitalWrite(Led_Right, HIGH); } else { digitalWrite(Led_Right, LOW); } StatusSize2 = digitalRead(Sound_Sensor2); 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(Sound_Sensor1) || digitalRead(Sound_Sensor2)) ; // 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(Sound_Sensor1, INPUT); // declare sensor as input pinMode(Sound_Sensor2, 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); } //*********************************************************************************************************************************************************************// NDelay1 = 0; while ( ( digitalRead(ButtonPin1) == HIGH || digitalRead(ButtonPin2) == HIGH ) && ( digitalRead(PIR_Sensor1) == HIGH || digitalRead(PIR_Sensor2) == HIGH || digitalRead(Sound_Sensor1) == LOW || digitalRead(Sound_Sensor2) == LOW ) && ( NDelay1 < 660 ) ) { NDelay1++; if ( ( NDelay1 == 600 ) && ( Count == 0 ) ) { digitalWrite(Led_Lamp, HIGH); } } //*********************************************************************************************************************************************************************// NDelay = 0; while ( ( (digitalRead(ButtonPin1) == HIGH || digitalRead(ButtonPin2) == HIGH || digitalRead(ButtonPin3) == HIGH ) && digitalRead(PIR_Sensor1) == LOW && digitalRead(PIR_Sensor2) == LOW && digitalRead(Sound_Sensor1) == HIGH && digitalRead(Sound_Sensor2) == 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); } //*********************************************************************************************************************************************************************// NDelay2 = 0; while ( ( digitalRead(ButtonPin1) == HIGH || digitalRead(ButtonPin2) == HIGH ) && ( digitalRead(PIR_Sensor1) == HIGH || digitalRead(PIR_Sensor2) == HIGH || digitalRead(Sound_Sensor1) == LOW || digitalRead(Sound_Sensor2) == LOW ) && ( NDelay2 < 660 ) ) { NDelay2++; if ( ( NDelay2 == 600 ) && ( Count == 0 ) ) { digitalWrite(Led_Lamp, HIGH); } } //*********************************************************************************************************************************************************************// }