Ethan Pizarro
Published © GPL3+

Lane Tech HS - PCL - Simple Door Sensor

Gather timestamps on when a door of interest is opened.

BeginnerFull instructions provided1 hour471
Lane Tech HS - PCL - Simple Door Sensor

Things used in this project

Hardware components

Argon
Particle Argon
×1
Elegoo Tilt Ball Sensor
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Google Sheets
Google Sheets

Story

Read more

Schematics

Circuit

Code

Code for Tilt Switch

C/C++
int tiltSwitch = D2; // digital pin for reading tilt switch value
int returnValue = 0; // variable for preventing repeat publishes and serial monitoring

int val; // variable for digital read

void setup() {
    pinMode(tiltSwitch, INPUT);
    
    // start serial monitor for testing and presentations
    Serial.begin(9600);
}

void loop() {
    // read pin D2
    val = digitalRead(tiltSwitch);
    
    // if switch read as LOW
    if (val == LOW)
    {
        // if new occurence of door being detected as open
        if (returnValue != 0)
        {
            // publishes event for webhook to Google Sheets
            Particle.publish("Door Opened", "door opened");
        }
        
        returnValue = 0;
    }
    else
    {
        returnValue = 1;
    }
    
    // output read on serial monitor for testing and presentations
    Serial.println(returnValue);
    
    // wait 100ms before checking again
    delay(100);
}

Credits

Ethan Pizarro
3 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.