📜 ⬆️ ⬇️

Ethernet weather station

It was written many articles on variations of weather stations on the Arduino platform. Data output was different everywhere. Let me introduce my variation, with data output via Ethernet.

Final photo assembly:



image

Components:



')
image



image



image



image

The DHT-22 sensors come in various versions, I came across a sensor ready for connection, with a pull-up resistor:

image



image
This sensor is found in various versions, it is necessary to watch the pinout and the presence of pull-up resistors to connect:

image

The final components of the scheme:


image

Tasks:


The main task was to implement the output of data on temperature, humidity and pressure in the home network, as well as developing and prototyping, a side task of load management through the network was implemented.
Implemented the ability to control any load via the WEB-interface.

Figuratively, the algorithm of the device looks like this:




Next, I cite the code, it contains many comments and I think will clarify what we are doing.

Sketch code:


Sketch code:
// ========================  ========== #include <SPI.h> #include <String.h> #include <Ethernet.h> #include "DHT.h" #include "Wire.h" #include "Adafruit_BMP085.h" // =============================================================== // ========================  ====================== byte mac[] = { 0xCA, 0xAF, 0x78, 0x1C, 0x13, 0x77 }; //mac -  ethernet shielda byte ip[] = { 192, 168, 1, 33 }; // ip  ethernet shielda byte subnet[] = { 255, 255, 255, 0 }; //  EthernetServer server(80); //  int ledPin = 4; //       4 Pin String readString = String(30); //string for fetching data from address boolean LEDON = false; //   -  // =============================================================== #define DHTPIN 3 //    DHT22 const unsigned char OSS = 0; // Oversampling Setting // =============================================================== // ========================  DHT======================= //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // ============================================================== DHT dht(DHTPIN, DHTTYPE); Adafruit_BMP085 bmp; // ===================================================== // ======================== .  4- ========== void setup(){ // Ethernet Ethernet.begin(mac, ip, subnet); // pin 4   pinMode(ledPin, OUTPUT); //enable serial datada print Serial.begin(9600); Serial.println("Port Test!"); //        Serial.println("GO!");//        dht.begin(); bmp.begin(); } // ============================================================== void loop(){ // ===================================================== float h = dht.readHumidity(); float t = dht.readTemperature(); float tdpa = bmp.readTemperature(); float Pa0 = (bmp.readPressure()); float Pa = (bmp.readPressure()/133.33);//   ... float Pa2 = (bmp.readPressure()/3386.582);//   ... if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("H=: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temp.=: "); Serial.print(t); Serial.println(" *C"); Serial.print("Temp.dat.BMP = "); Serial.print(tdpa); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(Pa); Serial.println(" mm."); Serial.print("Pressure = "); Serial.print(Pa2); Serial.println(" in Hg"); // ============================================================== // =============  ==================== EthernetClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { char c = client.read(); //read char by char HTTP request if (readString.length() < 30) { //store characters to string readString.concat( c); } //output chars to serial port Serial.print( c); //if HTTP request has ended if (c == '\n') { //   ? //Level=1 -  //Level=0 -  if(readString.indexOf("Level=1") >=0) { //  digitalWrite(ledPin, HIGH); // set the LED on LEDON = true; }else{ //  digitalWrite(ledPin, LOW); // set the LED OFF LEDON = false; } // ============= HTML-========================== client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("<head> "); client.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> "); client.println("<title> :: .Arduino:: V1.1</title>"); client.println("</head> "); client.println("<body"); client.println("<hr />"); client.println("<h1> ::.Arduino:: </h1>"); if (LEDON){ client.println("<form method=get name=LED><input type=radio name=Level value=1 CHECKED><input type=radio name=Level value=0><input type=submit value=OK></form>"); client.println("<font size='5′>LED-: "); client.println("<font size='5′>."); }else{ client.println("<form method=get name=LED><input type=radio name=Level value=1><input type=radio name=Level value=0 CHECKED><input type=submit value=OK></form>"); client.println("<font size='5′>LED-: "); client.println("<font size='5′>"); } //==============   web-====================== client.println("<hr />");//===================================== client.println("T = "); //  DHT 22 client.println(t); client.println(" *C"); client.println("<br> "); //  .  client.println(" = "); //  DHT 22 client.println(h); client.println(" %\t"); client.println("<br> "); //  .  client.println("<hr />");//===================================== client.println(" = "); //  BMP 085 client.println(Pa); client.println(" mm..."); client.println("<br> "); //  .  client.println("<hr />"); //===================================== client.println(" = "); //  BMP 085 client.println(Pa2); client.println(" in Hg"); client.println("<br> "); //  .  client.println("<hr />"); //===================================== client.println("T  = ");//  BMP 085 client.println(tdpa); client.println(" *C"); client.println("<br> "); //  .  client.println("<hr />"); //===================================== //============================================================== client.println("</body></html>"); //     //============== web-client=========================== readString=""; client.stop(); //============================================================== } } } } } } 



The web interface looks like this:



image

The interface has been made so far only for data acquisition and debugging, but in the future it will be modernized.
The output of pressure data was purposefully done in two ways, such as mm.rt.st. and inches of mercury
Due to the presence, as a reference sensor, of a watch with a barometer in inches Hg.

Device layout:


Device layout:
image


Device cost:



TOTAL: USD $ 65.9

I foresee at once that many will say that it is expensive, but for me the role was played by the fact of realization, and not the price.

Sketch and device layout:


LAN_Weather.rar

Future plans:



Photo plans further ...
433 MHz receiver, you can use any compatible.
image
The radio sensor of temperature and humidity of Oregon THGN132N on 433 MHz
image
The radio sensor of temperature and humidity of Oregon THGN132N on 433 MHz
image


Continued:


Ethernet Weather Station 2 - Continued ...

Related Links:


Arduino on Habré
Arduino & Oregon on Habré
We conjure a meteorological station ...
The content of the data transmitted by the Oregon sensor
Oregon protocol description
Oregon protocol parsing

Source: https://habr.com/ru/post/171525/


All Articles