Josh LiangBrock HeckSaul Uribe
Published

The Driveway Detector

The purpose of this project is to detect motion in the driveway and alert the user inside the house.

BeginnerFull instructions provided3 hours265
The Driveway Detector

Things used in this project

Hardware components

Argon
Particle Argon
×3
Breadboard (generic)
Breadboard (generic)
×3
Buzzer
Buzzer
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×3
Jumper wires (generic)
Jumper wires (generic)
×20
PIR Sensor, 7 m
PIR Sensor, 7 m
×2
LED (generic)
LED (generic)
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets

Story

Read more

Schematics

Particle Argon Communication Flow Chart

This is the flow chart of how the Particle Argons communicate with one another with two sets of 2-way communication.

PIR Motion Sensor Circuit Diagram

The motion sensor has a positive and negative terminal that are connected to the power and ground rails. The motion sensor also is connected to the Argon at pin D2 where it sends a signal. The LED light is connected to the ground and to pin D7 which sends power to the LED when the motion sensor detects motion.

Passive Buzzer and LED Circuit Diagram

The passive buzzer is connected to the ground strip. The passive buzzer is also connected to the VUSB pin which provides the buzzer power and pin D3 which sends the signal to activate the buzzer. The LED light is connected to the ground strip and pin D5 which provides power to light the LED.

Code

Buzzer Code

C/C++
Code for the buzzer
const int buzzer = 3;
const int led = 5;
int count = 0;
void setup(){
    Particle.subscribe("Motion Sensor 1", motionFunction1); // Subscribes to the first motion sensor
    Particle.subscribe("Motion Sensor 2", motionFunction1); // Subscribes to the second motion sensor
    pinMode(buzzer, OUTPUT); // Sets the buzzer pin as an output
    pinMode(led, OUTPUT); // sets the led pin as an input
}

void motionFunction1(const char *event, const char *data)
{
    if ((strcmp(data,"Motion Detected 1")==0) || (strcmp(data,"Motion Detected 2")==0)) { // Determine if motion is detected
        Particle.publish("Buzzer", "On"); // Publishes that the buzzer is on
        count = 25;
        while (count > 0){ // Turn on buzzer and flash led
            digitalWrite(led, HIGH);
            tone(buzzer, 1700);
            delay(100);
            noTone(buzzer);
            digitalWrite(led, LOW);
            tone(buzzer, 1800);
            delay(100);
            noTone(buzzer);
            count = count -1;
        }
    }
    else if ((strcmp(data,"Standby 1")==0) || (strcmp(data,"Standby 2")==0)) { // Determine if the motion sensor is in standyby mode
    Particle.publish("Buzzer", "Off"); // Publishes that the buzzer is on
  }
}

void loop() {
    
}

Motion Detector Code

C/C++
Code for PIR motion sensors
const char *eventName = "Buzzer";
int On = 1;
int Off = 0;
int inputPin = D2;            
int ledPin = D7;                
int pirState = LOW;            
int val = 0;                   
int calibrateTime = 5000;      

void setup(){
    Particle.subscribe("Buzzer", buzzerFunction); // Subscribe to the argon with the buzzer
    pinMode(ledPin, OUTPUT); // LED pin set as output
    pinMode(inputPin, INPUT); // PIR motion set as input
    digitalWrite(ledPin, HIGH); // initially have LED on
}

void loop(){
  if (calibrated()){ // Check if PIR sensor is calibrated
      
    readTheSensor(); // If the sensor is calibrated then read the input
    
    reportTheData(); // And publish the status of the sensor
    }
}

void readTheSensor(){
    val = digitalRead(inputPin); // Read the input from the PIR
}

bool calibrated(){
    return millis() - calibrateTime > 0; // PIR calibration
}

void reportTheData(){ // Publishes the status of the PIR sensor
    if (val == HIGH){
        
        if (pirState == LOW) {
          Particle.publish("Motion Sensor 1", "Motion Detected 1");
          
          pirState = HIGH;
        }
        
    } 
    
    else {
        
        if (pirState == HIGH) {
          Particle.publish("Motion Sensor 1", "Standby 1");
          
          pirState = LOW;
        }
    }
}

void buzzerFunction(const char *event, const char *data){ // Reads the status of the buzzer and tells the LED to turn on or off
    if (strcmp(data,"Off")==0) {
        digitalWrite(ledPin, HIGH);
        publishOff();
    }
    else if (strcmp(data,"On")==0) {
        digitalWrite(ledPin, LOW);
        publishOn();
    }
}

void publishOn() { // Publishes data to google sheets if buzzer is on
    char buf[128];

    snprintf(buf, sizeof(buf), "[%d]", On);

    Particle.publish(eventName, buf, PRIVATE);
    Log.info("published: %s", buf);
}  

void publishOff() { // Publishes data to google sheets if buzzer is off
    char buf[128];

    snprintf(buf, sizeof(buf), "[%d]", Off);

    Particle.publish(eventName, buf, PRIVATE);
    Log.info("published: %s", buf);
}  

Credits

Josh Liang

Josh Liang

1 project • 1 follower
Brock Heck

Brock Heck

1 project • 0 followers
Saul Uribe

Saul Uribe

1 project • 0 followers

Comments

Add projectSign up / Login