GithubHelp home page GithubHelp logo

treasureroom's Introduction

// Requesting/Including libraries required for running the code #include "Wire.h" #include "Adafruit_LiquidCrystal.h" #include <Button.h> #include <SoftwareSerial.h>

/* xbee = TX = 2(yellow), RX = 3(orange) *

  • LCD:
  • 5V to Arduino 5V pin
  • GND to Arduino GND pin
  • CLK to Analog #5 (green)
  • DAT to Analog #4 (yellow) */

// Activating the LCD display Adafruit_LiquidCrystal lcd(0);

// Assigning variable names to pins const int buzzer = 5; const int button1 = 4; const int button2 = 6; const int button3 = 7; const int button4 = 8; const int greenLED = 9; const int redLED = 10; const int pResistor = A0;

int pValue; // Photoresistor String buf; // Buffer to seperate passcodes int tries = 0; // Counts the amount of buttons clicked int count = 0; // Counts number of complete passcode tries int next = 0; // Counts 5th button press to clear message boolean repeat = true; // Stop repeating of "Intruder" message boolean state = true; // System state (on or off) | true = system off false = system on String password = "1234"; // Password for the system boolean laserTrip = false; // Laser status

// Activating the four button inputs for the entry code system Button code1 (button1, INPUT_PULLUP, 1500); Button code2 (button2, INPUT_PULLUP, 1500); Button code3 (button3, INPUT_PULLUP, 1500); Button code4 (button4, INPUT_PULLUP, 1500);

// Activating the xBee radio communication module SoftwareSerial xBee(2, 3);

void setup() { // Opening serial communication ports Serial.begin(9600); xBee.begin(9600);

// Activating the LCD display lcd.begin(16,2); lcd.print("System On");

// For setting up pins for input/output pinMode(greenLED, OUTPUT); pinMode(redLED, OUTPUT); pinMode(pResistor, INPUT);

// Setting the initial status light on startup digitalWrite(redLED, HIGH); }

void loop() { checkMessageReceived(); keycodeEntry(); laserReading(analogRead(pResistor)); }

// Method that handles communication with the command center as well as re-setting the system when receiving the command to void checkMessageReceived () { if (xBee.available()) { String Msystem = xBee.readString(); Serial.println(Msystem); if (Msystem == "treasure clear") { resetSystem(); lcd.print("System On"); state = true; repeat = true; laserTrip = false; digitalWrite(greenLED, LOW); digitalWrite(redLED, HIGH); } } }

// Method that contains the keycode entry algorithm void keycodeEntry() { // For checking if keycode entry buttons are pressed int code1Action = code1.checkButtonAction(); int code2Action = code2.checkButtonAction(); int code3Action = code3.checkButtonAction(); int code4Action = code4.checkButtonAction();

// For changing variables if keykode entry buttons are pressed if (code1Action == Button::CLICKED) { tone(buzzer, 3322, 20); buf += "1"; tries += 1; next += 1; } if (code2Action == Button::CLICKED) { tone(buzzer, 3322, 20); buf += "2"; tries += 1; next += 1; } if (code3Action == Button::CLICKED) { tone(buzzer, 3322, 20); buf += "3"; tries += 1; next += 1; } if (code4Action == Button::CLICKED) { tone(buzzer, 3322, 20); buf += "4"; tries += 1; next += 1; }

// For applying the "entry denied" message to the LCD if (tries == 4 && count < 3) { lcd.setCursor(0,1); lcd.print("Entry denied"); tone(buzzer, 4699, 20); tries = 0; if (state == true){ count += 1; } }

// For removing the "entry denied" message from the LCD on the next button press if (next == 5) { if (state == true) { next = 1; lcd.setCursor(0,1); lcd.print(" "); } }

// For triggering the alarm after either exceeding the number of password attempts or interrupting the laser if (count >= 3) { if (repeat == true) { lcd.clear(); lcd.print("Intruder"); if (laserTrip == false) { lcd.setCursor(0,1); lcd.print("Passcode Wrong"); xBee.println("treasure password"); } else { lcd.setCursor(0,1); lcd.print("Laser Trip"); xBee.println("laser trip"); } repeat = false; //reset repeat to true when command center sends message back } tone(buzzer, 4699); }

// For correct password entry - both activates and deactivates the system if (buf.endsWith(password) && state == true && count < 3) { resetSystem(); lcd.print("System Off"); digitalWrite(greenLED, HIGH); digitalWrite(redLED, LOW); state = false; xBee.println("treasure off"); } else if (buf.endsWith(password) && state == false) { resetSystem(); lcd.print("System On"); digitalWrite(greenLED, LOW); digitalWrite(redLED, HIGH); state = true; xBee.println("treasure on"); } }

// Method for resetting important variables that deal with the keycode entry algorithm void resetSystem() { noTone(buzzer); count = 0; lcd.clear(); buf += "END"; tries = 0; next = 0; }

// Method for checking to ensure the laser is not obstructed (which would indicate an intruder) int laserReading(int pValue) { int var = map(pValue, 0, 1024, 0, 255); if (var < 50 && state == true){ laserTrip = true; count = 3; Serial.println("Laser break"); Serial.println(var); } else{ Serial.println("Laser fine"); Serial.println(var); } }

treasureroom's People

Contributors

kellyx97 avatar humad avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.