Project tutorial
Smart Home Mini Arduino - In 30 Minutes - Posting in Ubidots

Smart Home Mini Arduino - In 30 Minutes - Posting in Ubidots © GPL3+

Make your smart home with Arduino system in less than 30 minutes with this project . Simple, no complicated codes. So let's start?

  • 15,552 views
  • 2 comments
  • 30 respects

Components and supplies

Apps and online services

Ubidots
Ubidots
Make your account , create 3 variables , take the data directly from your Arduino Ethernet Shield

About this project

Smart Home Mini - Post in Ubidots

A few days ago , I became interested more for IoT technology and its facilities and possibilities.

Thinking about it and doing intensive research on the web, I found that there were no tutorials and simple designs, anyone with little or none experience with Arduino, API, JSON, WEB SERVER and a plurality of expertise could enjoy this feature ( IoT ). 

This publication is simple to send variables sensors to clound ( Ubidots ) in a fast , direct and dynamic way. I will not describe in this tutorial step by step account setup , since the material of their own website is much better than what I could do. www.ubidots.com

Sensor 1 - DHT11

Will need only one sensor, in my case I used a DHT11 sensor, but the Internet has several ways to make a transistor pick up ambient temperature information.

Well, comments of the DHT11 sensor is a device that collects temperature and humidity environment, almost everyone who bought a starter kit have this sensor.

This sensor has three terminals, one VCC to left, another in the center OUT(Data Signal) and GND (ground) right.

Identified there in your component?

We need to connect it to breadboard it will connect to other more on sensor, you can follow the example we went through, so the wiring diagram had been clearer.

After that, we will connect the breadboard to Arduino, in my case I used the MEGA 2560, but nothing prevents you to use any model you have, because we use the total project only 3 Digital pins and 1 Analog pin.

Again nothing prevents you to modify and test in your project, for to understand better, but do it after mounting the way they explain, it will be easier after work, going for me.

Once connected to the terminals VCC and GND, the OUT (Data Signal) pin plug in the Digital pin 3 of your Arduino.

Ready your sensor DHT is already positioned.

Sensor 2 - PIR DYP-M003

Let's go to another sensor, in my case I used a PIR sensor DYP-ME003 (Motion Sensor), this consists of three terminals, see the image, and the terminal left VCC (5V-12V), the central OUT and the right terminal GND (ground) .

Once identified terminals, connect them to breadboard, terminal OUT at pin A1 (Analog 1) of the Arduino.

The approach to the regulation of sensitivity and activation time, I'll leave as homework for you search the internet, material widely publicized in search websites.

Now that the sensors are positioned and properly connected, let the final part of the physical links of the project.

Others - LED (green)

The design of the LED can be both appearing on pin 13 of the Arduino and an external LED, I opted for external LED only as a way to better display the drive motion sensor PIR DYP-M003.

Note that the scheme used, connect the cathode on GND (ground) and the anode in a 220 ohm resistor, +/- 5% and turn it to the Arduino pin 4.

We're almost there , the timer tah running there?

Others - Buzzer

The final link is the simplest , used a buzzer , which is triggered when the PIR sensor recognizes movement in the environment , therefore, beyond the LED warn visually , have a buzz that warns the presence of movement, this can be used to control access or as a primitive alarm, giving the idea of ​​how to integrate all these features at once .

The buzzer has a positive pole , which usually in addition to their greater attachment terminal, a markup on top ( +) indicating the same and a negative pole, usually a lower leg GND (ground ) .

The connection is simple, the lower leg binds to the GND (ground ), and the greater leg (+) in Arduino pin 2 .

Ready, is mounted all the physical part of your Smart Home Mini system , now let's make the magic happen.

Download the available code , open the Arduino IDE and upload it to your Arduino and see the operation .

Remember that to send the data from the sensors , need to set in your account Ubidots the variables will be three variables , humidity , temperature and movement , once you have the data of these variables add fields the indicated code , set data LOCAL NETWORK of its Ethernet Shield and see how simple it is .

