John R McAlpine V Mac
Published © CC BY-NC-SA

A Better Mousetrap

A better mousetrap using a particle for detection and remote status.

BeginnerFull instructions provided1 hour458
A Better Mousetrap

Things used in this project

Hardware components

Argon
Particle Argon
×1
victor moustrap
×1

Story

Read more

Code

Particle Argon Code - Trap

Arduino
//John McAlpine
//MEGR3171 UNC CHARLOTTE
//Introduction to Instrumentation
// A better mouse trap

//"Build a better mouse trap and the world will beat a path to your door"

/*connect mouse trap to ground and to D0
 *
 *                                     +-----+
 *                          +----------| USB |---------+
 *                          | O        +-----+      O  |
 *                          | [ ] RESET                |
 *                          | [ ] 3V3                  |         
 *                          | [ ] MODE                 |          
 *                   /------| [*] GND                  |   
 *                   |      | [ ] A0          Lipo [ ] |       
 *                   |      | [ ] A1  +-------+ EN [ ] |         
 *                   |      | [ ] A2  |   *   | VIN[ ] |
 *                   |      | [ ] A3  | ARGON | D8 [ ] |       
 *                   |      | [ ] A4  |       | D7 [ ] |         
 *                   |      | [ ] A5  +-------+ D6 [ ] |         
 *                   |      | [ ] D13           D5 [ ] |      
 *                   |      | [ ] D12           D4 [ ] |       
 *                   |      | [ ] D11           D3 [ ] |       
 *                   |      | [ ] D10           D2 [ ] |       
 *                   |      | [ ] D9            D1 [ ] |       
 *                   |      | [ ] NC            D0 [*] |-----0  /
 *                   |      |   WIFI0         0NFC     |       /  mouse trap
 *                   |      |O                        O|      /     
 *                   |      +--------------------------+     |   
 *                   |                                       |
 *                   \---------------------------------------/
 *

*/
//Particle will detect trap trigger and publish (circuit being broken)

int trapstatus = 0;  //global variable visible in all functions

void setup() {
  pinMode(D0,INPUT_PULLUP); //configure D0 to input with an internal resistor pullup.
}

void loop() {
    
trapstatus = digitalRead(D0);
if (trapstatus == TRUE){
    Particle.publish("MEGR3171F18/team1/mousestatus", "gotem",PUBLIC);  //subscribe to this mouse event.
    delay(10000);  //delay to prevent overloading the cloud communication.
    }
}

Particle Argon Code - Global Indicator

Arduino
//John McAlpine
//MEGR3171 UNC CHARLOTTE
//Introduction to Instrumentation
// Mouse Subscribe

//"Build a better mouse trap and the world will beat a path to your door"

int i;  //global variable

void setup() { //Runs once
Particle.subscribe("MEGR3171F18/team1/mousestatus", mousesubscribe);  //subscribe to this mouse event.
Serial1.begin(115200);  //Turns on the particle serial port
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);  //blink on reset
delay(500);
digitalWrite(D7,LOW);
}

void loop() {
//nothing happens here for this sketch
}

void mousesubscribe(const char *event, const char *data) {  //do this when the mouse event is published.
//the event name and data from the event are passed back as character strings.
//check out https://docs.particle.io/guide/getting-started/examples/core/#the-buddy-system-publish-and-subscribe
//for another example that does more than print the data
  i++;  //increment i
  Serial.print(i); //print the number of times this has been called over the serial port
  Serial.print(event);  //print the event name
  Serial.print(", data: ");
  if (data)
    Serial.println(data);
  else
    Serial.println("NULL");
  
    digitalWrite(D7, HIGH);  //make the LED turn on if the event occurs.
    delay(2500);
    digitalWrite(D7,LOW);
}

Credits

John R McAlpine V Mac

John R McAlpine V Mac

15 projects • 79 followers
www.MACSBOOST.com Assistant Teaching Professor at UNC Charlotte MEGR3171 Instrumentation, Motorsports Research

Comments

Add projectSign up / Login