Rosette 2.0: our Tesla answer



    Smart House. The concept of a truly modern home, where with the help of technology a person is provided with complete comfort. More and more people are buying turnkey solutions. unfortunately (especially because of the current course), many of these kits have greatly added to the price and often become too expensive a way to “touch the future”. And it remains to rejoice that still inquisitive minds are developing more and more DIY ways to automate their homes.

    I would like to tell you about the project that I spied on the BQ website. It always seemed to me that “Smart Home” is a complex technology and a person without a deep understanding of engineering and electronics should not even go in there. But as it turned out, everything is somewhat simpler.



    This project describes how to use the arduino-compatible board, a simple extension cord with a button, protocoder and a smartphone to turn on / off the light using voice commands. The basic principle is that you connect remotely to the board using bluetooth and by running the application on your smartphone, you can give a specific command. But first things first.

    Installation .

    The first thing you need to do is, of course, integrate the board into your extension cable.



    For this, first of all, this same extension cord must be dismantled in an absolutely barbaric way. Caring Spaniards warn with a large caps that it would be nice to disconnect the extension cord from the power supply before these manipulations.

    After you disassemble the extension cord, you can safely postpone the button - you will no longer need it. You are interested in the wires that went into it - there are only two of them. Most often they are blue and brown - we will repel them. The blue wire should be immediately soldered and shrink installed - these are the plastic “tubes” that you can easily find in any store for ham radio. This must be done, otherwise the exposed section of wires can soon lead to consequences that are not provided for by the project.

    The second wire does not need to be soldered. There, you will have two ends of the brown wire. They need to be installed in an arduino-compatible relay. The end coming from the power cord is installed in terminal C - central. With her you will not lose, she is in the middle. And the wire going from the “outlets” is to the NO terminal (normally open). If your relay is not labeled, rotate it with the terminals down. The left is the one you require.

    If everything is done right, now your extension cord from the inside will look something like this:



    After that, the extension cord can be “closed” by first passing the relay wire to connect the circuit board through the hole left from the button. The manipulations with the insides are over.



    Now you need to install the board itself. In the example, bq ZUM is used, the fundamental difference of which, in this case, lies in the integrated bluetooth module. However, ZUM can be replaced with another board, for example, Freeduino Uno. But then you additionally need the missing module.

    To securely attach the electronics to the extension cord, you will also need parts that are printed on a 3D printer. In addition to a small platform for the board, the number of parts also includes a container for the power module, where the batteries are installed. Surely with the help of additional electronics, you can power the board from the extension cord, but this example, unfortunately, is not considered.



    Having finally assembled all the electronics, we install it. The end result looks pretty nice, but the software part remains.

    Protocoder.

    Protooder is a programming environment + JavaScript framework for quickly building prototypes that can be used on Android devices. Installing it is very simple.



    The sketch for this project has been uploaded by the Spaniards to the public and there is no need to program anything. On the mobile screen, the application looks like this:



    Do not be alarmed by foreign non-English words, in the source code you can change the labels to whatever you want. In the application we see three buttons. And here is what each of them means:

    Conectar bluetooth - as it’s not hard to guess, by clicking this button you can through Protocoder join the desired bluetooth device. In our case, this device is a board;

    Desconectar- this is, accordingly, a break in communication. A very useful function, taking into account the fact that while the connection is established you cannot make changes to the code of the programmable board;
    Hablar - “speak.” By clicking this button, you will open the usual voice input service from google. It is by pressing this button that you will “enter” your commands;



    Here is the code for Protocoder and your smartphone:

    var bluetoothOn=0;
    ui.addButton("Conectar bluetooth", 10, 150, function() {
        network.connectBluetoothSerialByUi(function(m, data) {
            txt.text(data + "\n");
        });
        bluetoothOn=1;
    })
    ui.addButton("Desconectar", 380, 150, function() {
        network.disconnectBluetooth();
    })
    ui.addButton("Hablar", 280, 550, function() {
        media.startVoiceRecognition(function(text) { 
            console.log(text);
            if (bluetoothOn==1) {
                if(text=="enciende") network.sendBluetoothSerial("=on+");
                if(text=="apaga") network.sendBluetoothSerial("=off+");
                if(text=="parpadea cada segundo") network.sendBluetoothSerial("=1+");
                if(text.substring(0,13)=="parpadea cada" && text.substring(14,21)!="segundo" ) network.sendBluetoothSerial("="+text.split(" ")[2]+"+"); 
            }
        });
    })
    


    Take a close look at him. You will find on the 19th, 20th and 21st lines such words as enciende (“Turn on”), apaga (“Redeem”) and parpadea cada segundo (“Blink every second”). If you do not want to train your Spanish, these words should be replaced with more familiar ones. It is not difficult to guess what each team does.

    Now your mobile can join the board and give commands to it. But she herself is not yet able to perceive them - she also needs to be programmed.

    First of all, if you intend to use the source of the Spaniards, make sure that the relay is connected to the board in the correct pins: Have you made sure



    ? Then it's time to fill in the code. This is done using the Arduino IDE. Here is the code:

    String inString ="";
    int pinRele=7;
    void setup() {
    	Serial.begin(19200);
    	Serial.flush();
    	pinMode(pinRele, OUTPUT);
    	pinMode(13, OUTPUT);
    }
    void readFromAndroid(){
    	char inChar;
    	while(Serial.available()>0){
    		inChar =(char) Serial.read();
    		Serial.flush();
    		if (inChar=='='){
    			inString="";
    		}
    		else if(inChar!='+'){
    			inString+=inChar;
    		}
    	}
    }
    void writeData(){
    	if (inString=="on")	{
    		digitalWrite(13, HIGH);
    		digitalWrite(pinRele, HIGH);}
    	else if (inString=="off")	{
    		digitalWrite(13, LOW);	
    		digitalWrite(pinRele, LOW);}
    	else if (inString.toInt()){
    		digitalWrite(13, HIGH);
    		digitalWrite(pinRele, HIGH);
    		delay(inString.toInt() *1000 );
    		digitalWrite(13, LOW);	
    		digitalWrite(pinRele, LOW);
    		delay(inString.toInt() *1000 );
    	}
    }
    void loop() {
    	if (Serial.available()>0){
    		readFromAndroid();
    	}
    	writeData();
    }
    


    An important point. If you do not use the bq ZUM board, then there is a high probability that the bluetooth module is installed at a different speed. Then you need to replace the line:
    Serial.begin(19200);
    


    For example:
    Serial.begin(9600);
    


    There are also enough examples on the Internet how to independently change the data transfer speed of the bluetooth module itself.

    So, after installing the program on both the smartphone and the board, our project is completed. It's time to take fresh batteries, connect the extension cord to the network, and to it, for example, a lamp. What should you end up with? Demonstration - in the video:



    Of course, activating on / off using voice commands is not a smart home yet. But the main thing is the idea. And the idea is that with the help of DIY-projects, anyone can easily be Jack independently, who will build a house. Very smart home.

    PS Link with project files
    PSS I hope Elon Musk will see the text, and buy us all to Tesla for 400 tysjach dollarov. Spasibo!

    Also popular now: