Another environmental sensor for my parents' house

Aus DL8RDS Wiki
Version vom 18. März 2018, 23:08 Uhr von Dl8rds (Diskussion | Beiträge) (Images)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

1 Project Scope

As I have created an environmental sensor for the heating system of my parents' house a couple of years ago, I can monitor some basic values my parents' heating system. But the overall performance of the pumps can only be certified if we measure the heat that arrives in the last floor right under the roof. Given that this is a floor that is not visited every day, it was a good point to place another environmental sensor there.

2 Parts List

Total: 72

Working Time: 3 hours

3 Links

I found these resources very helpful:

4 Software

4.1 Arduino software

In order to use the cactus.io code examples, it was necessary to use the latest Arduino code. I downloaded the version 1.8.0.

4.2 The Code

Adafruit (Lady Ada) proposes a library that connects the BME 280 sensor with SPI. I didn't get the BME 280 working, probably because the Ethernet Shield also works with SPI. So it is very likely that there is some kind of conflict. This is why I decided to choose the other way: The BME 280 can also be attached via I2C. Cactus.io proposes some example code with I2C which worked fine.

Connectivity to the TEMT6000 sensor is straight forward as it is just a direct wire to the ADC pin 0.

In order to display everything on the web, I combined the cactus sketch with the standard Ethernet Webserver example.

/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor
  Designed specifically to work with the BME280 Breakout board
  ----> http://www.adafruit.com/products/2650
  This sketch only supports the I2C bus for connection.
 ***************************************************************************/

#include <Wire.h>
#include "cactus_io_BME280_I2C.h"
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xAA, 0xAA, 0xED
};
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);


// Create the BME280 object
BME280_I2C bme;              // I2C using default 0x77 
// or BME280_I2C bme(0x76);  // I2C using address 0x76

int temt6000Pin = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Bosch BME280 Barometric Pressure - Humidity - Temp Sensor | cactus.io"); 

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  bme.setTempCal(-1);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

   // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

  Serial.println("Pressure\tHumdity\t\tTemp\t\tTemp");
}

void loop() {

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 2");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<table>");
          bme.readSensor(); 
          
          Serial.print(bme.getPressure_MB()); Serial.print(" mBar\t");    // Pressure in millibars
          client.println("<tr><td>");
          client.println("Pressure"),
          client.println("</td><td>");
          client.print(bme.getPressure_MB()); 
          client.println("</td><td>");
          client.println(" mBar"); 
          client.println("</td></tr>");

          Serial.print(bme.getHumidity()); Serial.print(" %\t");
          client.println("<tr><td>");
          client.println("Humidity"),
          client.println("</td><td>");
          client.print(bme.getHumidity()); 
          client.println("</td><td>");
          client.println(" %");
          client.println("</td></tr>");

          Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");
          client.println("<tr><td>");
          client.println("Temperature_C");
          client.println("</td><td>");
          client.print(bme.getTemperature_C()); 
          client.println("</td><td>");
          client.println(" °C");
          client.println("</td></tr>");

          Serial.print(bme.getTemperature_F()); Serial.print(" *F\t");
          client.println("<tr><td>");
          client.println("Temperature_F"),
          client.println("</td><td>");
          client.print(bme.getTemperature_F()); 
          client.println("</td><td>");
          client.println(" °F");
          client.println("</td></tr>");

          int value = analogRead(temt6000Pin);
          Serial.print(value); Serial.println(" L");
          client.println("<tr><td>");
          client.println("Light");
          client.println("</td><td>");
          client.print(value); 
          client.println("</td><td>");
          client.println(" L");
          client.println("</td></tr>"),

          client.println("</table>");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }

}

5 Nano Pi Neo 2

The reason why I decided to kick out the Arduino was its inflexibility: It is simply a lot of effort to reprogram it in case something changes.

In addition to the sensors I was using up to now, I decided to add a MQ-7 carbon monoxide sensor. The device is now in the basement of my parents' house and since we have a wood stove there and given that the stove is in a closed confinement, I would like to measure also the carbon monoxide levels.

The MQ-7 is attached to a ADS1115 ADC, which again is connected to the Nano Pi with I2C.

Reading it out:

root@kellermon:~# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- 77                         

OK, here it is. The BME280 is on 0x77 and the ADC is in 0x48.

6 Images

6.1 The version till 2018-03 based on Arduino

2016-12-27-envsensor1.jpg 2016-12-27-envsensor2.jpg

2016-12-27-envsensor3.jpg 2016-12-27-envsensor4.jpg 2016-12-27-envsensor8.jpg

2016-12-27-envsensor5.jpg 2016-12-27-envsensor6.jpg 2016-12-27-envsensor7.jpg

6.2 The version after 2018-03 based on Nano Pi Neo 2