Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dht.h>
- #include <Keypad.h>
- //------------------PINS-------------------//
- //MONITORING
- int IR2 = 4;
- int IR1 = 3;
- //SAFETY
- const byte ROWS = 4;
- const byte COLS = 4;
- byte rowPins[ROWS] = { 13, 12, 11, 10 };
- byte colPins[COLS] = { 9, 8, 7, 6 };
- int motor = 42;
- //BULB AND LDR
- int ldr = A0;
- int bulb = 36;
- int bulbButton = 37;
- int ledsLow = 38;
- int ledsHigh = 39;
- //FLAME DETECTOR WITH BAZAR
- int flame = 40;
- int bazar = 41;
- //----------------LOGIC-----------------//
- //MONITORING
- int doneReading = false;
- char dir = 'n';
- int count = 0;
- //SAFETY
- #define Password_Length 9
- char Data[Password_Length];
- // Password
- char Master[Password_Length] = "123456AB";
- byte data_count = 0;
- char keyValue;
- char hexakeys[ROWS][COLS] = {
- { '1', '2', '3', 'A' },
- { '4', '5', '6', 'B' },
- { '7', '8', '9', 'C' },
- { '*', '0', '#', 'D' }
- };
- Keypad customKeypad = Keypad(makeKeymap(hexakeys), rowPins, colPins, ROWS, COLS);
- bool isLocked = true;
- //BULB
- void setup() {
- Serial.begin(9600);
- pinMode(IR1, INPUT);
- pinMode(IR2, INPUT);
- pinMode(ldr, INPUT);
- pinMode(bulb, OUTPUT);
- pinMode(bulbButton, INPUT);
- pinMode(ledsLow, OUTPUT);
- pinMode(ledsHigh, OUTPUT);
- pinMode(flame, INPUT);
- pinMode(bazar, OUTPUT);
- pinMode(motor, OUTPUT);
- }
- void loop() {
- monitoring();
- keyPress();
- bulbAndLeds();
- flameCode();
- }
- void countPersons() {
- //digitalReads
- bool ir1 = !digitalRead(IR1);
- bool ir2 = !digitalRead(IR2);
- Serial.println(ir1);
- Serial.println(ir2);
- if (doneReading && !ir1 && !ir2) {
- doneReading = false;
- dir = 'n';
- }
- if (dir != 'n' && !doneReading) {
- //dir e (for enter) && ir2 is 1 => make count++ and doneReading true
- if (dir == 'e' && ir2) {
- count++;
- doneReading = true;
- }
- //dir l && ir1 => make count-- and doneReading true
- if (dir == 'l' && ir1) {
- count--;
- doneReading = true;
- }
- } else if (dir == 'n') {
- if (ir1) {
- dir = 'e';
- doneReading = false;
- } else if (ir2) {
- dir = 'l';
- doneReading = false;
- }
- }
- Serial.print("doneReading ");
- Serial.println(doneReading);
- Serial.print("count ");
- Serial.println(count);
- Serial.print("direction ");
- Serial.println(dir);
- }
- void monitoring() {
- countPersons();
- }
- void keyPress() {
- Serial.print("Enter Password:");
- keyValue = customKeypad.getKey();
- if (keyValue) {
- Data[data_count] = keyValue;
- Serial.print(Data[data_count]);
- data_count++;
- }
- if (data_count == Password_Length - 1) {
- Serial.println("Password Length exceeded");
- if (!strcmp(Data, Master)) {
- // Password is correct
- Serial.println("Correct");
- // Turn on relay for 5 seconds
- isLocked = false;
- Serial.print("Locked: ");
- Serial.println(isLocked);
- // digitalWrite(lockOutput, HIGH);
- digitalWrite(motor, HIGH);
- delay(500);
- digitalWrite(motor, LOW);
- isLocked = true;
- Serial.print("Locked: ");
- Serial.println(isLocked);
- } else {
- // Password is incorrect
- Serial.println("Incorrect");
- delay(1000);
- }
- clearPassword();
- }
- }
- void clearPassword() {
- while (data_count != 0) {
- Data[data_count--] = 0;
- }
- return;
- }
- bool value = false;
- void bulbAndLeds() {
- // CODE FOR BULB
- int bulbRead = digitalRead(bulbButton);
- while (bulbRead) {
- //to block the code
- value = !value;
- }
- if (value) {
- digitalWrite(bulb, HIGH);
- } else {
- digitalWrite(bulb, LOW);
- }
- //CODE FOR LEDS
- int ldrRead = analogRead(ldr);
- if (ldr <= 45) {
- digitalWrite(ledsHigh, HIGH);
- digitalWrite(ledsLow, HIGH);
- } else if (ldr > 45 && ldr = < 90) {
- digitalWrite(ledsHigh, HIGH);
- digitalWrite(ledsLow, LOW);
- } else {
- digitalWrite(ledsHigh, LOW);
- digitalWrite(ledsLow, LOW);
- }
- }
- void flameCode() {
- digitalWrite(bazar, digitalRead(flame))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement