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

Reducing Arduino Power Consumption
Intermediate
  • 10
  • 3

Full instructions

One the most important feature of portable electronics should be long battery life. We can reduce the current drawn by several ways.

Thunderboard Sense and RPi
Intermediate
  • 73
  • 2

Collecting rich sensor data over BLE and uploading it to the cloud for analysis.

Particle Photon Based Security System with Alerting
Intermediate
  • 1,246
  • 20

Full instructions

Be alerted to any door or window opening and closing in your house on your smart phone.

Happy Plant Notifier
Intermediate
  • 224
  • 4

Full instructions

Get a text or call if your plant is getting too dry, along with a nice LCD display giving information regarding your plant's health.

My Guardian for the Workshop
Intermediate
  • 136
  • 3

Full instructions

Device will send emails if the door or window has been opened, and will monitor the temperature and humidity of the place.

Sigfox Forest Fire Detector
Intermediate
  • 1,622
  • 10

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog