empowering creative people

Showcase Image

Introduction

These days we can do just about anything on our phone, we can control so many aspects of our lives using the technology in our pocket, but the most mundane aspects of our lives; opening the garage door, blindly reaching for the light switch in the dark, opening the front door when we get home, still relies on manual interaction.

So I created the Particle IoT House, which contains servo motors to open and close the front and garage door, LED strip lighting, and temperature sensors, all inside a 3D printed replica of the Simpsons house (created by Thingiverse user Bubolz)


Project Description

This project uses the Electron microcontroller from Particle which allows for 3G connection to the Particle cloud services and internet interaction. By using the Particle cloud functions and variables, the various functions of the house can be controlled via a web application.

To complete this project I used:

You will of course need something to put all of this in. We 3D printed our Simpsons house replica to show the concept, however you can assemble it all on a breadboard to prove the concept, and then install it however you like.

Here's what the house model looked like before it was printed:

Simpsons houseHouse model 2House model

We scaled the entire print up uniformly by a factor of 1.38 using Cura's scale function. The first print was an ABS model (Natural ABS color) that had serious warping issues due to the size of the first layer (The thing was almost the entire Taz 6 Bed!

All parts of the house were printed using 3mm PLA (Black) on the Taz 6 with Standard detail profile; except the windows/door frames which were on high quality. Some touching up was required on the window holes in the house and windows themselves, we just used a small file and the Exacto knife that came with the Taz 6 to do this. So I did a little googling and found that any acrylic paints should work on the house providing the surface is painted with an acrylic primer first. So I went and bought some Acrylic paints from Officeworks and picked up a few $1 paintbrushes while I was there.

A quick trip down to the Local Bunnings led me to speaking with Jeff. Jeff let me know that when priming plastics you want to clean them down with some sort of alcohol first, recommending Isopropyl alcohol as a common product. I ended up grabbing a Spray Can of Dulux Plastic Primer (~$11) and some Plastic Epoxy Superglue ($8). The glue was to fix the door frames and windows to the walls of the house.

House primed coated

Cleaned the parts using some Isopropyl we had in the warehouse and paper towels. Once that was done, the primer coat went on well. I used an old cardboard box to minimize mess from the spraying. Decided to do another coat in 20 minutes time, then move onto painting the parts individually, gluing them onto the house and final touches.

Single coat painted

After the second coat, I have noticed that some white areas on the primed surface appear to have formed. I'm thinking it's the Isopropyl alcohol mixing with the Spray, will be painting over it so it isn't too much to worry about.

Third and fourth coats are down, and I have enlisted the help of a small 1.2kW heater to assist in drying between coats. The primer seems to have lifted from the doors, not sure why that is the case. Coats are coming up nicely though.

I had 4 coats on all the windows, and 5 one the walls section, I decided to glue them in using Plastic Fix SuperGlue. Comes with a primer and a glue, so I primed and glued each of the windows to the walls section and touched up a few paint problems. Following this I am putting more coats on the doors as it's hard to replicate the lighter pink on black PLA. 

A paint job and assembly later, and our house was looking great, if a bit empty:

House painted and assembled

Awesome, I wanted the house to have the functionality that would be useful and practical in a real house, things like opening and closing the garage and front door, controlling the lights, and temperate, that kind of thing. Whilst a PCB or at least soldered prototyping board would be a bit more durable, the model house shouldn't receive too much abuse, so mounting everything on a breadboard, worked fine. Here's the layout I used, it's a little messy, but it does the job:

Breadboard layout

After a quick manual test to check that everything was working nicely, I installed the electron into the breadboard, and fired it up to make sure the regulator was working properly and nothing was connected where it shouldn't be. The only thing I overlooked was the current output of the L7805 regulator. At 1.2A it would power the project adequately, although at the top of its range, but it can't handle the current demands of both the LEDs and the Electron. Particle state that whilst the Electron draws a nominal 500mA (approx.) during cellular transmission, it can pull between 800-1800mA. This is only for a tiny amount of time so the spike in current draw should be handled by the L805, but charging the battery alongside that is absolutely out of the question. But the battery is there so that when powering the Electron off a standard USB port which can only deliver 0.5-1A, the extra current capacity is needed.

The code to run it all is fairly simple, most of the magic is handled by the Particle.io servers and built in code to handle all of the cloud services. All of the house control happens by calling a single Particle.function from the web app, which passes a string (max 64 char length) to the function. From there, some basic string handling pulls the various sections apart and tests for the various commands and values for each part of the house, then outputs those to the hardware. At the moment, I'm just passing the raw sensor data to the Particle API, but I'll edit this soon with the formula to convert the raw sensor voltage into degrees. Because it's an analogue sensor, the readings won't be super accurate, but it proves the concept well, and the TMP36 sensor can easily be substituted for a more precise digital sensor without any significant changes on the software side.

Servo doorservo;
Servo garageservo;
int const door = D0;
int const garage = D1;
int const ledR = B0;
int const ledG = B1;
int const ledB = B2;
int const tempSense = A0;

unsigned char rValue = 0b11111111;
unsigned char gValue = 0b11111111;
unsigned char bValue = 0b11111111;
int temp;
int voltage;

int posDoor = 0;
int posGarage = 0;

std::string controlString;
std::string rString;
std::string gString;
std::string bString;
std::string posDoorString;
std::string posGarageString;

void setup() {
    pinMode(door, OUTPUT);
    pinMode(garage, OUTPUT);
    pinMode(ledR, OUTPUT);
    pinMode(ledG, OUTPUT);
    pinMode(ledB, OUTPUT);
    pinMode(tempSense, INPUT);
    
    Particle.function("control", control);
    Particle.variable("temp", &temp, INT);
    
    analogWrite(ledR, LOW);
    analogWrite(ledG, LOW);
    analogWrite(ledB, LOW);
    digitalWrite(door, LOW);
    
    doorservo.attach(door);
    garageservo.attach(garage);
}

void loop() {
    voltage = analogRead(tempSense);
    temp = voltage;
}


int control(String control) {
    
   controlString = control;
    
    if(controlString.substr(0,3) == "LED") {
        if(controlString.substr(3, 2) == "on") {
            analogWrite(ledR, rValue);
            analogWrite(ledG, gValue);
            analogWrite(ledB, bValue);
            return 1;
        }
        
        if(controlString.substr(3, 3) == "off") {
            analogWrite(ledR, LOW);
            analogWrite(ledG, LOW);
            analogWrite(ledB, LOW);
            return 1;
        }
        
        if(controlString.substr(3,1) == "c") {
            rString = controlString.substr(4,3);
            gString = controlString.substr(8,3);
            bString = controlString.substr(12,3);
            
            rValue = atoi(rString.c_str());
            gValue = atoi(gString.c_str());
            bValue = atoi(bString.c_str());
            
            analogWrite(ledR, rValue);
            analogWrite(ledG, gValue);
            analogWrite(ledB, bValue);
            return 1;
        }
    }
    
    if(controlString.substr(0,6) == "GARAGE") {
        posGarageString = controlString.substr(6,3);
        posGarage =  atoi(posGarageString.c_str());
        if(posGarage < 2) {
            posGarage = 2;
        }
        if(posGarage > 160) {
            posGarage = 160;
        }
        garageservo.write(posGarage);
        return 1;
    }
    
     if(controlString.substr(0,5) == "FRONT") {
        posDoorString = controlString.substr(5,3);
        posDoor =  atoi(posDoorString.c_str());
        if(posDoor > 120) {
            posDoor = 120;
        }
        doorservo.write(posDoor);
        return 1;
    }
        
    else {
        return -1;
    }
}

I used some LEDs to test the different functions of the servos and LED strips on the breadboard to make sure that everything was responding will to the code, which it did, and whilst the code could be made a bit more efficient and compact, the layout makes it fairly easy to read, and understand what's going on. To test out all the functions, I just modified one of the web app examples on the Particle website to include the functions I wanted with the appropriate string commands. This works great for early testing, but it's an ugly, clunky interface, and I'll share the final web app interface that gets created to work with the house. For now, I've attached the basic html script which you can load into a web browser which interacts with the Particle API. If you're using this script for your own project, you'll need to change to device ID and access token to whatever yours is. Just change the file extension to .html and open with the web browser of your choice. For more info on this, check out the Particle resource site.

The Particle IDE is absolute magic, all your code is stored on the cloud, along with a huge database of libraries, many of which are ports of the familiar Arduino libraries. I used a Photon board for some of the early testing because it operates over Wi-Fi vs cellular which means you can upload/download as much data as you want and not worry about data usage/costs, however once everything was up and running nicely, I switched over to the Electron as ultimately, cellular communication is way cooler. The limitation to this is that if you flash your code heaps of times over the cellular connection to test out different things, you will chew through data very quickly. So I used the local Particle CLI (Command Line Interface) which is easy to use to flash boards over USB or serial. You can download the binaries for each program and navigate to them in the CLI to flash in one line of code.

Particle CLI

Next up was to install everything in the house and test it out. As you can see, hot glue was used extensively to secure things in place, although it works a little too well, as when applied to printed plastic, the heat of the glue causes it to soften and bond to the plastic underneath, so it's very difficult to get off! The wiring could be a bit cleaner, but it's all out of the way when you look through the windows, and allows you to see the process behind the creation.

House 6

House 4

House 1

House 2

House 5

House 3

Because of the unique nature of the house that we printed, I had to get a bit creative with the mechanisms for the doors. The garage door uses a weighted pulley system, and for the front door, I made an actuator out of some spare plastic card, and super glued part of a spare servo motor wing to the inside and used small bolts to create pivot points. Not exactly pretty, but it works reliably and demonstrates the house, so that's a win in my book.

After a few tweaks in the code to limit the rotational movement of the servo motors to make sure they don't hyer-extend, everything works well.

House gif 3 bottom

And there it is, my IoT house, powered by Particle. 

Attachments

1. 1469671518_Control_test.txt