Introduction: Arduino Weather Station

A simple tweeting weather station based on ESPDUINO , ability to view localised climate conditions any where in the world

Step 1: About :

This Instructable describes how to use Espduino (Arduino + wifi) to work as weather station.

Following functions are provided in weather station

(1) Temperature

(2) Humidity

(3) Pressure & Altitude

(4) Ambient Light level

All the above inputs are plotted on thinsspeak.com to have visual effect of climate change. Further an attempt is made to determine the worst weather conditions, such as prediction of rainfall or high speed winds etc.

Espdiono = Wifi Arduino provides an opurtunity to view the result any where in the world via thingspeak.com

check my @ https://thingspeak.com/channels/231848

Step 2: Components :

  1. Espduino : https://www.tindie.com/products/doit/espduinowifi-arduino-uno-r3/
  2. Pressure Sensor BM180 : https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup-
  3. Humidity sensor : https://www.tindie.com/products/Ruilongmaker/dht11-temperature-and-humidity-sensor
  4. LDR along with Resistor (Ligh Dependent resistor)
  5. Jumper Wires
  6. BreadBoard
  7. 9V 2A, Charger for Arduino
  8. 10 K Resistor (required for LDR circuit)
  9. Plastic Enclosure

Step 3: Assembling :

The weather station assembling is simple, i have directly assembled the Espduino and breadboard in the plastic enclosure, connection of various sensor with espduino is detailed out as below. For making the assembly simple, i have used double side tape for sticking out the espduino and breadboard to plastic enclousre.

BMP180 Interface with Espduino :

BM 180 ESPDUINO

SCL ------ SCL

SDA ------ SDA

VCC ------ +5V

GND ------ GND

DHT 11 Interface With Arduino

DHT 11 ESPDUINO

Pin 1 ------ +5V

Pin 2 ----- D3

Pin 3 ----- Not connected

Pin 4 ----- GND

LDR Interface With Arduino

LDR (Pin 1) ---- 10K resistor --- +5V

LDR (Pin 1) ---- A0 (Analog pin A0)

LDR (Pin 2) ---- GND

Step 4: Coding :

  • Following is the complete code for weather station, the code also describes how to publish the channel information on thingspeak website.

//Put all the library required here

#include <SFE_BMP180.h> // BMP180 Pressure sensor library

#include <wire.h>

#include <ThingSpeak.h> // Required for communicating with Thingspeak website #include< ESP8266WiFi.h> // ESP8266 Library #include < dht.h> // DHT 11 Temperature and humidity sensor library #include <WiFiClient.h> #include <ESP8266WebServer.h>

#include <ESP8266HTTPClient.h>

SFE_BMP180 pressure; #define ALTITUDE 84.0 // Define the Altitude at your location #define sealevelpressure 1013 // Sea level pressure is defined , this is further used to compute the difference between actual and sea level pressure to calculat the possibilty of rain

const char* ssid = "JioFi3_467"; // define your wifi SSID const char* password = "nhv6"; // Put your wifi password if any dht DHT; #define DHT11_PIN 3 // define the DHT Pin

float t,h,light,y; float abspress,Sealevelpress,Altitude,Temperature,relativepress;

unsigned long myChannelNumber = 231848; // Register at Thingspeak.com and put your channel no. const char * myWriteAPIKey = "LDRGM4H8YNJ578TA";

WiFiClient client;

String thingSpeakAPI = "api.thingspeak.com"; String talkBackAPIKey = "AQXDM7VGTYGV4XWT"; // Put your talkback key , the key is obtained from thingspeak website after registration String talkBackID = "14904"; const int checkTalkBackInterval = 15 * 1000; // Time interval in milliseconds to check TalkBack (number of seconds * 1000 = interval)

// Variable Setup long lastConnectionTime = 0;

