Things used in this project

Hardware components:
Photon new
Particle Photon
×2
SPDT 10A 3V Relay
×1
Solar Motion Sensor Light
×2
Mfr 25frf52 10k sml
Resistor 10k ohm
×4
12002 04
Breadboard (generic)
×2
11026 02
Jumper wires (generic)
×15
Software apps and online services:
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service
Hackster
ThingSpeak API
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Schematics

Car Relay Photon Schematic
Displays the pin out and schematic of the car relay photon.
car_relay_schematic_TPV39UW1BT.fzz
Car Door Sensor Photon Schematic
Displays the pin out and schematic of the car door sensor photon.
car_door_sensor_schematic_qgZ5vJNJy1.fzz

Code

Webhook FormJSON
This is the code needed to enter into the Webhook form integration for the car door sensor photon so that it will graph using Thingspeak.
{
    "event": "cardoor_open_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}
Webhook Form Car RelayJSON
This is the code needed to enter into the form section of your Webhook Integration for the car relay photon.
{
    "event": "carrelay_open_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}
Car Door Sensor PhotonArduino
This is the code that corresponds to the car door sensor photon.
/*  begin particle webhook code snippit to add to particle webhook interface on console
{
    "event": "cardoor_open_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}
*/

char publishString[40];
int doorpin = D0;
int volttestpin = A5;
int voltpowerpin = A4;

const String key = "0W9OG8025VEKLUCM";



int rssival = 0;
volatile bool doorsend = FALSE;
volatile bool rssisend = FALSE;
int doortriggers = 0;
long waketime = 0;
SYSTEM_THREAD(ENABLED); //enable multitasking.  allows the ability to catch the doorpin trigger and send the message
SYSTEM_MODE(AUTOMATIC);  //run code. then connect     
     
void rssi_update()
{
    //delay (2000);
    static int count = 0;
    Serial.println(count++);
    rssival = WiFi.RSSI();
    sprintf(publishString,"%d",rssival);
    bool success = Particle.publish("RSSI",publishString);
    
    sprintf(publishString, "%1.4f", checkbattery());



       Particle.publish("cardoor_open_All", "{ \"1\": \"" + String(rssival) + "\"," +
       "\"2\": \"" + String(checkbattery()) + "\"," +
       "\"3\": \"" + String(doortriggers) + "\"," +
     //"\"4\": \"" + String(var3) + "\"," +
     //"\"5\": \"" + String(var4) + "\"," +
       "\"k\": \"" + key + "\" }", 60, PRIVATE);
    if (success == TRUE) {
        //delay(10000);
        rssisend = FALSE; //if sent, then turn of the send flag, otherwise let it try again.
    }
}


void enabledoorsend(void){
    doorsend=TRUE;
    digitalWrite(D7,1);
}


      



void setup() {
    //setADCSampleTime(ADC_SampleTime_239Cycles5);  //sets adc to longest time for low noise
    Time.zone(-4);  //set eastern time zone
    pinMode(doorpin,INPUT);
    pinMode(voltpowerpin, INPUT);
    pinMode(D7, OUTPUT);
    attachInterrupt(doorpin, enabledoorsend, FALLING);
    Particle.variable("doortrig", doortriggers);
    rssisend = TRUE;
}



void loop()


{
    if ((Particle.connected())&&(doorsend == TRUE)&&WiFi.ready()) 
    {
        doornotification();
    }
    
    if ((Particle.connected())&&(rssisend == TRUE)&&WiFi.ready()) 
    {
        rssi_update();
    }
    

    if ((millis()-waketime > 200000) && (doorsend == FALSE) && (rssisend == FALSE)) 
    {
        Particle.disconnect();
        
        //System.sleep(doorpin,RISING,30); 
        System.sleep(doorpin,FALLING);
        pinMode(doorpin,INPUT); // this may need resetting after sleep.
        waketime = millis();  //millis haults when sleeping.  find out the time on boot and compare from there.
        rssisend = TRUE;  //on wakeup report rssi but do not report door trigger
        doorsend = FALSE;
        
    }

    if (digitalRead(doorpin) == LOW) {
        enabledoorsend();
    }
    
    if (Particle.connected() == false) 
    {
        Particle.connect();
    }
    /*if (waitFor(Particle.connected, 20000))
    {
    }
    */
   
}

float checkbattery(){
    float battvolts;
    pinMode(volttestpin, INPUT);  
    pinMode(voltpowerpin, OUTPUT); //sent power pin as output
    digitalWrite(voltpowerpin, 0); //send a 0, or LOW to turn on voltage test
    delay(1); //wait for volts to settle good measure
    battvolts = analogRead(volttestpin); //sample voltage
    battvolts = float(battvolts)*3.3/4096.0*2.0*3.85/3.827;  //calibrate voltage reading
    pinMode(voltpowerpin, INPUT); //disable powerpin and set as high Z input
    return(battvolts); //return calibrated battery voltage
}

void doornotification(void){
    digitalWrite(D7,1);
    rssi_update();
    sprintf(publishString, "%1.4f", checkbattery());
    Particle.publish("mail/volts", publishString,60,PRIVATE);
    
    sprintf(publishString, "%d", doortriggers);
    bool success = Particle.publish("Someone is in your caarrrrrr!!!!", Time.format(Time.now(), "240027000f51353338363333"), 60, PRIVATE);
    delay(1000);
    if (success == TRUE) {
        doortriggers++;
        doorsend = FALSE; //if sent, then turn off the send flag, otherwise let it try again.
        digitalWrite(D7,0);
        }
}
Car Relay PhotonArduino
This is the code that corresponds to the car relay photon.
/*  begin particle webhook code snippit to add to particle webhook interface on console
{
    "event": "carrelay_open_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}
*/

char publishString[40];
int doorpin = D0;
int volttestpin = A5;
int voltpowerpin = A4;
int carpin1 = D2;
int carpin2 = D3;


const String key = "8AX5KQ0S06M3E3EZ";



int rssival = 0;
volatile bool doorsend = FALSE;
volatile bool rssisend = FALSE;
int doortriggers = 0;
long waketime = 0;
SYSTEM_THREAD(ENABLED); //enable multitasking.  allows the ability to catch the doorpin trigger and send the message
SYSTEM_MODE(AUTOMATIC);  //run code. then connect     
     
void rssi_update()
{
    //delay (2000);
    static int count = 0;
    Serial.println(count++);
    rssival = WiFi.RSSI();
    sprintf(publishString,"%d",rssival);
    bool success = Particle.publish("RSSI",publishString);
    
    sprintf(publishString, "%1.4f", checkbattery());


       Particle.publish("carrelay_open_All", "{ \"1\": \"" + String(rssival) + "\"," +
       "\"2\": \"" + String(checkbattery()) + "\"," +
       "\"3\": \"" + String(doortriggers) + "\"," +
     //"\"4\": \"" + String(var3) + "\"," +
     //"\"5\": \"" + String(var4) + "\"," +
       "\"k\": \"" + key + "\" }", 60, PRIVATE);
    if (success == TRUE) {
        //delay(10000);
        rssisend = FALSE; //if sent, then turn of the send flag, otherwise let it try again.
    }
}


void enabledoorsend(void){
    doorsend=TRUE;
    digitalWrite(D7,1);
}


      



void setup() {
    //setADCSampleTime(ADC_SampleTime_239Cycles5);  //sets adc to longest time for low noise
    Time.zone(-4);  //set eastern time zone
    pinMode(doorpin,INPUT);
    pinMode(voltpowerpin, INPUT);
    pinMode(D7, OUTPUT);
    attachInterrupt(doorpin, enabledoorsend, FALLING);
    Particle.variable("doortrig", doortriggers);
    rssisend = TRUE;
        //We set the pin mode to output
    pinMode(carpin1, OUTPUT);
    pinMode(carpin2, OUTPUT);
    //We "Subscribe" to our IFTTT event called button so that we get events for it 
    Particle.subscribe("button", myHandler);
}

//The function that handles the event from IFTTT
void myHandler(const char *event, const char *data){
    // We'll turn off the car
    digitalWrite(carpin1, HIGH);
    digitalWrite(carpin2, HIGH);
    
    delay(900000);
    
    
     digitalWrite(carpin1, LOW);
    digitalWrite(carpin2, LOW);
}
void loop()


{
    if ((Particle.connected())&&(doorsend == TRUE)&&WiFi.ready()) 
    {
        doornotification();
    }
    
    if ((Particle.connected())&&(rssisend == TRUE)&&WiFi.ready()) 
    {
        rssi_update();
    }
    

    if ((millis()-waketime > 200000) && (doorsend == FALSE) && (rssisend == FALSE)) 
    {
        Particle.disconnect();
        
        //System.sleep(doorpin,RISING,30); 
        System.sleep(doorpin,FALLING);
        pinMode(doorpin,INPUT); // this may need resetting after sleep.
        waketime = millis();  //millis haults when sleeping.  find out the time on boot and compare from there.
        rssisend = TRUE;  //on wakeup report rssi but do not report door trigger
        doorsend = FALSE;
        
    }

    if (digitalRead(doorpin) == LOW) {
        enabledoorsend();
    }
    
    if (Particle.connected() == false) 
    {
        Particle.connect();
    }
    /*if (waitFor(Particle.connected, 20000))
    {
    }
    */
   
}

float checkbattery(){
    float battvolts;
    pinMode(volttestpin, INPUT);  
    pinMode(voltpowerpin, OUTPUT); //sent power pin as output
    digitalWrite(voltpowerpin, 0); //send a 0, or LOW to turn on voltage test
    delay(1); //wait for volts to settle good measure
    battvolts = analogRead(volttestpin); //sample voltage
    battvolts = float(battvolts)*3.3/4096.0*2.0*3.85/3.827;  //calibrate voltage reading
    pinMode(voltpowerpin, INPUT); //disable powerpin and set as high Z input
    return(battvolts); //return calibrated battery voltage
}

void doornotification(void){
    digitalWrite(D7,1);
    rssi_update();
    sprintf(publishString, "%1.4f", checkbattery());
    Particle.publish("mail/volts", publishString,60,PRIVATE);
    
    sprintf(publishString, "%d", doortriggers);
    bool success = Particle.publish("Someone is in your caarrrrrr!!!!", Time.format(Time.now(), "240027000f51353338363333"), 60, PRIVATE);
    delay(1000);
    if (success == TRUE) {
        doortriggers++;
        doorsend = FALSE; //if sent, then turn off the send flag, otherwise let it try again.
        digitalWrite(D7,0);
        }
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

ConnectTheDots with Particle Azure IoT Hub Integration
Intermediate
  • 598
  • 7

Protip

This project will allow you to connect your Particle device into an Azure IoT Hub for viewing data in real-time through an ASP.NET web app!

Other Clocks
Intermediate
  • 194
  • 3

Work in progress

A combination of 3 different clocks in one frame.

Christmas Gift Box
Intermediate
  • 3,604
  • 595

Full instructions

Christmas Gift Box plays music and sends an email when it is opened.

Weather Aware Sprinkler Controller
Intermediate
  • 1,321
  • 16

Full instructions

6 station Photon controller uses the Weather Underground API to prevent watering when windy, rainy, or too cold.

Simple Environmental Monitoring
Intermediate
  • 1,613
  • 13

Full instructions

Particle Photon circuit allowing the display of environmental conditions (light, temperature, humidity, pressure) using the Blynk app.

THDweeter
Intermediate
  • 253
  • 2

Protip

Yet another temperature-humidity sensor publishing to dweeter, with WiFi auto-disconnect and a push button to read daily max and min values.

Add projectSign up / Login