For our Arduino experiments we are using multiple sensors to measure the room-environment.

During these experiments we’ve noticed the sensors are giving back different values when adding more sensors. At that moment we only used the USB to power our Arduino.

The setup for this Arduino experiment is:

  • DTH-22: form Temperature/Humidity,
  • BMP-180: barometric pressure and temperature
  • PIR motion detector: to register if there is movement in the room
  • Light Sensor
  • MQ-131: Ozon
  • MQ-135: Sensor Air Quality Sensor
  • MG-811: CO2

The first measurements with the USB connection for the MQ-135 are above the 200.
We’ve bought an adaptor for the Arduino (1500 m-amp, universal adaptor). When using the new adaptor for supplying the power the values dropped significantly. The values changed back to values we measured when using only one-sensor with a USB power supply. This indicates that you need external power if you are using more gas-sensors, to get values you can trust.

Below we’ve added the the Arduino code for the readers who are interested in it. This code is still in draft and we are still working on it.

To read the sensor-values we’ve used the freeware RS232 Datalogger by Eltima Software. The data appends to a RoomSensor.csv file.
That file is read from Excel. We use Excel to give us realtime graphic dashboard.

sensor-data

Arduino-Sketch for this experiment (still draft):

#include <SFE_BMP180.h>
#include <Wire.h>
#include <Time.h>
#include <TimeLib.h>
// #include <Arduino.h> // needed for string manipulation, werkt nog niet

#include <DHT.h>

// Carlo van Haren
// 24-03-2016
// Code for the room sensors
//   DHT22 for temperature and humidety
//   MQ-135 for cleanair
//   MQ-131 for ozon
//   Led to show if values are out of range


// how long wait in loop to perform next measurement
// int waittime = 30000;
int waittime = 10000;
// integers to set time (manually set for now) hr,min,sec,day,month,year
int hr=14; int mm=00; int sec=0; int dd=26; int mon=6; int yr=2016;

// DHT-22
  #include "DHT.h"
  
  #define DHTPIN 2     // the pin op de arduino used for te DHT22 (digital pin)
  #define DHTTYPE DHT22   // DHT 22  (AM2302)
  
  // My DHT22 is on a FC-22 board
  // Middle pin is connected to pin 2 of my Arduino
  // The + and - are connected to the +5V (max) and GND.
  
  DHT dht(DHTPIN, DHTTYPE);

// MQ-135
  const int gasPin = A0; //GAS sensor output pin to Arduino analog A0 pin

// MQ-131 (Ozon KS123)
  const int ozonPin =  A3;

// MG-811 (CO2)
  const int co2Pin =  A1;

// BMP180 presure, altitude
  SFE_BMP180 pressure;
  #define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters
  // values for BMP 180
  char status;
  double T,P,p0,a;

// Led
  int LEDpinRed = 10;          // connect Red LED to pin 10 (PWM pin)
  int LEDpinGreen = 11;
  int LEDbrightness;        //

// LightSensor
  int photocellPin = 2;     // the cell and 10K pulldown are connected to a0
  int photocellReading;     // the analog reading from the sensor divider

// PIR motion detector
  // Connection pins on my board are with potmeters towards me: left = grnd, middle=digital pin, right= 5v
  int pirPin = 9;    //the digital pin connected to the PIR sensor's output
  
  //the amount of milliseconds the sensor has to be low 
  //before we assume all motion has stopped
  long unsigned int pause = waittime * 5; // if 5 times in a row movement is detected 

  //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
  int calibrationTime = 30; 
  String  detectionchange = "init";   
  boolean   takeLowTime = false;
  int lowIn = 0;

// Time : to log the outcomes to date-time
  #define TIME_HEADER  "T"   // Header tag for serial time sync message 
  #define TIME_REQUEST  7    // ASCII bell character requests a time sync message 
  char timeString[12]; 
  char dateString[12];

void setup() {
  Serial.begin(9600); //Initialize serial port - 9600 bps
  // Initialize the sensor (it is important to get calibration values stored on the device).

  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.
  }

  // init motion detector
  pinMode(pirPin, INPUT);
      // pinMode(ledPin, OUTPUT);
      digitalWrite(pirPin, LOW);
    
      //give the sensor some time to calibrate
      Serial.print("calibrating sensor ");
        for(int i = 0; i < calibrationTime; i++){
          Serial.print(".");
          delay(500);
          }
        Serial.println(" done");
        Serial.println("SENSOR ACTIVE");
        delay(50);

  // initialization of time
  setSyncProvider( requestSync);
  setTime(hr,mm,sec,dd,mon,yr); // nodig zolang ik tijd opvragen nog niet goed heb
  dht.begin();

    Serial.println("Sensor, Date, Time, Humidity, Temperature, Heat Index, CleanAir, Ozon, CO2, Photocell, Temp (bmp80), Pressure (abs), Motion Change"); // headerline for the output ps date is for future use. I do not know how to do this yet
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);
  // get photocell reading
  photocellReading = analogRead(photocellPin); 

  // Controleer of alle gegevens kloppen, als deze iets vreemds aangeven (NaN - not a number) geen nummerieke waarde, dan is er iets niet in orde!

  // motion detection
        if(digitalRead(pirPin) == HIGH){
         detectionchange = "motion";
         takeLowTime = true;
       }
      if(digitalRead(pirPin) == LOW){       
        if(takeLowTime){
          lowIn = millis();          //save the time of the transition from high to LOW
          takeLowTime = false;       //make sure this is only done at the start of a LOW phase
          }
        if (millis() - lowIn > pause) {
            detectionchange = "no motion";      //output
           }
           else detectionchange = "motion";
      };
      
  if (isnan(t) || isnan(h)) {
    Serial.println("Kan niet lezen van DHT");
  } else {
    sprintf(timeString, "%02d:%02d:%02d",hour(),minute(),second()); 
    sprintf(dateString, "%d-%02d-%02d",year(),month(),day()); 
    Serial.print("Sensor1,");
    Serial.print(dateString); 
    Serial.print(",");
    Serial.print(timeString); 
    Serial.print(",");
    Serial.print(h,1);
    Serial.print(",");
    Serial.print(t,1);
    Serial.print(",");
    Serial.print(hic,1);
    Serial.print(",");
    Serial.print(analogRead(gasPin));
    Serial.print(",");
    Serial.print(analogRead(ozonPin));
    Serial.print(",");
    Serial.print(analogRead(co2Pin));
    Serial.print(",");
    Serial.print(photocellReading);
    Serial.print(",");
    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(T,2);
      } else Serial.print("Error");
    }
      Serial.print(","); 
      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 in mb
           Serial.print(P,2);
          //  Serial.print(P*0.0295333727,2); // in HG
        } else Serial.print("Error");
    }
    // Output for motion
    Serial.print(","); 
    Serial.print(detectionchange);
  }
  Serial.println("");
  if ( analogRead(gasPin) > 65 )
  {   analogWrite(LEDpinRed, 255);
      analogWrite(LEDpinGreen, 0);
   } else  { 
       analogWrite(LEDpinRed, 0);
       analogWrite(LEDpinGreen, 255);
   }
  

  delay(waittime);
}


time_t requestSync() 
 { 
   Serial.write(TIME_REQUEST);   
   return 0; // the time will be sent later in response to serial mesg 
}
Likes(0)Dislikes(0)
Categories: Arduino

0 Comments

Leave a Reply

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