Hadarel RappaportJesse RaffertyChristopher Gutierrez
Published

MEGR3171 Group 25: A Better Alarm System

A great new way to ensure someone is awake and about, using motion and sound so you know the person is talking and out of bed!

BeginnerFull instructions provided52
MEGR3171 Group 25: A Better Alarm System

Things used in this project

Hardware components

SparkFun Electret Microphone Breakout
SparkFun Electret Microphone Breakout
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Gravity:Digital Push Button (Yellow)
DFRobot Gravity:Digital Push Button (Yellow)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×4
LED (generic)
LED (generic)
×6
Resistor 220 ohm
Resistor 220 ohm
×5
Argon
Particle Argon
×3

Software apps and online services

ThingSpeak API
ThingSpeak API
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Microphone Sensor Schematic

Ultrasonic Sensor Schematics

Button Sensor

Code

Microphone Sensor Code

C/C++
Code for the microphone sensor, as a test it has one LED that will light for a second whenever the microphone picks something up. When Chris hits the button and lets us know he wants to check if someone is awake, another LED will light up on the microphone letting us know it's ready to send a signal back to Chris. It will then publish an event when the microphone picks something up.
int MicSensor=D3;

int led=D13;

int MicState;

int led_indicator=D11;

void setup() {
    
    
pinMode(led,OUTPUT);

pinMode(led_indicator, OUTPUT);

pinMode(MicSensor,INPUT);

digitalWrite(led, LOW);

digitalWrite(led_indicator, LOW);

digitalWrite(MicState, LOW);

 Particle.subscribe("Pressure_Sensor",Button_hit, "e00fce68d88a4d1ae9d50ae5");
    // this will actibvate when chris hits the button on his board
}

void loop() {
    
    MicState=digitalRead(MicSensor);
    
    if (MicState==HIGH)
{
    digitalWrite(led, HIGH);
    
    delay(1000);
    
Particle.publish("Mic_sensor","Voice_Detected",MY_DEVICES); //this lets Chris know the microphone sensor has been triggered
    
}

 else
{digitalWrite(led,LOW);
    
}

}

void Button_hit(const char *event, const char *data) //this code activates when chris hits the button. It will activate and LED light to let us know the button has been pressed
{
    delay(1000);
   digitalWrite(led_indicator,HIGH);
   
   MicState=digitalRead(MicSensor);
   
   if (MicState==HIGH)
   {
       
digitalWrite(led_indicator, LOW);


Particle.publish("Mic_sensor","Voice_Detected",MY_DEVICES);
//this will send some code out
   }

}

/*void Switch_on(const char *event, const char *data)
{
    
    digitalwrite(ledpin, HIGH)
    if (val==HIGH){
        
        
        
    }
    
    

Button Code

C/C++
This is the code made by Chris for the button sensor. When pressed with will publish an even and light up 2 LEDs. Each LED corresponds to another sensor; when the sensors are activated, they will send an event back to this board that turns of its corresponding LED.
int buttonOut = A5;
int buttonIn = A3;
int buttonVal = 0;

int sensor0 = D8;
int sensor1 = D6;
int sensor2 = D4;

void setup() {
    pinMode(buttonOut, OUTPUT);
    pinMode(buttonIn, INPUT);
    
    pinMode(sensor0, OUTPUT);
    pinMode(sensor1, OUTPUT);
    pinMode(sensor2, OUTPUT);
    
    digitalWrite(buttonOut, HIGH);
    
    //Chris_Argon (Self-Test)
    //Particle.subscribe("Pressure_Sensor", Pressure_Sensor_On, "e00fce68d88a4d1ae9d50ae5");
    
    // Hadarel_Argon
    Particle.subscribe("Mic_sensor", Voice_Detected, "e00fce688a7cc6e106322b40");
    
    //Jesse_Argon
    Particle.subscribe("Motion-Sensor", Distance_Detected, "e00fce6807b1ab55fc64bf41");
}

void loop() {
    
    buttonVal = digitalRead(buttonIn);
    
    if (buttonVal == HIGH) {
        //digitalWrite(sensor0, HIGH);
        digitalWrite(sensor1, HIGH);
        digitalWrite(sensor2, HIGH);
        
        Particle.publish("Pressure_Sensor", "Pressure_Sensor_On", MY_DEVICES);
    }
    
    delay(2000);
}

//void Pressure_Sensor_On(const char *event, const char *data)
//{
  //  delay(1000);
    //digitalWrite(sensor0, LOW);
//}

void Voice_Detected(const char *event, const char *data)
{
    delay(1000);
    digitalWrite(sensor1, LOW);
}

void Distance_Detected(const char *event, const char *data)
{
    delay(1000);
    digitalWrite(sensor2, LOW);
}

Ultrasound sensor

C/C++
This is the Ultrasound Sensor coded by Jesse. This board publishes it's reading to thingspeak whenever the sensor is triggered. It also has an LED set to trigger whenever is gets an event from Chris' board, so we know it's ready to send a response back to his.
// This #include statement was automatically added by the Particle IDE.
#include "lib1.h"

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>


int RED = D7; // Pin D7 is set to the red, detection, LED
int LED = D8; // Pin D8 is set to the green, on, LED
int trigPin = D3; // Pin D3 is set to the trigger pin to output an ultrasound wave
int echoPin = D2; // Pin D2 is set to the echo from the ultrasound distnace sensor when the sound waves bounce back to the device

void setup() {
    
    pinMode(LED, OUTPUT); // Sets the green LED as an output
    pinMode(RED, OUTPUT); // Sets the red LED as an output
    pinMode(trigPin, OUTPUT); // Sets the trigger, sound, emitting pin as an output
    pinMode(echoPin, INPUT); // Sets the echo response pin as an input
    Particle.subscribe("Pressure_Sensor", Button_hit, "e00fce68d88a4d1ae9d50ae5"); // Subscribe to Chris' Argon to trigger the sensor to work once the button on his Argon is pressed
}

    void Button_hit(const char *event, const char *data){
    digitalWrite(LED, HIGH); // Turns the on, green, LED on if the button on Chris' Argon is hit
}

void loop() {
    
        //digitalWrite(LED, LOW); // Turns the on, green, LED on to know that the sensor is ready
        long duration, distance; // Stores the variables duration and distance
        digitalWrite(trigPin, LOW); // Sends a trigger signal to the trigger pin
        delayMicroseconds(2); // Delay of 2 microseconds
        digitalWrite(trigPin, HIGH); // Turns the trigger signal 
        delayMicroseconds(10); // Delay of 10 microseconds
        digitalWrite(trigPin, LOW); // Sends the trigger signal 
        
        duration = pulseIn(echoPin, HIGH); // Defines the duration variable 
        distance = (duration*0.343)/2; // Defines the distance as the duration of the trigger signal multiplied by the speed of sound and divided by the number of times it has to travel, 2
        
        if(distance <= 200) { // If statement stating that if the distance is less than 20 cm
            digitalWrite(RED, HIGH); // Turns the detection, red, LED on
            Particle.publish("Motion-Sensor", String(distance), MY_DEVICES); // Publishes an event stating that the ultrasound distance sensor detected movment across it, and the distance of the object
            delay(2000); // Delay for 15 seconds, that is how often ThingSpeak can recieve the data points
            digitalWrite(RED, LOW); // Turns the detection, red, LED off
            digitalWrite(LED, LOW); // Turns the on, green, LED off
        }
}

Credits

Hadarel Rappaport

Hadarel Rappaport

1 project • 0 followers
Jesse Rafferty

Jesse Rafferty

1 project • 0 followers
Christopher Gutierrez

Christopher Gutierrez

1 project • 0 followers

Comments

Add projectSign up / Login