Aaron Hall
Published

PCL Door Switch

A particle device that pulls dials controlling light and a fan when a door is opened.

BeginnerShowcase (no instructions)2 hours30
PCL Door Switch

Things used in this project

Hardware components

Photo resistor
Photo resistor
×1
Adafruit vibration sensor
×1
Continuous Motion Servo
×2
Photon 2
Particle Photon 2
×1
Male/Male Jumper Wires
×15
Resistor 100 ohm
Resistor 100 ohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Code

Door Switch Code

C/C++
// Include Particle Device OS APIs
#include "Particle.h"
SerialLogHandler logHandler(LOG_LEVEL_INFO);
Servo myServo;
Servo myServo2;
int photoPin = A5;
int vibePin = A2;



void setup()
{
    myServo.attach(D1);
    myServo2.attach(MISO);
    pinMode(photoPin, INPUT);
    Serial.begin(9600);
}

void loop()
{
// read the analog pin
    int vibe = analogRead(vibePin);
    int light = analogRead(photoPin);
//    Particle.publish(String(vibe));
//    Particle.publish(String(light));
    if(vibe > 30){
        if(light < 2000){
            myServo.write(0);
            myServo2.write(0);
            delay(1000);
            myServo.write(90);
            myServo2.write(90);
        }else if(light > 2000){
            myServo.write(180);
            myServo2.write(180);
            delay(1000);
            myServo.write(90);
            myServo2.write(90);
        }
    }
    delay(2000);
}

Credits

Aaron Hall
1 project • 0 followers

Comments