Take the opportunity to study the code, thus understood better than the coding is simple, so you could play with it !

Thank's for your Time, stopwatch! :))


Code

Humidity And Temperature And presence sensor POST With UbidotsArduino
All code and sensors
#include <DHT.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
  0xZZ, 0xZZ, 0xZZ, 0xZZ, 0xZZ, 0xZZ // Change all ZZ MAC ADDRESS ETHERNET SHIELD
};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(0, 0, 0, 0); ETHERNET SHIELDIP ADDRESS LOCAL LAN

// fill in your Domain Name Server address here:
IPAddress myDns(0, 0, 0, 0); DNS IP ADDRESS LOCAL LAN

// initialize the library instance:
EthernetClient client;
   
String idvariable = ""; //Varible Temperature UBIDOTS
String idvariable_umidade = ""; //Variable Humidity UBIDOTS
String idvariable_sensorPIR = ""; //Variable presence sensor UBIDOTS
String token = ""; //TOKEN UBIDOTS

//Define PIN do Sensor
#define DHTPIN A1 // pino que estamos conectado
#define DHTTYPE DHT11 // DHT 11
 
// Conecte pino 1 do sensor (esquerda) ao +5V
// Conecte pino 2 do sensor ao pino de dados definido em seu Arduino
// Conecte pino 4 do sensor ao GND
// Conecte o resistor de 10K entre pin 2 (dados) 
// e ao pino 1 (VCC) do sensor
DHT dht(DHTPIN, DHTTYPE);

//SD Card
File dataFiles;


 
//Declarao das variveis referentes aos pinos digitais - ALARME + PIR.
int pinBuzzer = 2;
int pinSensorPIR = 3;
int pinLed = 4;
int valorSensorPIR = 0;

void setup() {

  
  // start serial port:
  Serial.begin(9600);

  // start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac, ip, myDns);
  // print the Ethernet board/shield's IP address:
  Serial.print("Conexao com a REDE LOCAL - IP: ");
  Serial.println(Ethernet.localIP());     
  delay(1000);  
  
  if (Ethernet.begin(mac) == 0) {
       Serial.println("Falha na Conexao com a REDE Local");
       // no point in carrying on, so do nothing forevermore:
       for(;;);
     }

  // SD Card - Iniciando
  Serial.println("Inicializando SD card...");

  if (!SD.begin(4)) {
    Serial.println("Falha na Inicializacao do SD Card!");
    Serial.println("Falha no Modo DATA LOGGER SD Card!");
    return;
  }
  Serial.println("Inicializacao Completa");
  Serial.println("Modo DATA LOGGER Inicializado com Sucesso");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  dataFiles = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (dataFiles) {
    Serial.print("Escrevendo no Arquivo test.txt...");
    dataFiles.println("Testando 1, 2, 3.");
    // close the file:
    dataFiles.close();
    Serial.println("Escrita FInalizada com Sucesso");
  } else {
    // if the file didn't open, print an error:
    Serial.println("Erro Abrindo arquivo test.txt");
  }

  // re-open the file for reading:
  dataFiles = SD.open("test.txt");
  if (dataFiles) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (dataFiles.available()) {
      Serial.write(dataFiles.read());
    }
    // close the file:
    dataFiles.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("Erro Abrindo arquivo test.txt para LEITURA");
  }
    
     
  //Inicia Sensor DHT
  Serial.println("Iniciando - Sensor - DHT");
  dht.begin();  

  //Definido pinos como de entrada ou de sada
  pinMode(pinBuzzer, OUTPUT);
  pinMode(pinSensorPIR, INPUT);
  pinMode(pinLed, OUTPUT);
  
}

