Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Michael Gillett
Published © MIT

Low-cost Home Automation with Voice Control

An inexpensive open-source home automation solution for low income individuals.

IntermediateShowcase (no instructions)21,506
Low-cost Home Automation with Voice Control

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Photon
Particle Photon
×1
USB Microphone
Most USB microphones should work, this is the one I used for this project.
×1
Breadboard (generic)
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
Jumper wires (generic)
Jumper wires (generic)
×1
5050 RGB LED strip
×1

Software apps and online services

Windows 10 IoT Core
Microsoft Windows 10 IoT Core
Wit.ai
https://wit.ai/michael-gillett/Dorm%20Automation

Story

Read more

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.

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.

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.

Code

Photon code used to control the door lock, overhead lights, and the LED strip

C/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

Michael Gillett

Michael Gillett

1 project • 12 followers

Comments