Matthew InnesBhargav GajjarUmeed Bhandary
Published

The UBM Security System

A home security system that utilizes blockchain-like consensus to keep your belongings safe and alert you if the system is tampered with.

IntermediateFull instructions provided3 hours860
The UBM Security System

Things used in this project

Hardware components

Argon
Particle Argon
×3
Breadboard (generic)
Breadboard (generic)
×3
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED (generic)
LED (generic)
×4
Resistor 220 ohm
Resistor 220 ohm
×3
Jumper wires (generic)
Jumper wires (generic)
×13

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Maker service
IFTTT Maker service
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Rangefinder Argon

Alerter Argon

Code

Rangefinder Argon

C/C++
 /*
 *                     +-----+
 *          +----------| USB |----------+
 *          |          +-----+          |
 *          | [ ] RST                   |
 *          | [ ] 3V3                   |
 *          | [ ] MD                    |
 * Ground ->| [*] GND                   |
 *          | [ ] A0            Li+ [ ] |
 *          | [ ] A1            EN  [ ] |
 *          | [ ] A2           VUSB [*] |<- Rangefinder VCC
 *          | [ ] A3  [S]   [R]  D8 [ ] |
 *          | [ ] A4             D7 [ ] |
 *          | [ ] A5  +-------+  D6 [*] |<- Rangefinder Echo
 *          | [ ] SCK |   *   |  D5 [*] |<- 220 Ohm --- Red LED
 *          | [ ] MO  | Argon |  D4 [*] |<- 220 Ohm --- White LED
 *          | [ ] MI  |       |  D3 [*] |<- Rangefinger Trig
 *          | [ ] RX  +-------+  D2 [*] |<- 220 Ohm --- Green LED
 *          | [ ] TX            SCL [ ] |
 *          | [ ] NC            SDA [ ] |
 *          |                           |
 *           \    []         [______]  /
 *            \_______________________/
 *
 */

unsigned long duration;

WiFiSignal sig = WiFi.RSSI();

int U = 101;                                                   
// Initialize vital publishing counter
int V = 1;                                                      
// Initialize Confirmation Variable 1
int W = 1;                                                      
// Initialize Confirmation Variable 2
int X = 0;                                                      
// Initialize sensor trip counter
int Y = 1;                                                      
// Initialize repeat non-trigger counter
int Z = 1;                                                      
// Initialize repeat trigger counter

void setup() {

    pinMode(D7, OUTPUT);                                        
    // Built-in LED
    pinMode(D2, OUTPUT);                                        
    // Sensor tripped LED
    pinMode(D6, INPUT);                                         
    // Echo
    pinMode(D3, OUTPUT);                                        
    // Trig
    pinMode(D4, OUTPUT);                                        
    // Confirmation LED 1
    pinMode(D5, OUTPUT);                                        
    // Confirmation LED 2
    delay(5000);                                                
    // Delay for 5 seconds before starting to avoid initial
    // arbitrary triggers
    Particle.subscribe("LED2Off", MainLED, MY_DEVICES);         
    // Listen for the signal to turn off Confirmation LED 1
    Particle.subscribe("LED3Off", FlatLED, MY_DEVICES);         
    // Listen for the signal to turn off Confirmation LED 2
    
}

