Introduction: How to Build a Smart House Model

About: In my spare time, I fly RC airplanes and enjoy sharing my passion for learning how things work through my own instructional videos.

Smart House will be the next smartphone. The technology that encompasses a smart house will become the new normal for modern-day homeowners. Smart houses range from basic to advanced depending on the sensors that are installed in the house and the operating system.

The ARD-02, 201 Arduino Basics Starter Kit, comes with everything to build a Smart House Model. The kit comes equipped with a temperature sensor for temperature control, LED lights for the house lighting system, sound for the security system, servo motors, and stepper motors for a wide range of motion control.

We want to take advantage of the lessons that come with the ARD-02 Kit, we will use their provided code and do a little modification to work with the smart house project, I will attach the link for the ARD-02 example code below for reference.

I collaborate with Circuit Specialists on this project because this project is about STEM and the company is all about STEM. Circuit Specialists and I go way back when we collaborate on the Arizona University EE robotic club robot arm project https://www.instructables.com/Circuits-Specialists...

Supplies

Step 1: Pick the House

In today’s project, we will implement the “Sensing Light” lesson on page 23, which is the most basic step of a smart house, a smart LED light system. The light sensor will provide constant input from the environment and change the light level accordingly.

The light system can be set to a specific mood such as dinner, movie, party, etc. You can print the house template and glue it on cardboard with school glue, and then cut it out.

This project also works with LEGO City Series and you would have to run the wire internally within the building.

Step 2: Installing the LED System

  1. Now you need to cut the slot for the door and windows.
  2. Install the LED lights for the first and second floors.
  3. For reference, we used glue and a white piece of paper to close up the windows for better light distribution. I will include a schematic below for the wiring.

Step 3: Assemble and Testing the Light Sensor

  1. I would test the resistor value to make sure that you have the correct 10K Ohm.
  2. Assembling the Light Sensor circuit to make sure everything works. I will include the schematic below for reference.
  3. Upload the code to make sure the Light Sensor works as expected. I will attach a link below where you can download the example file. http://osepp.com/files/osepp_201K.zip

Now, we need to make the sensor portable so that it works with our Smart House project.

  1. Solder the one side of the resistor to the photoresistor as in the photo below, then solder the wire according to the code.
  2. The Light Sensor should look like the picture below.
  3. Pick a location toward the roof of the house for the best light input and connect the wire to the Arduino just like the previous step.
  4. Now we will change the code so that in a certain light condition, the LED light system for our smart house will turn on or off accordingly.
//Project: Smart House with Light Sensor system 

int First_Floor_LED = 3;
int Second_Floor_LED = 4;


const int sensorMin = 0;
// sensor maximum, discovered through experiment
const int sensorMax = 800;

// the photocell voltage divider pin
int photocellPin = A0;

void setup()
{
    // set up serial at 9600 baud   
    Serial.begin(9600);
    pinMode(First_Floor_LED, OUTPUT);
    pinMode(Second_Floor_LED, OUTPUT);
}

void loop()
{
    int analogValue;
    int range;

// read our photocell
analogValue = analogRead(photocellPin);
// map the sensor range to a range of four options
range = map(analogValue, sensorMin, sensorMax, 0, 3);

// do something different depending on the 
// range value
switch (range) 
{
    // Dark turn on the light 
    case 0:
        Serial.println("dark");
        digitalWrite(First_Floor_LED, HIGH);
        digitalWrite(Second_Floor_LED, HIGH);
        break;
    // Dim turn on the light 
    case 1:
        Serial.println("dim");
        digitalWrite(First_Floor_LED, HIGH);
        digitalWrite(Second_Floor_LED, HIGH);
        break;
    // Medium turn off the ligh 
    case 2: 
        Serial.println("medium");
        digitalWrite(First_Floor_LED, LOW);
        digitalWrite(Second_Floor_LED, LOW);
        break;
    // Bright Turn off the ligh 
    case 3:
        Serial.println("bright");
        digitalWrite(First_Floor_LED, LOW);
        digitalWrite(Second_Floor_LED, LOW);
        break;
}

// wait 0.25s before reading the photocell again
delay(250);
}

