Backpack Defender 3000

The Backpack Defender 3000 is the state of the art, cutting-edge backpack guardian which protects hardworking students from backpack thieves

IntermediateFull instructions provided3 hours23
Backpack Defender 3000

Things used in this project

Hardware components

Grove Starter Kit for LaunchPad
Seeed Grove Starter Kit for LaunchPad
×1
Seeed Moisture sensor
×1
Seeed Buzzer
×1
Seeed Light Sensor
×1
Seeed 4-Digit display
×1

Software apps and online services

Energia
Texas Instruments Energia

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

STL file for the 3-D printed case

Schematics

Schematic

Backpackdefender gmprlu8k9n

Code

Bagpack Defender 3000

C/C++
/* Buzzer Header */ #
define BUZZER_PIN 37 /* sig pin of the Grove Buzzer */
int length = 10; /* the number of notes */
char notes[] = "eeeeeeeeee "; //notes in the song

/* Countdown Header */
#include "TM1637.h"

#
define CLK 39 //pins definitions for TM1637 and can be changed to other ports
# define DIO 38
TM1637 tm1637(CLK, DIO);

/* Moisture Sensor Header*/
#
define MOISTURE_PIN 27 /* pin of Moisture Sensor */ # define THRESHOLD_VALUE 1500 /* threshold for sensing moisture */ # define LED RED_LED
int analog_value = 0; /* variable to store the value coming from Moisture Sensor */
int8_t bits[4] = {
  0
}; /* array to store the single digits of the value */

/* Light Sensor Header*/
#
define LIGHT_SENSOR 25 /* pin connected to the Light Sensor */
int analog_value_two = 0; /* variable to store the value coming from Light Sensor */

/*Button 1 Header*/
const int buttonPin = PUSH1; // the number of the pushbutton pin
int buttonState = 0;
int flag = 0;

/*Button 2 Header*/
const int buttonPinTwo = PUSH2; // the number of the pushbutton pin
int buttonStateTwo = 0;
int flag_m = 0;

void setup() {
  // put your setup code here, to run once:
  /* Buzzer setup */
  pinMode(BUZZER_PIN, OUTPUT);

  /* Countdown setup */
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL); //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;

  /*Moisture Sensor setup*/
  pinMode(LED, OUTPUT);

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buttonPinTwo, INPUT_PULLUP);

}

void loop() {

  /* Look for light and moisture*/
  /* read the value from the sensor */
  analog_value = analogRead(MOISTURE_PIN);

  // put your main code here, to run repeatedly: 
  int8_t NumTab[] = {
    9,
    8,
    7,
    6,
    5,
    4,
    3,
    2,
    1
  }; //0~9,A,b,C,d,E,F
  int8_t ListDisp[4];

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. Arm device if pressed
  if (buttonState == LOW) {
    delay(10000);
    flag = 1;
  }

  // Buzz while moisture is detected
  if (analog_value > THRESHOLD_VALUE) {
    playTone(1915, 1000);
  }
  analog_value_two = analogRead(LIGHT_SENSOR);\
  //Start countdown if armed and light is sensed
  int t = 250;
  if (analog_value_two >= 2250 && flag)

  {

    ListDisp[1] = NumTab[0];
    tm1637.display(0, ListDisp[1]);

    //Countdown
    for (int i = 0; i < length, flag == 1; i++) {
      //Decrease seconds each iteration
      ListDisp[1] = NumTab[i];
      tm1637.display(0, ListDisp[1]);

      //Make note faster each iteration
      t = t / 1.5;
      int count = 0;
      //    buttonStateTwo = digitalRead(buttonPinTwo);
      //Make sure that a constant amount of time is elapsed between seconds
      while (count < 250 && flag) {
        //        buttonStateTwo = digitalRead(buttonPinTwo);
        if ((count + t) > 250) {
          playNote('e', 250 - count);
          count += 250;
          buttonStateTwo = digitalRead(buttonPinTwo);
          if (buttonStateTwo == LOW) {
            flag = 0;

          }
        } else if ((count + t + 83.3) > 250) {
          playNote('e', t);
          count += t;
          delay(250 - count);
          count += 250;
          buttonStateTwo = digitalRead(buttonPinTwo);
          if (buttonStateTwo == LOW) {
            flag = 0;

          }
        } else {
          playNote('e', t);
          count += t;
          delay(83.3);
          count += 83.3;
          buttonStateTwo = digitalRead(buttonPinTwo);
          if (buttonStateTwo == LOW) {
            flag = 0;

          }
        }

      }
      buttonStateTwo = digitalRead(buttonPinTwo);
      if (buttonStateTwo == LOW) {
        flag = 0;

      }

    }
    //Stop countdown until armed again
    flag -= 1;
  }

  // Read Value of second PushButton
  buttonStateTwo = digitalRead(buttonPinTwo);
  if (buttonStateTwo == LOW) {
    flag = 0;
  }
}

/* play tone */
void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000 L; i += tone * 2) {
    digitalWrite(BUZZER_PIN, HIGH);
    delayMicroseconds(tone);
    digitalWrite(BUZZER_PIN, LOW);
    delayMicroseconds(tone);
  }
}

char name = 'e';
int tones = 1915;

void playNote(char note, int duration) {

  // play the tone corresponding to the note name
  for (int i = 0; i < 9; i++) {
    if (name == note) {
      playTone(1915, duration);
    }
  }
}

Credits

Prashanth Pai

Prashanth Pai

0 projects • 4 followers
Rodrigo Andrade

Rodrigo Andrade

0 projects • 4 followers
Michael Sprintson

Michael Sprintson

0 projects • 3 followers
Mit Mehta

Mit Mehta

0 projects • 3 followers
dhananjaysingh2000

dhananjaysingh2000

0 projects • 2 followers
Max Bender

Max Bender

0 projects • 0 followers

Comments

Add projectSign up / Login