void loop()
   {

    
      // A leitura da temperatura e umidade pode levar 250ms!
      // O atraso do sensor pode chegar a 2 segundos.
      float h = dht.readHumidity();
      float t = dht.readTemperature();
      // testa se retorno  valido, caso contrrio algo est errado.
      if (isnan(t) || isnan(h)) 
      {
        Serial.println("Falha na Leitura do Sensor - DHT");
      } else {

      //Lendo o valor do sensor PIR. Este sensor pode assumir 2 valores
      //1 quando detecta algum movimento e 0 quando no detecta.
      valorSensorPIR = digitalRead(pinSensorPIR);
       
      Serial.print("Sensor de Movimento - Valor Recebido: ");  
      Serial.println(valorSensorPIR);
       
        //Verificando se ocorreu deteco de movimentos
        if (valorSensorPIR == 1) {
          ligarAlarme();
        } else {
          desligarAlarme();
        }

        
       int value_temperatura = t;
       int value_umidade = h;
       int value_sensorPIR = valorSensorPIR; 
       save_value(String(value_temperatura));
       save_value_umidade(String(value_umidade));     
       save_value_sensorPIR(String(value_sensorPIR));
      }
   }
 
 
 //Grava Dados Variavel 1 - Temperatura
   void save_value(String value_temperatura)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_temperatura) + "}";
     num = var.length();
     delay(500);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

        //Temperatura
       client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("Falha na Gravacao - Variavel 2 - Temperatura");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("DESCONECTANDO...");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }   
     client.flush();
     client.stop();

   }

    //Grava DAdos Variavel 2 - Humidade
   void save_value_umidade(String value_umidade)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var2 = "{\"value\":"+ String(value_umidade) + "}";
     num = var2.length();
     delay(1000);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

        //Temperatura
       client.println("POST /api/v1.6/variables/"+idvariable_umidade+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_umidade+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var2);
       Serial.print(var2+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("Falha na Gravacao - Variavel 1 - Humidade");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("DESCONECTANDO...");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }

     client.flush();
     client.stop();

   }


    //Grava Dados Variavel 3 - Sensor PIR
   void save_value_sensorPIR(String value_sensorPIR)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var3 = "{\"value\":"+ String(value_sensorPIR) + "}";
     num = var3.length();
     delay(1000);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

        //Temperatura
       client.println("POST /api/v1.6/variables/"+idvariable_sensorPIR+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_sensorPIR+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var3);
       Serial.print(var3+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("Falha na Gravacao - Variavel 1 - Humidade");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("DESCONECTANDO...");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }

     client.flush();
     client.stop();

   }   


  //Alarme de Presena
  void ligarAlarme() {
    //Ligando o led
    digitalWrite(pinLed, HIGH);
     
    //Ligando o buzzer com uma frequencia de 1500 hz.
    tone(pinBuzzer, 1500);
    delay(4000); //tempo que o led fica acesso e o buzzer toca
    
    if (valorSensorPIR != 1){ 
      desligarAlarme();
    }
  }
 
  void desligarAlarme() {
    //Desligando o led
    digitalWrite(pinLed, LOW);
     
    //Desligando o buzzer
    noTone(pinBuzzer);
  }
   

  

Schematics

BreadboardSchematic
Fritzing Archive
BreadboardSchematic.fzz
BreadboardSchematic_bb.jpg
Breadboardschematic bb
BreadboardSchematic_Esquemático.png
Breadboardschematic esquema%cc%81tico

Comments

Similar projects you might like

Octopod: Smart IoT Home/Industry Automation Project

Project tutorial by Saksham Bhutani

  • 7,028 views
  • 8 comments
  • 30 respects

Smart Connected Open Source Pot (Scopot)

Project showcase by Hendra Kusumah

  • 2,943 views
  • 1 comment
  • 29 respects

Home Smart Home

Project tutorial by Syed Sanoor

  • 68,548 views
  • 10 comments
  • 193 respects

Arduino + Raspberry Pi + Ubidots Made Easy

Project tutorial by David Escobar

  • 13,507 views
  • 4 comments
  • 41 respects

Smart Home - Smart Rules using ARTIK Cloud & Photon

Project tutorial by Raghavendra Ponuganti

  • 4,102 views
  • 2 comments
  • 13 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 24,853 views
  • 17 comments
  • 75 respects
Add projectSign up / Login