Project in progress
Central Metereológica

Central Metereológica © LGPL

Receptor de datos como base de una Central Metereológica.

  • 14 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

Code

codeArduino
#include <SoftwareSerial.h>       
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

SoftwareSerial ESP8266(3, 2);   //Pin 2 and 3 act as RX and TX. Connect them to TX and RX of ESP8266      

#define DEBUG true

#define DHTPIN            7         // Pin which is connected to the DHT sensor.
#define DHTTYPE           DHT11     // DHT 11 // Uncomment the type of sensor in use:
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;


String mySSID = "VTR-3xxxxxxxx570";       // WiFi SSID
String myPWD = "sb7xxxxxxxxxxxxxxxx9yj"; // WiFi Password
String myAPI = "AVxxxxxxxxxxxxxPFHJ";   // API Key
String myHOST = "api.thingspeak.com";
String myPORT = "80";
String myFIELD1 = "field1"; 
String myFIELD2 = "field2"; 




void setup()
{
  Serial.begin(9600);
  

  ESP8266.begin(9600);
  espData("AT+RST", 1000, DEBUG);                      //Reset the ESP8266 module
  espData("AT+CWMODE=1", 1000, DEBUG);                 //Set the ESP mode as station mode
  espData("AT+CWJAP=\""+ mySSID +"\",\""+ myPWD +"\"", 1000, DEBUG);   //Connect to WiFi network
  delay(1000);
  
  
  dht.begin();
  sensor_t sensor;   // Temperatura de 0 a 50 C; Humedad de 20 a 80% 
  dht.temperature().getSensor(&sensor);
  dht.humidity().getSensor(&sensor);

  delayMS = sensor.min_delay / 300;  // Set delay between sensor readings based on sensor details.
  
}

  void loop()
  {

  delay(delayMS);  // Delay between measurements.
  sensors_event_t event;  
  
  dht.temperature().getEvent(&event); // Get temperature event and print its value.
    float temp = event.temperature; 
    Serial.print("Temperatura: ");
    Serial.print(temp);
    Serial.println(" C");
 
    
  dht.humidity().getEvent(&event);   // Get humidity event and print its value.
    float humi = event.relative_humidity; 
    Serial.print("Humedad:     ");
    Serial.print(humi);
   Serial.println(" %");



    String sendData = "GET /update?api_key="+ myAPI +"&"+ myFIELD1 +"="+String(temp) +"&"+ myFIELD2 +"="+String(humi);
    
    espData("AT+CIPMUX=1", 1000, DEBUG);      
    espData("AT+CIPSTART=0,\"TCP\",\""+ myHOST +"\","+ myPORT, 1000, DEBUG);
    espData("AT+CIPSEND=0," +String(sendData.length()+4),1000,DEBUG);  
    ESP8266.find(">"); 
    ESP8266.println(sendData);
    espData("AT+CIPCLOSE=0",1000,DEBUG);
    

    
    delay(5000);
  }
  
  
  
  ////

  String espData(String command, const int timeout, boolean debug)
  
  
{
  
  // Serial.println(command);

//
  
  String response = "";
  ESP8266.println(command);
  long int time = millis();
  
  while ( (time + timeout) > millis())
  {
    while (ESP8266.available())
    {
      char c = ESP8266.read();
      response += c;
    }
  }
  if (debug)
  {
    //Serial.print(response);
  }
  return response;
}

Comments

Similar projects you might like

Personal Weather Station (Arduino+ ESP8266 + Thingspeak)

Project tutorial by Jayraj Desai

  • 51,646 views
  • 32 comments
  • 108 respects

Central Heating Boiler Control Box

Project tutorial by Peter Groeneveld

  • 9,744 views
  • 10 comments
  • 44 respects

Wifi Controlled Car with Central Hub

Project showcase by Cooper and Vaughn

  • 2,573 views
  • 0 comments
  • 11 respects

10 Awesome Beginner Arduino Projects

by RoyTobby

  • 103,897 views
  • 1 comment
  • 25 respects

Temperature and Humidity Logger (Using Arduino)

Project showcase by lmsousa

  • 7,778 views
  • 3 comments
  • 34 respects

Rube Goldberg Weather Station with Internet Data Storage

Project in progress by randtekk

  • 6,705 views
  • 6 comments
  • 42 respects
Add projectSign up / Login