fbpx

This project is about the creation of an indoor weather station with air quality sensors,humidity, temperature, CO2,sSO2,CO,Vibration and wind sensor.

This project is about the creation of an indoor/outdoor weather station with all the possible parameter measurement

The station has several sensors for:

  • Humidity,Temperature (DHT22/11)
  • MQ2 (Lpg,Propane,Alcohol)
  • MQ135 (Air quality sensor -CO,SO2,CO2)
  • Rain sensor
  • Vibration sensor
  • Wind flow sensor

The resulting data can be displayed various platforms like on a TFT screen,through an online dashboard or a Mobile app.

Step 1 : Create a DETAILED Schematic of What You Are Doing

 Create a DETAILED Schematic of What You Are Doing

For the schematic i have used EasyEDA software

https://easyeda.com/

Step 2: Select the Perfect Microcontroller for Your Project

NodeMCU is an open source firmware for which open source prototyping board designs are available. The name “NodeMCU” combines “node” and “MCU” (micro-controller unit). The term “NodeMCU” strictly speaking refers to the firmware rather than the associated development kits.

As i wanted a IOT platform integrated to my project,there is no other mcu(microcontroller) better than nodemcu(esp8266)

Step 3: Select the Sensors for Weather Monitoring

In order to develop the project we will need the following components:

  • NodeMCU ESP8266 microcontroller
  • 16 channel analog Multiplexer
  • LCD 16×2 I2C shield (optional as we will be using IOT Dashboard to monitor)
  • MQ2
  • MQ135
  • DHT22
  • Vibration sensor Wind sensor

Why Analog multiplexer?

It is very important for NodeMCU as it only has one Analog Pin, so for multiple sensors we require a analog multiplexer.

Sensors

analog multiplexer

Nodemcu

Step 4: Designing the PCB

As we will using this as a complete module,we then require a PCB board.

I have designed this using easyEDA

https://easyeda.com/

easyEDA Project

PCB design

Step 5: Simulated 2D and 3D Design View

This is how our board will look!

2D ,3D View

Step 6: PCB Order

I have ordered this PCB from

NextPCB

Step 7: Soldering Time!!!!!

This is how a neat and structured soldering looks!

Very much similar to our simulated version ūüôā

Step 8: Modules Intact(sensors)

Add the modules accordingly!!

Step 9: Working Time!!!!!!!!!!!

Yes its not any Star wars Shield, it is our board……pat yourself !

I have provided the code too:)

Weather station code

#include <ESP8266WiFi.h>

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_Client.h"

#define S3 D6

#define S2 D7

#define S1 D8

#define S0 D3

#define analogpin A0

/************************* WiFi Access Point *********************************/




#define WLAN_SSID    "*********"

#define WLAN_PASS    "*************"




/************************* Adafruit.io Setup *********************************/




#define AIO_SERVER   "io.adafruit.com"

#define AIO_SERVERPORT 1883          // use 8883 for SSL

#define AIO_USERNAME  "***********"

#define AIO_KEY     "*************"




/************ Global State (you don't need to change this!) ******************/




// Create an ESP8266 WiFiClient class to connect to the MQTT server.

WiFiClient client;

// or... use WiFiFlientSecure for SSL

//WiFiClientSecure client;




// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);




/****************************** Feeds ***************************************/




// Setup a feed called 'photocell' for publishing.

// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>

Adafruit_MQTT_Publish sensor_1 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mq2");

Adafruit_MQTT_Publish sensor_2 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mq135");

Adafruit_MQTT_Publish sensor_3 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/rain");

Adafruit_MQTT_Publish sensor_4 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/vibration");

Adafruit_MQTT_Publish sensor_5 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/dht");

// Setup a feed called 'onoff' for subscribing to changes.

//Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");




/*************************** Sketch Code ************************************/




// Bug workaround for Arduino 1.6.6, it seems to need a function declaration

// for some reason (only affects ESP8266, likely an arduino-builder bug).

void MQTT_connect();




