Smart Office Automation
Smart Office Automation seamlessly integrates IoT, AI, and cloud technologies to create intelligent, adaptive workspaces that boost productivity, energy efficiency, and user experience.
Components and supplies
1
an old cooling fan
1
NodeMCU ESP8266
1
16x4 I2C LCD Screen
1
Arduino Uno Rev3
1
PIR Sensor
1
Bulb (as a warm body)
1
RFID Module
1
12V adapter
1
4 relay module 5VDC 10A (assembled)
Apps and platforms
1
Arduino IDE
1
Chrome
1
Arduino IoT Cloud
1
Firebase
1
VSCODE
Project description
Code
ESP8266 code
cpp
--
1// Includes 2#include <SPI.h> 3#include <Wire.h> 4#include <MFRC522.h> 5#include <LiquidCrystal_I2C.h> 6#include <ESP8266WiFi.h> 7#include <WiFiClient.h> 8 9// Pin Definitions 10#define RST_PIN D3 11#define SS_PIN D4 12#define LED D8 13 14// RFID, LCD, and Network Setup 15MFRC522 mfrc522(SS_PIN, RST_PIN); 16MFRC522::MIFARE_Key key; 17LiquidCrystal_I2C lcd(0x27, 16, 4); 18 19// WiFi Credentials 20const char* ssid = "Arpit's Galaxy M14 5G"; 21const char* password = "whsshcp77"; 22 23// Server Settings 24const char* serverIP = "192.168.36.152"; // Change to your local server's IP 25const int serverPort = 80; // Standard HTTP port 26 27// Block and Buffer 28int blockNum = 2; 29byte bufferLen = 18; 30byte readBlockData[18]; 31 32void setup() { 33 Serial.begin(9600); 34 35 // Initialize LCD 36 Wire.begin(D2, D1); 37 lcd.init(); 38 lcd.backlight(); 39 lcd.clear(); 40 lcd.setCursor(0, 0); 41 lcd.print("Initializing..."); 42 delay(2000); 43 44 // Connect to WiFi 45 WiFi.begin(ssid, password); 46 while (WiFi.status() != WL_CONNECTED) { 47 Serial.print("."); 48 delay(500); 49 } 50 Serial.println("\nWiFi connected."); 51 lcd.clear(); 52 lcd.setCursor(0, 0); 53 lcd.print("WiFi Connected!"); 54 55 pinMode(LED, OUTPUT); 56 SPI.begin(); 57 mfrc522.PCD_Init(); 58} 59 60void loop() { 61 lcd.clear(); 62 lcd.setCursor(0, 0); 63 lcd.print("Scan your Card"); 64 65 if (!mfrc522.PICC_IsNewCardPresent()) return; 66 if (!mfrc522.PICC_ReadCardSerial()) return; 67 68 ReadDataFromBlock(blockNum, readBlockData); 69 70 lcd.clear(); 71 lcd.setCursor(0, 0); 72 String name = String((char*)readBlockData); 73 if (name=="2240135") { 74 lcd.print("Hello, Pallavi"); 75 } else if (name=="2240153") { 76 lcd.print("Hello, Velan"); 77 } else if (name=="2240155") { 78 lcd.print("Hello, Sahil"); 79 } else if (name=="2240156") { 80 lcd.print("Hello, Arpit"); 81 } else { 82 lcd.print("Invalid User"); 83 } 84 85 digitalWrite(LED, HIGH); 86 delay(500); 87 digitalWrite(LED, LOW); 88 89 sendAttendanceData((char*)readBlockData); 90 91 // *Fix: Halt the RFID reader properly* 92 mfrc522.PICC_HaltA(); 93 mfrc522.PCD_StopCrypto1(); 94 Serial.println("RFID scan halted, ready for next card..."); 95 96 delay(3000); // Allow time before scanning a new card 97} 98 99void sendAttendanceData(String cardName) { 100 WiFiClient client; 101 102 Serial.print("Connecting to server: "); 103 Serial.print(serverIP); 104 Serial.print(":"); 105 Serial.println(serverPort); 106 107 if (client.connect(serverIP, serverPort)) { 108 Serial.println("Connected to server."); 109 110 // HTTP Request 111 String url = "/Smart_office/rfid_login.php?user_id=" + cardName; 112 113 client.print("GET " + url + " HTTP/1.1\r\n"); 114 client.print("Host: " + String(serverIP) + "\r\n"); 115 client.print("Connection: close\r\n\r\n"); 116 117 delay(500); // Give server time to respond 118 119 // Read response 120 while (client.available()) { 121 String line = client.readStringUntil('\r'); 122 Serial.print(line); 123 } 124 125 Serial.println("\nRequest complete."); 126 client.stop(); 127 } else { 128 Serial.println("Connection to server failed."); 129 } 130} 131 132void ReadDataFromBlock(int blockNum, byte readBlockData[]) { 133 for (byte i = 0; i < 6; i++) { 134 key.keyByte[i] = 0xFF; 135 } 136 137 MFRC522::StatusCode status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid)); 138 if (status != MFRC522::STATUS_OK) { 139 Serial.println("Authentication failed."); 140 return; 141 } 142 143 status = mfrc522.MIFARE_Read(blockNum, readBlockData, &bufferLen); 144 if (status != MFRC522::STATUS_OK) { 145 Serial.println("Read failed."); 146 } else { 147 Serial.println("Data read successfully."); 148 } 149}
Arduino part
cpp
--
1#define PIN1 4 // FAN 2#define PIN2 5 3#define PIN3 6 4#define PIN4 7 // BULB (Controlled by PIR and Manual) 5#define PIR_PIN 8 // PIR Sensor Input Pin 6 7#include <SoftwareSerial.h> 8 9bool pirActivated = false; 10bool manualOverride = false; // Track if manual override is ON 11 12SoftwareSerial espSerial(9, 10); 13 14void setup() { 15 pinMode(PIN1, OUTPUT); 16 pinMode(PIN2, OUTPUT); 17 pinMode(PIN3, OUTPUT); 18 pinMode(PIN4, OUTPUT); 19 pinMode(PIR_PIN, INPUT); 20 21 espSerial.begin(9600); 22 Serial.begin(9600); 23 24 // Initialize all devices OFF (for Active LOW relay, HIGH = OFF) 25 digitalWrite(PIN1, HIGH); 26 digitalWrite(PIN2, HIGH); 27 digitalWrite(PIN3, HIGH); 28 digitalWrite(PIN4, HIGH); 29} 30 31void loop() { 32 int motion = digitalRead(PIR_PIN); 33 34 // PIR should only control PIN4 if not manually overridden 35 if (motion == HIGH && !manualOverride) { 36 Serial.println("Motion detected - Turning ON Bulb"); 37 digitalWrite(PIN4, LOW); // ON 38 pirActivated = true; 39 delay(5000); // Keep it ON for 5 seconds 40 digitalWrite(PIN4, HIGH); // OFF 41 } 42 43 if (espSerial.available()) { 44 String command = espSerial.readStringUntil('\n'); 45 command.trim(); 46 Serial.println("Received: " + command); 47 48 if (command == "ON1") { 49 digitalWrite(PIN1, LOW); // ON 50 Serial.println("Fan ON"); 51 } else if (command == "OFF1") { 52 digitalWrite(PIN1, HIGH); // OFF 53 Serial.println("Fan OFF"); 54 } else if (command == "ON2") { 55 digitalWrite(PIN2, LOW); // ON 56 Serial.println("Device 2 ON"); 57 } else if (command == "OFF2") { 58 digitalWrite(PIN2, HIGH); // OFF 59 Serial.println("Device 2 OFF"); 60 } else if (command == "ON3") { 61 digitalWrite(PIN3, LOW); // ON 62 Serial.println("Device 3 ON"); 63 } else if (command == "OFF3") { 64 digitalWrite(PIN3, HIGH); // OFF 65 Serial.println("Device 3 OFF"); 66 } else if (command == "ON4") { 67 manualOverride = true; // Manual ON overrides PIR 68 digitalWrite(PIN4, LOW); 69 Serial.println("Bulb ON (Manual Override)"); 70 } else if (command == "OFF4") { 71 manualOverride = false; // Allow PIR to control it again 72 digitalWrite(PIN4, HIGH); 73 Serial.println("Bulb OFF (Manual Control Disabled)"); 74 } 75 } 76}
Documentation
Report Documentation
Please don't reuse it
organized2.pdf
Comments
Only logged in users can leave comments