Below would be the demonstration of this add on feature for the Smart House

Step 4: What Next?

The Autonomous LED Light system is just the beginning of the Smart House project. There will also be motion control, security systems, and much more in future projects. That is not to overlook the importance of an intelligent LED light system in a Smart House.

The house of the future will always make the occupants feel welcome after a long day of work, or changing the mood of the house for a welcome home party. Furthermore, the ability to turn the light on and off from an app could add another layer to the security overall.

Step 5: How to Build a Security System

A smart house should provide its occupants with more than just comfort. It should also provide a sense of security and a smart house is no different. For the sake of argument, a smart house should do more than just provide a passive defense system for stopping intruders. A smart house should be equipped with a sensor system that actively listens to outside noise.

We will use a speaker and a Piezo element as a sound sensor. If you are following along with the ARD-02 201 Arduino Basics Starter Kit, this will be covered under these 2 lessons: Melody (pg.53) and Knock Sensor(pg.63). I will be referencing the information from these 2 lessons as they provide a great deal of information such as schematics, circuit and coding theory, explanation, etc.

Step 6: Sound Circuit

  1. The sound circuit is fairly simple to assemble, the resistor connects to the speaker in series.
  2. Plug the circuit into an Uno to make sure everything works. OSEPP provided the sound example code in this link http://osepp.com/files/osepp_201K.zip
  3. Now, we will try to build the same circuit with a slightly bigger speaker for our house.
  4. Finally, you can protect the resistor by covering it with a T3 heat shrink tube and then set it aside.

Step 7: Knock Sensor Circuit

  1. This circuit is also fairly simple to build and test out before installing in the house.
  2. I usually upload the provided code from OSEPP to make sure the system works before moving on to the next step.
  3. Now we need to build the sound sensor so that it can go into the smart house project. The resistor is connected parallel to the Piezo Buzzer.
  4. Fold the wires down so the heat shrink tube can go over it. The final product should look like the photo below.
  5. Next, install the Sound system and the Knock Sensor to the house. Give yourself a pat on the back because the hard part is done. I will attach the schematic below for your reference or page 55 on the OSEPP handbook.

Step 8: The Code

I will go over what changes only and the full code file will be attached below in case you need it.

In the Light Sensor Code, I change Second_Floor_LED to pin 5 so that I can use analogWrite instead of the digitalWrite function.

int First_Floor_LED = 3;
int Second_Floor_LED = 5;

void LightControl(int LightLevel)
{
  int Light = map(LightLevel,0,5,0,250);
  
    analogWrite(First_Floor_LED, Light);
    analogWrite(Second_Floor_LED,Light);


}

void LightSensor()
{
      int analogValue;
    int range;

// read our photocell
analogValue = analogRead(photocellPin);
// map the sensor range to a range of four options
range = map(analogValue, sensorMin, sensorMax, 0, 3);

// do something different depending on the 
// range value
switch (range) 
{
    // Dark turn on the light 
    case 0:
        Serial.println("dark");
        LightControl(5);
//        digitalWrite(First_Floor_LED, HIGH);
//        digitalWrite(Second_Floor_LED, HIGH);
        break;
    // Dim turn on the light 
    case 1:
        Serial.println("dim");
        LightControl(5);
//        digitalWrite(First_Floor_LED, HIGH);
//        digitalWrite(Second_Floor_LED, HIGH);
        break;
    // Medium turn off the ligh 
    case 2: 
        Serial.println("medium");
        LightControl(0);
//        digitalWrite(First_Floor_LED, LOW);
//        digitalWrite(Second_Floor_LED, LOW);
        break;
    // Bright Turn off the ligh 
    case 3:
        Serial.println("bright");
        LightControl(0);
//        digitalWrite(First_Floor_LED, LOW);
//        digitalWrite(Second_Floor_LED, LOW);
        break;
}

// wait 0.25s before reading the photocell again
delay(25);
}<br>