void setup() {

// Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); 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"); //server.on ( "/", handleRoot );

// Print the IP address Serial.println(WiFi.localIP()); ThingSpeak.begin(client); if (pressure.begin()) { Serial.println("BMP180 init success"); } else { // Oops, something went wrong, this is usually a connection problem, // see the comments at the top of this sketch for the proper connections.

Serial.println("BMP180 init fail\n\n"); //while(1); // Pause forever. } }

void loop() { char status; double T,P,p0,a;

int chk = DHT.read11(DHT11_PIN); client.println("Temp: "); client.print(DHT.temperature); t = DHT.temperature; h = DHT.humidity;

light = analogRead(A0); Serial.println(); Serial.print(light); delay(1000); y = ((light/1023)*100); Serial.println(); Serial.print("provided altitude: "); Serial.print(ALTITUDE,0); Serial.print(" meters, "); Serial.print(ALTITUDE*3.28084,0); Serial.println(" feet"); // If you want to measure altitude, and not pressure, you will instead need // to provide a known baseline pressure. This is shown at the end of the sketch.

// You must first get a temperature measurement to perform a pressure reading. // Start a temperature measurement: // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned.

status = pressure.startTemperature(); if (status != 0) { // Wait for the measurement to complete: delay(status);

// Retrieve the completed temperature measurement: // Note that the measurement is stored in the variable T. // Function returns 1 if successful, 0 if failure.

status = pressure.getTemperature(T); if (status != 0) { // Print out the measurement: Serial.print("temperature: "); Serial.print(T,2); Serial.print(" deg C, "); Serial.print((9.0/5.0)*T+32.0,2); Serial.println(" deg F"); Temperature = T; // Start a pressure measurement: // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned.

status = pressure.startPressure(3); if (status != 0) { // Wait for the measurement to complete: delay(status);

// Retrieve the completed pressure measurement: // Note that the measurement is stored in the variable P. // Note also that the function requires the previous temperature measurement (T). // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) // Function returns 1 if successful, 0 if failure.

status = pressure.getPressure(P,T); if (status != 0) { // Print out the measurement: Serial.print("absolute pressure: "); Serial.print(P,2); Serial.print(" mb, "); Serial.print(P*0.0295333727,2); Serial.println(" inHg"); abspress = P;

// The pressure sensor returns abolute pressure, which varies with altitude. // To remove the effects of altitude, use the sealevel function and your current altitude. // This number is commonly used in weather reports. // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m. // Result: p0 = sea-level compensated pressure in mb

p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO) Serial.print("relative (sea-level) pressure: "); Serial.print(p0,2); Serial.print(" mb, "); Serial.print(p0*0.0295333727,2); Serial.println(" inHg"); Sealevelpress = p0; relativepress = p0-sealevelpressure;

// On the other hand, if you want to determine your altitude from the pressure reading, // use the altitude function along with a baseline pressure (sea-level or other). // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb. // Result: a = altitude in m.

a = pressure.altitude(P,p0); Serial.print("computed altitude: "); Serial.print(a,0); Serial.print(" meters, "); Serial.print(a*3.28084,0); Serial.println(" feet"); Altitude = a; } else Serial.println("error retrieving pressure measurement\n"); } else Serial.println("error starting pressure measurement\n"); } else Serial.println("error retrieving temperature measurement\n"); } else Serial.println("error starting temperature measurement\n");

delay(5000); // Pause for 5 seconds. ThingSpeak.writeField(myChannelNumber, 1, t, myWriteAPIKey); delay(20000); // ThingSpeak will only accept updates every 15 seconds. ThingSpeak.writeField(myChannelNumber, 2, h, myWriteAPIKey); delay(20000); ThingSpeak.writeField(myChannelNumber, 3, abspress, myWriteAPIKey); delay(20000); ThingSpeak.writeField(myChannelNumber, 4, Sealevelpress, myWriteAPIKey); delay(20000); ThingSpeak.writeField(myChannelNumber, 5, Altitude, myWriteAPIKey); delay(20000); ThingSpeak.writeField(myChannelNumber, 6, Temperature, myWriteAPIKey); delay(20000); ThingSpeak.writeField(myChannelNumber, 7, y, myWriteAPIKey); delay(20000); ThingSpeak.writeField(myChannelNumber, 8, relativepress, myWriteAPIKey); delay(20000); }

Step 5: Final Output :- Thingspeak Plot

There is also an option to add Talkback to device, wherin one can give commands to espduino as an when required over the internet. The necessary codes for talkback are included in .ino file.

Thingspeak also have a tweet control app, i have set the app to notify when some inputs reach some threshold levels, you can work out your own.

and there is my twitter handle

@Ashutosh_Dubey1

Step 6: Some Outdoor Mount Views:

Mounting the device outdoor, gives correct ambient light level as well as other parameters

Explore Science Contest 2017

Participated in the
Explore Science Contest 2017

Invention Challenge 2017

Participated in the
Invention Challenge 2017