   bmp.begin();
   light.begin();
   sdBegin();
+  digitalWrite(WIFIPIN,HIGH); //active wifishield
+  digitalWrite(SDPIN,LOW); //inactive SD
   wifiBegin();
-  t.every(5*60*1000,arduairRead); // 5 minutes
-}
+  arduairSetup();
+  digitalWrite(GREEN_LED_PIN,LOW);
+}
+/**
+ * Arduair measuring cycle, it control all measuring cycle and ends writing the
+ * results in a SD card and sending a request to the server
+ * the measuring order is:
+ * 2) 30 s :   measuring PM10 and PM2.5.
+ * 3) 30 s :   measuring O3
+ * 4) 30 s :   measuring light, humidity, temperature and Pressure
+ * 5) 1 s :   detach Winsen sensor interrups (to avoid unnespected results during SD writing and http request)
+ * 6) 1 m :   writing in the SD and senging the recuest
+ * 7) 1 s :   clear variables
+ * Also, asynchronously, Arduair handles the interrupt for the Winsen sensors,
+ * thats comes every second per sensor.
+ *
+ */
 void loop() {
-  t.update();
-}
-void arduairRead(){
-    tableWrite();
-}
-void wifiBegin(){
-  while (status != WL_CONNECTED) {
-    Serial.print("Attempting to connect to SSID: ");
-    Serial.println(ssid);
-    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
-    status = WiFi.begin(ssid, pass);
-
-    // wait 10 seconds for connection:
-    delay(10000);
-  }
-  Serial.println("Connected to wifi");
-}
-
+  //2
+  pmRead();
+  //3
+  mq131Read();
+  //4
+  meteorologyRead();
+  //5
+  winsenRead(CO);
+  winsenRead(NO2);
+  winsenRead(SO2);
+  //6
+  getDate();
+  tableWrite();
+  request(h,t,p,l,co,so2,no2);
+}
+/**
+ * Perform a request to the given server variable. in the form:
+ * http://myserver.com/device/password/monthDay/month/year/hour/minute
+ * ?h=humidity&t=temperature&p=pressure&l=luminosity&co=[co]&o3=[o3]&&
+ * @param h   [description]
+ * @param t   [description]
+ * @param p   [description]
+ * @param l   [description]
+ * @param co  [description]
+ * @param so2 [description]
+ * @param no2 [description]
+ */
 void request(int h,int t,float p,float l,float co,float so2,float no2){
   // close any connection before send a new request.
   // This will free the socket on the WiFi shield
-   client.stop();
-
-  // if there's a successful connection:
-  if (client.connect(server, 80)) {
-    Serial.println("connecting...");
-
-    //String getRequest ="GET"+"hola"+" "
-    // send the HTTP GET request:
-    client.print("GET "); client.print("/"); client.print(device); client.print("/"); client.print(password);
-    // HTTP time
-    client.print(monthDay);client.print(month);client.print(year);client.print(hour);client.print(minute);
-    //http GET end
-    ; client.print(" HTTP/1.1");
-    client.println("");
-    // parameters:
-    client.print("h="); client.print(h); client.print(",");
-    client.print("t="); client.print(t); client.print(",");
-    client.print("l="); client.print(l); client.print(",");
-    client.print("co="); client.print(pm10); client.print(",");
-    client.print("o3="); client.print(pm10); client.print(",");
-    client.print("pm10="); client.print(pm10); client.print(",");
-    client.print("pm25="); client.print(pm25); client.print(",");
-    client.print("so2="); client.print(so2); client.print(",");
-    client.print("no2="); client.print(no2); client.print(",");
-    client.println("");
-    //server
-    client.print("Host: ");client.print(server);
-    client.println("User-Agent: Arduair");
-    client.println("Connection: close");
-    client.println();
-  }
+  client.stop();
+
+ // if there's a successful connection:
+ if (client.connect(server, 80)) {
+   Serial.println("connecting...");
+
+   //String getRequest ="GET"+"hola"+" "
+   // send the HTTP GET request:
+   client.print("GET "); client.print("/"); client.print(device); client.print("/"); client.print(password);
+   // HTTP time
+   client.print(monthDay);client.print(month);client.print(year);client.print(hour);client.print(minute);
+   //http GET end
+   ; client.print(" HTTP/1.1");
+   client.println("");
+   // parameters:
+   client.print("h="); client.print(h); client.print(",");
+   client.print("t="); client.print(t); client.print(",");
+   client.print("l="); client.print(l); client.print(",");
+   client.print("co="); client.print(pm10); client.print(",");
+   client.print("o3="); client.print(pm10); client.print(",");
+   client.print("pm10="); client.print(pm10); client.print(",");
+   client.print("pm25="); client.print(pm25); client.print(",");
+   client.print("so2="); client.print(so2); client.print(",");
+   client.print("no2="); client.print(no2); client.print(",");
+   client.println("");
+   //server
+   client.print("Host: ");client.print(server);
+   client.println("User-Agent: Arduair");
+   client.println("Connection: close");
+   client.println();
  }
-
+ }
+/**
+ * Writes the data in the SD.
+ * This function act in the following form: first, inactive the wifi-shield
+ * and active the SD shield, next writes the data in the SD and inactive
+ * the SD.
+ */
 void tableWrite(){
   //write data in SD
   digitalWrite(WIFIPIN,HIGH); //inactive wifi-shield
   digitalWrite(SDPIN,LOW); //active SD
 
   myFile = SD.open("DATA.txt", FILE_WRITE); //open SD data.txt file
+
   if (myFile){
-
-    int   h = dht.readHumidity();   // 1* medir humedad
-    int   t = dht.readTemperature();// 2* medir temperatura
-    float p = readPressure();       // 3* medir presion
-    float co= mq7Read();            // 4* medir sensor 1 y transformar
-    float so2=zeso2Read();          // 5* Meaus
-    float no2=zeno2Read();
-    float l=lightRead();
-    pmRead();
 
     myFile.print(h);
     myFile.print(",");

byte bcdToDec(byte val)  {
  return ( (val/16*10) + (val%16) );
}

void getDate(){
  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);

  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());


    Serial.print(" lux: ");
    Serial.print(lux);

    if (good) l=lux; else l="undefined";
    return l;
  }
}
/**
 * Reads Temperature from DHT
 */
float temperatureRead(){
  return dht.readTemperature()
}
/**
 * Reads Temperature from DHT
 */
float humidityRead(){
  return dht.readHumidity()
}
/**
 * Convert binary coded decimal to normal decimal numbers
 * @param  val byte value to be converteted