The Alarm system

// iterate over the notes of the melody
for (int thisNote = 0; thisNote < numberOfNotes; thisNote++)
{
    // grab our note and note duration from our array
    int thisNoteTone = melody[thisNote][0];
    int thisNoteDuration = melody[thisNote][1];

    // to calculate the note duration in ms
    int noteDurationMS = 100 / thisNoteDuration;

    // play the note
    tone(speakerPin, thisNoteTone, noteDurationMS);
void Alarm_System()
{
   int analogValue;

    // read the sensor and store it in the variable sensorReading:
    analogValue = analogRead(piezoPin);
    Serial.print ("Loud= ");Serial.println(analogValue);
    // if the sensor reading is greater than the threshold:
    if (analogValue > threshold)
    {
        // send the string "Knock!" back to the computer, followed by newline
        //Serial.println("Knock!");
    for(int i = 0; i<10; i++) 
    { 
    alarm_sound();
    LightControl(5);
    delay(10);
    }
    
    }
        digitalWrite(First_Floor_LED, LOW);
        digitalWrite(Second_Floor_LED, LOW);
    // delay to avoid overloading the serial port buffer
    delay(10);
}
void alarm_sound()
{
         // figure out the number of notes in our melody
    int numberOfNotes = sizeof(melody) / sizeof(melody[0]);

    // iterate over the notes of the melody
    for (int thisNote = 0; thisNote < numberOfNotes; thisNote++)
    {
        // grab our note and note duration from our array
        int thisNoteTone = melody[thisNote][0];
        int thisNoteDuration = melody[thisNote][1];

        // to calculate the note duration in ms
        int noteDurationMS = 100 / thisNoteDuration;

        // play the note
        tone(speakerPin, thisNoteTone, noteDurationMS);

        // to distinguish the notes, set a minimum time between them.
        // the note's duration + 30% seems to work well:
        delay(noteDurationMS * 1.30);
    }
}<br>

The Welcome song from OSEPP source code.

int WelcomeSong()
{
    int numberOfNotes = sizeof(melody) / sizeof(melody[0]);
    for (int thisNote = 0; thisNote < numberOfNotes; thisNote++)
    {
        int thisNoteTone = melody[thisNote][0];
        int thisNoteDuration = melody[thisNote][1];
        int noteDurationMS = 1000 / thisNoteDuration;
        // play the note
        tone(speakerPin, thisNoteTone, noteDurationMS);
        delay(noteDurationMS * 1.30);
    }
}<br>

The full code.

//Project: Smart House with Security sysytem 

// include our list of note pitches
#include "pitches.h"

int First_Floor_LED = 3;
int Second_Floor_LED = 5;

// the photocell voltage divider pin
int photocellPin = A0;
int piezoPin = A1;

// the pin the speaker is attached to
int speakerPin = 8;


const int sensorMin = 0;
// sensor maximum, discovered through experiment
const int sensorMax = 800;
const int threshold = 10; 

// the notes in our melody and their duration in fractions of a second
// e.g. quarter note = 4, eighth note = 8, etc.
const int melody[][2] = 
{
    {NOTE_C4, 4},
    {NOTE_G3, 8},
    {NOTE_G3, 8},
    {NOTE_A3, 4},
    {NOTE_G3, 4},
    {NOTE_BLANK, 4},
    {NOTE_B3, 4},
    {NOTE_C4, 4}
};

void setup()
{
    // set up serial at 9600 baud   
    Serial.begin(9600);
    pinMode(First_Floor_LED, OUTPUT);
    pinMode(Second_Floor_LED, OUTPUT);
    WelcomeSong();
}

void loop()
{
  LightSensor();
 Alarm_System();
}

void Alarm_System()
{
   int analogValue;

    // read the sensor and store it in the variable sensorReading:
    analogValue = analogRead(piezoPin);
    Serial.print ("Loud= ");Serial.println(analogValue);
    // if the sensor reading is greater than the threshold:
    if (analogValue > threshold)
    {
        // send the string "Knock!" back to the computer, followed by newline
        //Serial.println("Knock!");
    for(int i = 0; i<10; i++) 
    { 
    alarm_sound();
    LightControl(5);
    delay(10);
    }
    
    }
        digitalWrite(First_Floor_LED, LOW);
        digitalWrite(Second_Floor_LED, LOW);
    // delay to avoid overloading the serial port buffer
    delay(10);
}
void alarm_sound()
{
         // figure out the number of notes in our melody
    int numberOfNotes = sizeof(melody) / sizeof(melody[0]);

    // iterate over the notes of the melody
    for (int thisNote = 0; thisNote < numberOfNotes; thisNote++)
    {
        // grab our note and note duration from our array
        int thisNoteTone = melody[thisNote][0];
        int thisNoteDuration = melody[thisNote][1];

        // to calculate the note duration in ms
        int noteDurationMS = 100 / thisNoteDuration;

        // play the note
        tone(speakerPin, thisNoteTone, noteDurationMS);

        // to distinguish the notes, set a minimum time between them.
        // the note's duration + 30% seems to work well:
        delay(noteDurationMS * 1.30);
    }
}

int WelcomeSong()
{
    int numberOfNotes = sizeof(melody) / sizeof(melody[0]);
    for (int thisNote = 0; thisNote < numberOfNotes; thisNote++)
    {
        int thisNoteTone = melody[thisNote][0];
        int thisNoteDuration = melody[thisNote][1];
        int noteDurationMS = 1000 / thisNoteDuration;
        // play the note
        tone(speakerPin, thisNoteTone, noteDurationMS);
        delay(noteDurationMS * 1.30);
    }
}

void LightSensor()
{
      int analogValue;
    int range;

// read our photocell
analogValue = analogRead(photocellPin);
// map the sensor range to a range of four options
range = map(analogValue, sensorMin, sensorMax, 0, 3);

// do something different depending on the 
// range value
switch (range) 
{
    // Dark turn on the light 
    case 0:
        Serial.println("dark");
        LightControl(5);
//        digitalWrite(First_Floor_LED, HIGH);
//        digitalWrite(Second_Floor_LED, HIGH);
        break;
    // Dim turn on the light 
    case 1:
        Serial.println("dim");
        LightControl(5);
//        digitalWrite(First_Floor_LED, HIGH);
//        digitalWrite(Second_Floor_LED, HIGH);
        break;
    // Medium turn off the ligh 
    case 2: 
        Serial.println("medium");
        LightControl(0);
//        digitalWrite(First_Floor_LED, LOW);
//        digitalWrite(Second_Floor_LED, LOW);
        break;
    // Bright Turn off the ligh 
    case 3:
        Serial.println("bright");
        LightControl(0);
//        digitalWrite(First_Floor_LED, LOW);
//        digitalWrite(Second_Floor_LED, LOW);
        break;
}

// wait 0.25s before reading the photocell again
delay(25);
}

void LightControl(int LightLevel)
{
  int Light = map(LightLevel,0,5,0,250);
  
    analogWrite(First_Floor_LED, Light);
    analogWrite(Second_Floor_LED,Light);

Below would be the demonstration of this add-on feature for the Smart House.

Step 9: Conclusion

The Security System adds another layer to the smart house project. It provides its occupants with comfort yet security by actively listening to the outdoor environment at night. Furthermore, the smart house can then notify the occupants about the disturbance when no one is home. The house of the future is environmentally friendly yet doesn’t sacrifice its occupant’s comfort. In the next chapter, we will learn how a smart house can make an environmentally friendly air conditioning system.

STEM Contest

Participated in the
STEM Contest