#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD(0x27, 16, 2);
#define cursor(x, y) LCD.setCursor(x, y)
#define lcd(x) LCD.print(x)
#define lcd1(x) LCD.setCursor(0, 0);LCD.print(x)
#define lcd2(x) LCD.setCursor(0, 1);LCD.print(x)
#define clear() LCD.clear()
#include <Servo.h>
Servo ALCOHOL_SPRAY;
const int alcoholSprayServoPin = 3;
#define alcoWrite(x) ALCOHOL_SPRAY.write(x)
Servo TOOL_BOX;
const int toolBoxServoPin = 5;
#define toolWrite(x) TOOL_BOX.write(x)
const int pirSensorPin = 2;
#define PIR digitalRead(pirSensorPin)
void setup() {
Serial.begin(9600);
LCD.init();
LCD.backlight();
lcd1("Initializing...");
delay(500);
lcd2("ALCOHOL SPRAY...");
ALCOHOL_SPRAY.attach(alcoholSprayServoPin);
alcoWrite(90);
delay(500);
lcd2("PIR SENSOR......");
pinMode(pirSensorPin, INPUT);
delay(500);
lcd2("TOOL BOX........");
TOOL_BOX.attach(toolBoxServoPin);
toolWrite(0);
delay(500);
clear();
lcd1("Done!");
delay(800);
clear();
}
void loop() {
unsigned int seconds = millis() / 1000 % 60;
unsigned int minutes = millis() / 60000;
char time[5];
if (minutes < 10 && seconds < 10) {
sprintf(time, "0%d:0%d", minutes, seconds);
} else if (minutes < 10) {
sprintf(time, "0%d:%2d", minutes, seconds);
} else if (seconds < 10) {
sprintf(time, "%2d:0%d", minutes, seconds);
} else {
sprintf(time, "%2d:%2d", minutes, seconds);
}
cursor(11, 1);
lcd(time);
if (PIR == HIGH) {
alcoWrite(180);
delay(250);
alcoWrite(90);
delay(250);
} else {
alcoWrite(90);
}
}