void loop() {
        U = U + 1;                                              
        // Iterate vital publishing counter
        
        if (U > 100) {
            U = 0;
            float RSSInum = sig.getStrength();
            String RSSI = String(RSSInum);
            Particle.publish("RSSI", RSSI, PRIVATE);
        }
    
        delay(10);                                              
        // Brief pause
        digitalWrite(D3, HIGH);                                 
        // Activate trigger
        delayMicroseconds(10);                                  
        // Pulse for 10 microseconds
        digitalWrite(D3, LOW);                                  
        // Deactivate trigger
        
        duration = pulseIn(D6, HIGH);                           
        // Time the reply
        
        if (duration > 2000) {                                  
          // Time from 200 to 16000 ms       
            Y = Y + 1;                                          
            // Iterates every time the device is not triggered
            Z = 1;                                              
            // Resets constant trigger counter
            
            digitalWrite(D7, HIGH);                             
            // D7 on if far
            digitalWrite(D2, LOW);                              
            // D2 off if far
            
            if (Y < 2) {                                        
              // If the device has not been triggered the last 2 times it               // has checked, it will stop trying to publish the same                  // data over and over.
                String LED = String(X);                         
                // Convert variable to string
                Particle.publish("LED", LED, PRIVATE);          
                // Generates a flatline if sensor is not tripped.                        // Thingspeak
            }
            
            else {
                Y = 2;                                          
                // Sets Y to 2 to avoid maxing out the device's memory
            }       
            
        }
        
        else {
            
            digitalWrite(D7, LOW);                              
            // D7 off if close
            digitalWrite(D2, HIGH);                             
            // D2 on if close. Green LED
            digitalWrite(D4, HIGH);                             
            // D4 on if sensor is tripped. White LED
            digitalWrite(D5, HIGH);                             
            // D5 on if sensor is tripped. Red LED
            V = 1;                                              
            // Reinitialization of Confirmation Variable 1
            W = 1;                                              
            // Reinitialization of Confirmation Variable 2

            Y = 1;                                              
            // Resets null counter
            Z = Z + 1;                                          
            // Iterate consecutive, uniterrupted trip counter
            
            if (Z < 10) {                                       
              // If the device has been triggered 10 times without                     // interruption it will stop trying to publish the same                  // data over and over
                X = X + 1;                                      
                // Iterate sensor trip counter
                String LED = String(X);                         
                // Convert variable to string
                Particle.publish("LED", LED, PRIVATE);          
                // Publish the value of the LED variable to Thingspeak
                Particle.publish("SensorTripped", PRIVATE);     
                // Sends an alert to the receiver Argon that the sensor                  // has been tripped
                delay(1500);                                    
                // Wait for 1.5 seconds to avoid iterating more than once                 // per sensor trip
                
            }
            
            else {
                
                Z = 10;                                         
                // Sets Z to 10 to avoid maxing out the device's memory
            }
            
        } 
        
        if (V == 0 && W == 0) {                                 
          // Send a signal to the alerter Argon that both LEDs are off
            Particle.publish("EverythingOff", PRIVATE);         
        }
}

void MainLED(const char *event, const char *data) {             
  // Receives signal from the receiver Argon to turn off 
  // Confirmation LED 1
    digitalWrite(D4, LOW);
    V = 0;
}

void FlatLED(const char *event, const char *data) {             
  // Receives signal from the alerter Argon to turn off 
  // Confirmation LED 2
    digitalWrite(D5, LOW);
    W = 0;
}

Alerter Argon

C/C++
 /*
 *                       +-----+
 *            +----------| USB |----------+
 *            |          +-----+          |
 *            | [ ] RST                   |
 *            | [ ] 3V3                   |
 *            | [ ] MD                    |
 *   Ground ->| [*] GND                   |
 *            | [ ] A0            Li+ [ ] |
 *            | [ ] A1            EN  [ ] |
 *            | [ ] A2           VUSB [ ] |
 *            | [ ] A3  [S]   [R]  D8 [ ] |
 *            | [ ] A4             D7 [ ] |
 *            | [ ] A5  +-------+  D6 [ ] |
 *            | [ ] SCK |   *   |  D5 [ ] |
 *            | [ ] MO  | Argon |  D4 [ ] |
 *            | [ ] MI  |       |  D3 [ ] |
 *            | [ ] RX  +-------+  D2 [*] |<- Green LED
 *            | [ ] TX            SCL [ ] |
 *            | [ ] NC            SDA [ ] |
 *            |                           |
 *             \    []         [______]  /
 *              \_______________________/
 * 
 */

int X = 0;                                                          
// Intialize On variable to activate IFTTT notification

void setup() {
    pinMode(D7, OUTPUT);                                            
    // Initialize mode of built-in LED pin
    digitalWrite(D7, LOW);                                          
    // Start by making sure that the built-in LED is off
    pinMode(D2, OUTPUT);                                            
    // Initialize mode of the external LED pin
    Particle.subscribe("LEDFlashing", LEDON, MY_DEVICES);           
    // Listen for a signal from the receiver Argon that the LED is            // flashing
    Particle.subscribe("EverythingOff", LEDOFF, MY_DEVICES);        
    // Listen for a signal from the rangefinder Argon to turn all the LEDs     // off
}

void LEDON(const char *event, const char *data) {                   
  // What to do when the receiver Argon indicates that it is flashing the   // LED
    
    digitalWrite(D7, HIGH);                                         
    // Turn on the built-in LED
    digitalWrite(D2, HIGH);                                         
    // Turn on the external LED
    X = 1;                                                          
    // Set X value to 1 to activatve IFTTT notification
    String On = String(X);                                          
    // Convert the X value to a string
    Particle.publish("On", On, PRIVATE);                            
    // Send the X value to IFTTT so it will send a notifcation
    delay(5000);                                                   
    // Wait 5 seconds
    Particle.publish("Off", PRIVATE);                               
    // Send a signal to the receiver Argon to stop flashing the LED
    delay(5000);                                                    
    // Wait 5 seconds
    Particle.publish("LED3Off", PRIVATE);                           
    // Send a signal to the rangefinder Argon to turn off 
    // Confirmation LED 2
    digitalWrite(D7, LOW);                                          
    // Turn off the built-in LED
    X = 0;                                                                    // Reset X value to 0 so another notification can be sent
}

void LEDOFF(const char *event, const char *data) {                  
  // What to do when the rangefinder Argon publishes EverythingOff
    delay(5000);                                                    
    // Wait 5 seconds
    digitalWrite(D2, LOW);                                          
    // Turns off the external LED
}

Receiver Argon

C/C++
/*
 *             +-----+
 *  +----------| USB |----------+
 *  |          +-----+          |
 *  | [ ] RST                   |
 *  | [ ] 3V3                   |
 *  | [ ] MD                    |
 *  | [ ] GND                   |
 *  | [ ] A0            Li+ [ ] |
 *  | [ ] A1            EN  [ ] |
 *  | [ ] A2           VUSB [ ] |
 *  | [ ] A3  [S]   [R]  D8 [ ] |
 *  | [ ] A4             D7 [ ] |
 *  | [ ] A5  +-------+  D6 [ ] |
 *  | [ ] SCK |   *   |  D5 [ ] |
 *  | [ ] MO  | Argon |  D4 [ ] |
 *  | [ ] MI  |       |  D3 [ ] |
 *  | [ ] RX  +-------+  D2 [ ] |
 *  | [ ] TX            SCL [ ] |
 *  | [ ] NC            SDA [ ] |
 *  |                           |
 *   \    []         [______]  /
 *    \_______________________/
 *
 *
 * The built-in LED is the only physical component used with this Argon
 */

int X = 0;                                                          
// Initialize flash counter

void setup() {
Particle.subscribe("SensorTripped", Tripped, MY_DEVICES);           
// Receive signal from rangefinder Argon that the device has been tripped
Particle.subscribe("Off", LED1Off, MY_DEVICES);                     
// Receive signal from alerter Argon to turn off the LED
pinMode(D7, OUTPUT);                                                
// Initialize state of pin D7
pinMode(D2, OUTPUT);
}

void Tripped(const char *event, const char *data) {                 
  // What the Argon does when the sensor has been tripped

    Particle.publish("LEDFlashing", PRIVATE);                       
    // Sends an alert to the alerter Argon that the LED is flashing

    X = 0; 
    while (X == 0) {                                                
      // Flash the LED until told to stop by the alerter Argon
        digitalWrite(D7, HIGH);
        delay(100);
        digitalWrite(D7, LOW);
        delay(100);
    }
    
}

void LED1Off(const char *event, const char *data) {                 
  // Stops flashing the LED when told to do so by the alerter Argon
    delay(5000);                                                    
    // Wait 5 seconds
    Particle.publish("LED2Off", PRIVATE);
    
    X = 1;
    delay(1000);                                                    
    // Allows enough time for the signal to be sent before resetting the      // flash counter
}

Credits

Matthew Innes

Matthew Innes

1 project • 1 follower
Bhargav Gajjar

Bhargav Gajjar

0 projects • 2 followers
Umeed Bhandary

Umeed Bhandary

0 projects • 1 follower

Comments