Things used in this project

Hardware components:
R8326274 01
Raspberry Pi 2 Model B
×1
Photon new
Particle Photon
×1
USB Microphone
Most USB microphones should work, this is the one I used for this project.
×1
12002 04
Breadboard (generic)
×2
SparkFun Servo - Generic High Torque (Standard Size)
Used to flip the light switch on and off.
×1
SparkFun Servo - Generic High Torque Full Rotation (Standard Size)
Used to wind the cable that moves the door handle.
×1
SparkFun Reed Switch - Insulated
Used to detect a magnet on the handle to determine if the door is unlocked.
×1
SparkFun N-Channel MOSFET 60V 30A
Used for control the color pins of the LED strip
×3
SparkFun DC Barrel Jack Adapter - Breadboard Compatible
Used to supply 12v to the LED strip
×1
11026 02
Jumper wires (generic)
×1
5050 RGB LED strip
×1
Software apps and online services:
10
Microsoft Windows 10 IoT Core
Wit.ai
https://wit.ai/michael-gillett/Dorm%20Automation

Schematics

RGB LED Strip Control
This circuit is used to control the RGB LED strip. The circuit uses N-channel MOSFETs to change the color pins of a 5050 Common anode LED strip (depicted by a single LED in the diagram). A 12v power supply is attached to the barrel connector. The resistors attached to the gate pins of the MOSFETs are 330Ω each.
Rgb%20strip
Door Lock
A continuous rotation servo winds and unwinds a cable to move the door handle. To unlock the door, the servo winds the cable until a magnet on the door handle trips the reed switch (magnet sensor). To lock the door, the servo unwinds the cable for 2 seconds.
Door%20lock
Light Switch
A generic servo motor that rotates to one angle for turning the light switch on and another angle for turning the light switch off.
Light%20switch

Code

Photon code used to control the door lock, overhead lights, and the LED stripC/C++
This code should be uploaded to your Photon board. It matches the pins from the circuits in the schematics section.
#include "rgb-controls/rgb-controls.h"
#include "SparkJson/SparkJson.h"
using namespace RGBControls;

Servo servo;
String method = "";
Color c1(0, 0, 0);
Color c2(0, 0, 0);
Led led(D0, D1, D2);
bool is_locked = true;
bool switch_on = true;

void setup() {
  RGB.brightness(16);
  Spark.function("method", color_method);
  Spark.function("lock", lock);
  Spark.function("switch", mainLight);
  Spark.variable("is_locked", &is_locked, BOOLEAN);
  Spark.variable("switch_on", &switch_on, BOOLEAN);
  
  pinMode(D5, INPUT);
  pinMode(D7, OUTPUT);
  pinMode(WKP, OUTPUT);
  pinMode(RX, OUTPUT);
}

void loop() {
    if (method.equals("fade")) {
        led.fade(c1, c2, 5000);
    }
    
    if (digitalRead(D5) == HIGH) {
        is_locked = false;
        delay(100);
        servo.detach();
    } else {
        is_locked = true;
    }
    digitalWrite(D7, digitalRead(D5));
}

int lock(String state) {
    if (state.equals("lock")) {
        if (!is_locked) {
            is_locked = true;
            servo.attach(RX);
            servo.write(150);
            delay(2000);
            servo.detach();
        }
        return 1;
    } else if (state.equals("unlock")) {
        servo.attach(RX);
        servo.write(30);
        return 0;
    } else {
        return -1;
    }
}

int mainLight(String state) {
    if(state.equals("on")) {
        servo.attach(WKP);
        servo.write(10);
        delay(1200);
        servo.detach();
        switch_on = true;
        return 1;
    } else if(state.equals("off")) {
        servo.attach(WKP);
        servo.write(70);
        delay(1200);
        servo.detach();
        switch_on = false;
        return 0;
    } else {
        return -1;
    }
}


int color_method(String command) {
    char json[100];
    command.toCharArray(json, 100);
    StaticJsonBuffer<512> jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject(json);
    
    if (!root.success())
        return -1;
    
    method = root["method"];
    if (method.equals("fade")) {
        c1 = Color(root["c1"][0], root["c1"][1], root["c1"][2]);
        c2 = Color(root["c2"][0], root["c2"][1], root["c2"][2]);
    } else if (method.equals("set")) {
        c1 = Color(root["c1"][0], root["c1"][1], root["c1"][2]);
        led.setColor(c1);
    }
    
    return 0;
}
Home Automation Backend code
This is the repository for the node.js backend code that runs on the Raspberry Pi 2

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

PHPoc Blue to Control Door Knob by MQTT Protocol and Cortana
Intermediate
  • 68
  • 7

Programming a PHPoc Blue board to control a servo motor to rotate the knob of a door using MQTT Protocol through voice command.

Starry Night Prom
Intermediate
  • 2,231
  • 18

How did I stand out at prom? In a light up dress of course!

Face Detection Using OpenCV With Raspberry Pi
Intermediate
  • 3,172
  • 31

Protip

In this project, we are going to detect faces using OpenCV with Raspberry Pi.

Creating an IoT Server with Home Assistant and MQTT
Intermediate
  • 3,554
  • 20

Protip

This guide will help you set up Home Assistant. Access it from any web browser and automations.

Third Eye for The Blind
Intermediate
  • 944
  • 12

Full instructions

An innovative wearable technology for visually impaired peoples.

DIY Fidget LED Display
Intermediate
  • 1,542
  • 11

Full instructions

Fidget spinners, the simple spinning toy that came out of nowhere. I thought it'd be cool give it some flare and make it a POV display.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login