void setup() {

 Serial.begin(115200);

 delay(10);

 pinMode(analogpin, INPUT);

 pinMode(S0,OUTPUT);

 pinMode(S1,OUTPUT);

 pinMode(S2,OUTPUT);

 pinMode(S3,OUTPUT);  




 Serial.println(F("Adafruit MQTT demo"));




 // Connect to WiFi access point.

 Serial.println(); Serial.println();

 Serial.print("Connecting to ");

 Serial.println(WLAN_SSID);




 WiFi.begin(WLAN_SSID, WLAN_PASS);

 while (WiFi.status() != WL_CONNECTED) {

  delay(500);

  Serial.print(".");

 }

 Serial.println();




 Serial.println("WiFi connected");

 Serial.println("IP address: "); Serial.println(WiFi.localIP());




 // Setup MQTT subscription for onoff feed.

 //mqtt.subscribe(&onoffbutton);

}




uint32_t x=0;




void loop() {

 // Ensure the connection to the MQTT server is alive (this will make the first

 // connection and automatically reconnect when disconnected). See the MQTT_connect

 // function definition further below.

 MQTT_connect();




 




 // Now we can publish stuff!

 Serial.print(F("\nSending Sensor's Value "));

 digitalWrite(S0,LOW);

 digitalWrite(S1,LOW);

 digitalWrite(S2,LOW);

 digitalWrite(S3,LOW);

 Serial.print("Sensor 1 ");Serial.println(analogRead(analogpin));

 Serial.print("...");

 int Value = analogRead(analogpin);

 if (! sensor_1.publish(Value)) {

  Serial.println(F("Failed"));

 } else {

  Serial.println(F("OK!"));

 }




 digitalWrite(S0,HIGH);

 digitalWrite(S1,LOW);

 digitalWrite(S2,LOW);

 digitalWrite(S3,LOW);

 Serial.print("Sensor 2 ");Serial.println(analogRead(analogpin));

 Serial.print("...");

 Value = analogRead(analogpin);

 if (! sensor_3.publish(Value)) {

  Serial.println(F("Failed"));

 } else {

  Serial.println(F("OK!"));

 }




 digitalWrite(S0,LOW);

 digitalWrite(S1,HIGH);

 digitalWrite(S2,LOW);

 digitalWrite(S3,LOW);

 Serial.print("Sensor 3 ");Serial.println(analogRead(analogpin));

 Serial.print("...");

 Value = analogRead(analogpin);

 if (! sensor_2.publish(Value)) {

  Serial.println(F("Failed"));

 } else {

  Serial.println(F("OK!"));

 }




 digitalWrite(S0,HIGH);

 digitalWrite(S1,HIGH);

 digitalWrite(S2,LOW);

 digitalWrite(S3,LOW);

 Serial.print("Sensor 4 ");Serial.println(analogRead(analogpin));

 Serial.print("...");

 Value = analogRead(analogpin);

 if (! sensor_4.publish(Value)) {

  Serial.println(F("Failed"));

 } else {

  Serial.println(F("OK!"));

 }

  digitalWrite(S0,LOW);

 digitalWrite(S1,LOW);

 digitalWrite(S2,HIGH);

 digitalWrite(S3,LOW);

 Serial.print("Sensor 5 ");Serial.println(analogRead(analogpin));

 Serial.print("...");

 Value = analogRead(analogpin);

 if (! sensor_5.publish(Value)) {

  Serial.println(F("Failed"));

 } else {

  Serial.println(F("OK!"));

 }




 delay(7000);

 // ping the server to keep the mqtt connection alive

 // NOT required if you are publishing once every KEEPALIVE seconds

 /*

 if(! mqtt.ping()) {

  mqtt.disconnect();

 }

 */

}




// Function to connect and reconnect as necessary to the MQTT server.

// Should be called in the loop function and it will take care if connecting.

void MQTT_connect() {

 int8_t ret;




 // Stop if already connected.

 if (mqtt.connected()) {

  return;

 }




 Serial.print("Connecting to MQTT... ");




 uint8_t retries = 3;

 while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected

    Serial.println(mqtt.connectErrorString(ret));

    Serial.println("Retrying MQTT connection in 5 seconds...");

    mqtt.disconnect();

    delay(5000); // wait 5 seconds

    retries--;

    if (retries == 0) {

     // basically die and wait for WDT to reset me

     while (1);

    }

 }

 Serial.println("MQTT Connected!");

}

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

or

Log in with your credentials

or    

Forgot your details?

or

Create Account