Alex Warsun
Published © GPL3+

Smart Living Room (Home Theatre)

I built myself a voice controlled home theatre, with background light, screen and projector control. With an ESP8266 and an Arduino Nano.

IntermediateShowcase (no instructions)24 hours5,141
Smart Living Room (Home Theatre)

Things used in this project

Hardware components

ESP8266 ESP-01
Everything ESP ESP8266 ESP-01
Used for the communication between the amazon echo und the relay board
×1
Arduino Nano R3
Arduino Nano R3
used for the projector and the screen control
×1
Relay Shield for Particle Photon I²C 8-Channel SPDT 10-Amp
ControlEverything.com Relay Shield for Particle Photon I²C 8-Channel SPDT 10-Amp
this is not the exact hardware i used, but it's a 8-Channel Relay
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Smart living room schematic

I had to write on it, because there was no 8-Channel relay board.. sorry for that. Also its a different ESP8266 board. I'm using one with micro-USB socket.
Smart home vm3mcc29lo

Code

ESP8266 voice control

Arduino
for controlling the esp8266 with the amazon echo and the relays
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
#include "credentials.h"

#define SERIAL_BAUDRATE                 115200
#define LIGHT                             D0
#define LAMP                              D1
#define START_ARD                         D2


fauxmoESP fauxmo;

// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------

void wifiSetup() {

    // Set WIFI module to STA mode
    WiFi.mode(WIFI_STA);

    // Connect
    Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
    WiFi.begin(WIFI_SSID, WIFI_PASS);

    // Wait
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(100);
    }
    Serial.println();

    // Connected!
    Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());

}

void setup() {

    
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println();
    Serial.println();

    // Wifi
    wifiSetup();

    // Setting up
    pinMode(LIGHT, OUTPUT);
    pinMode(LAMP, OUTPUT);
    pinMode(START_ARD, OUTPUT);
    
    digitalWrite(LIGHT, HIGH);
    digitalWrite(LAMP, HIGH);
    digitalWrite(START_ARD, HIGH);

    fauxmo.enable(true);

    // Add virtual devices
    fauxmo.addDevice("Licht");
    fauxmo.addDevice("Lampe"); 
    fauxmo.addDevice("Beamer");
    
   // "Control section"
    fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state) {
        Serial.printf("[MAIN] Gerät #%d (%s) ist: %s\n", device_id, device_name, state ? "AN" : "AUS");

        if( (strcmp(device_name, "Licht") == 0)){
          if(state){
            digitalWrite(LIGHT, LOW);
            } else{
            digitalWrite(LIGHT, HIGH);
              }
          }//end of if

        if( (strcmp(device_name, "Lampe") == 0)){
          if(state){
            digitalWrite(LAMP, LOW);
            } else{
              digitalWrite(LAMP, HIGH);
              }//end of if-else
          }//end of if 

        if( (strcmp(device_name, "Beamer") == 0)){
          if(state){
            digitalWrite(START_ARD, LOW);
            } else{
              digitalWrite(START_ARD, HIGH);
              }//end of if-else
          }//end of if
          
    });

    // Callback to retrieve the current state
    fauxmo.onGetState([](unsigned char device_id, const char * device_name) {
        return digitalRead(LIGHT) == LOW;
        return digitalRead(LIGHT) == HIGH;
        return digitalRead(LAMP) == LOW;
        return digitalRead(LAMP) == HIGH;
        return digitalRead(START_ARD) == LOW;
        return digitalRead(START_ARD) == HIGH;
    });

}

void loop() {
    fauxmo.handle();

    static unsigned long last = millis();
    if (millis() - last > 5000) {
        last = millis();
        Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
    }

}

Arduino Nano projector control

Arduino
this code is for the Nano, which controls the projector and the screen.
#include <IRremote.h>

IRsend irsend;  // PIN 3

#define SCREEN_DOWN         6  //IN4
#define SCREEN_UP           7  //IN5

int aktiviert = 0;    // activation variable

void setup()
{
  Serial.begin(9600);
 // Setting up 
  pinMode(2, INPUT);
  pinMode(SCREEN_DOWN, OUTPUT);
  pinMode(SCREEN_UP, OUTPUT);

  // Turning the Relay switches off in the beginning 
   digitalWrite(SCREEN_DOWN, HIGH);
   digitalWrite(SCREEN_UP, HIGH);

}//end of setup()

void loop() {  
 if(digitalRead(2) == HIGH){
       if(aktiviert == 0){        //Screen down, projector on
         digitalWrite(SCREEN_DOWN, LOW);
         delay(1000);
         digitalWrite(SCREEN_DOWN, HIGH);
         delay(30000); //Wait 45 sec.
         irsend.sendNEC(0x61D6F807, 32);
         delay(15000);
         digitalWrite(SCREEN_UP, LOW);
         delay(1000);
         digitalWrite(SCREEN_UP, HIGH);
         aktiviert = 1;
       }//end of if
    }else {
      if(aktiviert == 1){         //Screen up, projector off               
         irsend.sendNEC(0x61D6F807, 32);
         delay(1000);
         irsend.sendNEC(0x61D6F807, 32);
         delay(1000);
         irsend.sendNEC(0x61D6F807, 32);
         digitalWrite(SCREEN_UP, LOW);
         delay(46000);
         digitalWrite(SCREEN_UP, HIGH);
         delay(1000);
         digitalWrite(SCREEN_DOWN, LOW);
         delay(1000);
         digitalWrite(SCREEN_DOWN, HIGH);
        aktiviert = 0;
        }//end of if       
      }//end of if-else
 }//end of loop()

Credits

Alex Warsun

Alex Warsun

1 project • 3 followers

Comments