Adersh B
Published © GPL3+

Living Space web APP

Moving Somewhere New? Want to know the climate of a location with amenities nearby ? Use LIVING SPACE APP to find that perfect location.

AdvancedWork in progressOver 2 days1,437
Living Space web APP

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
MyOctopus i2c Barometric Air Pressure Sensor BMP280
MyOctopus i2c Barometric Air Pressure Sensor BMP280
×1
anemometer
×1
Dust/pollen sensor
×1
CO gas sensor
×1
UV sensor
×1
Ceramic Capacitive Rain Sensor
Telecontrolli Ceramic Capacitive Rain Sensor
×1

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015
Arduino IDE
Arduino IDE

Story

Read more

Schematics

img_20170430_145520940_KFMQ3UNpPi.jpg

NodeMCU ESP8266

Code

Mini IoT weather station

C/C++
instructions could be found with a simple google search
#include "DHT.h"
// WiFi Weather Station

// Required libraries
#include <ESP8266WiFi.h>

// Pin
#define DHTPIN 5

/* Detector air quality with ESP8266 and          **
** Optical Dust Sensor (GP2Y1010AU0F)              */
 
#define dust 14
#define UV 12
#define carbon 13
// Use DHT11 sensor
#define DHTTYPE DHT11

float voMeasured = 0;
float calcVoltage = 0;
float d = 0;



// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE, 15);

// WiFi parameters
const char* ssid = "enter your SSID";
const char* password = "enter your password";

// Create an instance of the server
WiFiServer server(80);

void setup() {

  // Start Serial
  Serial.begin(115200);
  delay(10);

  // Init DHT
  dht.begin();

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {

  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }

  // Reading temperature and humidity
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();

  delayMicroseconds(280);
  
  voMeasured = analogRead(dust); // read the dust value
  delayMicroseconds(40);
  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);
  d = 0.17 * calcVoltage - 0.1;
  
  Serial1.print("Raw Signal Value(0-1023) : ");
  Serial1.print(voMeasured);
  
  Serial1.print(" - Voltage: ");
  Serial1.print(calcVoltage);
  
  Serial1.print(" - Dust Density: ");
  Serial1.println(d); // mg/m3

//  UV sensor
int sensorValue;
    long  sum=0;
    String x;
    for(int i=0;i<1024;i++)// accumulate readings for 1024 times
    {
        sensorValue=analogRead(UV);
        sum=sensorValue+sum;
        delay(2);
    }
    long meanVal = sum/1024;  // get mean value
    Serial.print("The current UV index is:");
    int UV_inx = ((meanVal*1000/4.3-83)/21) ;
    if(0<=UV_inx<=2)
    {
       x="LOW";
    }
   else if(3<=UV_inx<=5)
   {
    x="MODERATE";
   }
   else if(6<=UV_inx<=7)
   {
    x="HIGH";
   }
   else if(8<=UV_inx<=10)
   {
    x="VERY HIGH";
   }
     else if(UV_inx<=11)
   {
    x="EXTREME";
   }
   else
   {
    x="UNAVAILABLE";
   }
    Serial.print("\n");
    delay(20);
  
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
  s += "<head>";
  s += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
  s += "<meta http-equiv=\"refresh\" content=\"60\" />";
  s += "<script src=\"https://code.jquery.com/jquery-2.1.3.min.js\"></script>";
  s += "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css\">";
  s += "<style>body{font-size: 24px;} .voffset {margin-top: 30px;}</style>";
  s += "</head>";

  s += "<div class=\"container\">";
  s += "<h1>WiFi Weather Station</h1>";

  s += "<div class=\"row voffset\">";
  s += "<div class=\"col-md-3\">Temperature: </div><div class=\"col-md-3\">" + String(t) + "</div>";
  s += "<div class=\"col-md-3\">Humidity: </div><div class=\"col-md-3\">" + String(h) + "</div>";
  s += "<div class=\"col-md-3\">DUST/POLLEN: </div><div class=\"col-md-3\">" + String(d) + "</div>";
  s += "<div class=\"col-md-3\">UV INDEX: </div><div class=\"col-md-3\">" + String(x) + "</div>";
  s += "</div>";
  s += "</div>";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disconnected");

  // The client will actually be disconnected
  // when the function returns and 'client' object is detroyed
}

Credits

Adersh B

Adersh B

1 project • 8 followers
An Engineer unrestricted by trade. Makers are meant be "Jack of all".

Comments