Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By piersfinlayson
#61713
ErikLem wrote:(Since all commercial products around are also quite expensive, I'm kind of guessing that measuring co2/voc is just a lot more complicated than temperature or humidity. have a look at this list for instance:
http://www.energycircle.com/guide/guide ... althy-home)


Another option is to use the analog sensors and use an external ADC that supports I2C, such as the ADS1115. This supports 2 differential inputs, or 4 single inputs, and can be controlled over I2C. You'll need a logic level shifter as well - as the ADS range requires 5V. Not hard though. The combination of an ADS1115 board and a logic level shifter should only come to $2-3.

As to the reason for the cost of these devices while I suspect it is more complicated to build such a think, I suspect the reason for the price difference is more to do with quantity - and probably safety concerns as well.
User avatar
By vcch
#61724 Scaling is really easy - just buy an adjustable resistor - they're cheap and you could keep a dozen they're always useful !

You can also find ozone & fine particles (PM25) sensors for a few dollars on alibaba.com
I did this with a routine feeding directly a google spreadhseet file (just use the search button of this forum if you're interested in doing this). good luck !
User avatar
By GengusKahn
#61730 Hi there, I have been adding 5v ADC's for MQ-2, MQ-7 etc.....Using the Arduino.....

Code: Select allvoid GetNano(){
int lOop=0;
    New1="";
    hostStringC="";
  delay(50);
  Wire.begin(4,5);            // I2C Bus 0
  delay(20);
  digitalWrite(2, LOW);       // When Set Request To Send Active Slave will refresh data....
  delay(RTSDelay);            // This will make sure the Arduino is in the for loop refreshing data......     
  Wire.beginTransmission(8);
 // yield();
  Wire.requestFrom(8, 6);     // request 6 bytes from slave device #8 bus 0 (Arduino Mini Pro costs £8 for 5 from China)
   while (Wire.available()) { // slave may send more Bytes than requested, embedded Respose Bytes - 8:15
    if(lOop>=2){
    one1 = Wire.read();       // receive a raw byte
    two1 = Wire.read();;
    three1 = Wire.read();
    four1 = Wire.read();
     if(Wire.available()>0){
     char c =  Wire.read();
     hostStringC += c;
     }
    }
  lOop++;
  char c = Wire.read();       // receive a byte as character
  New1+=c;
  }
 Wire.endTransmission();
  delay(25);
  lOop=0;
    New2="";
  hostString2C="";
  Wire.beginTransmission(6);
  Wire.requestFrom(6, 6);     // request 6 bytes from slave device #6 bus 0 (Arduino Mini Pro costs £8 for 5 from China)
   while (Wire.available()) { // slave may send more Bytes than requested, embedded Respose Bytes - 8:15
    if(lOop>=2){
    one12 = Wire.read();        // receive a raw byte
    two12 = Wire.read();;
    three12 = Wire.read();
    four12 = Wire.read();
     if(Wire.available()>0){
     char c =  Wire.read();
     hostString2C += c;
     }
    }
  lOop++;
  char c = Wire.read();       // receive a byte as character
  New2+=c;
  }
 Wire.endTransmission();
  delay(100);


New2=New2.substring(0,2);
if(New2=="A2"){// Very Simple error checking - ignored if missing.........
    four2=four12;
    three2=three12;
    two2=two12;
    one2=one12;
}
 delay(75);
 Wire.begin(12,13);           // I2C Bus 1
 delay(75);
 myHTU21D.begin();
 delay(50);
   Hum = myHTU21D.readCompensatedHumidity();
   Temp = myHTU21D.readTemperature();
   CoUnt++;
   ulMeasCount++;
    if(ulMeasCount>300){ulMeasCount=1;}
   pfTemp[ulMeasCount] = Temp;
   New1=New1.substring(0,2);  // Simple error checking.........
if(New1=="A1" && one1!=255 && four1!=255 ){
   pfVcC =  ESP.getVcc();
   duration1 = "";
   int hr,mn,st;
   st = millis() / 1000;
   mn = st / 60;
   hr = st / 3600;
   st = st - mn * 60;
   mn = mn - hr * 60;
   if (hr<10) {duration1 += ("0");}
   duration1 += (hr);
   duration1 += (":");
   if (mn<10) {duration1 += ("0");}
   duration1 += (mn);
   duration1 += (":");
   if (st<10) {duration1 += ("0");}
   duration1 += (st);
   four=four1;
   three=three1;
   two=two1;
   one=one1;
if(one>=12){SmAlrm=1;sAcnt++;}
if(two>=200){COAlrm=1;cAcnt++;}
/*
Serial.println("|_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_¬");
Serial.print("\r\n0  Device ID Value : ");
Serial.println(New1);
Serial.print("\r\n1 Arduino A0 Value  ");
Serial.print((float(one*20)));
Serial.print(" MilliVolts\r\n2 Arduino A1 Value  ");
Serial.print((float(two*2)/100)); 
Serial.print(" Volts\r\n3 Arduino A2 Value  ");
Serial.print((float(three*2)/100));
Serial.print(" Volts\r\n4 Arduino A3 Value  ");
Serial.print((float(four*2)/100));
Serial.print(" Volts\r\n5 ESPVcc ADC Value  ");
Serial.print(pfVcC/1000, 2);
Serial.print(" Volts\r\n6    SHT21 Humidity ");
Serial.print(Hum);
Serial.print(" RH %\r\n7 SHT21 Temperature ");
Serial.print(Temp);
Serial.print(" Deg C\r\n     Running Time : ");
Serial.print(duration1);
Serial.print("\r\nLoops ");
Serial.print(CoUnt);
Serial.print("\r\nSingle Errors ");
Serial.print(FCoUnt);
Serial.print("\r\nArduino Resets(+2 errors) ");
Serial.println(ReSet);
*/
}else{
    /*
    Serial.println("\r\nError in IIC Retrying.... ");
    Serial.print("\r\nLoops ");
    Serial.println(CoUnt);
    Serial.print("\r\nSingle Errors ");
    Serial.println(FCoUnt);
    Serial.print("\r\nArduino Resets(+2 errors) ");
    Serial.println(ReSet);
    */
    FCoUnt++;
  }
digitalWrite(2, HIGH);      // Set Request idle
}


Arduino Slave....

Code: Select all/* This provides some easy access to the Arduino peripherals and Libraries via an 6 byte transfer
   run any sketch and include this snippet to provide readings to the ESP8266 Via I2C using the array.
   ESP8266 connected to I2C via pins 4(SDA) and 5(SCL)
   Arduino pins 4 and 5 are connected via 5v to 3v converter to the ESP8266 pins 4 and 5.
   The 6 bytes are arranged - bytes 0+1 are a 2 char ID, bytes 2-5 Arduino A0 to A3 reading
   presenting data as byte allows very simple transfer.
   ESP8266 pin0 Used to Reset this Arduino and ESP8266 pin2 to send Request for data (RTS) to this Arduino.....
   Arduino Pin  Esp Pin
   Reset         0
   2             2
   A4            4
   A5            5
   All via 5V to 3V shifter......Arduino 5v side can take more Slaves......
*/
#include <Wire.h>
#include "HTU21D.h"

HTU21D myHTU21D;

// Send variables
char msg[6];

// Recieved variables
String ArdData;

// Measurement timer
unsigned long ulNextMeas_ms=1000;
int RTSState;                        // Current RTS State
int lastRTSState = HIGH;             // Previous RTS State
unsigned long lastResponseTime = 0;  // Last RTS Toggled time
unsigned long ResponseDelay = 25;    // Delay to provide time for pin to settle.....

void ReadSensors() {
  Wire.write(msg);             // Response to Master Request
}


void setup() {
  pinMode(2, INPUT);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
    pinMode(5, OUTPUT);
  digitalWrite(5, LOW);
 // Serial.begin(115200);
 // Serial.println("\r\n\r\n");
  Wire.begin(8);               // join i2c bus with address #8
  Wire.onRequest(ReadSensors); // register event
  delay(25);
  msg[0]='A';  //  Used to identify which Arduino, Use as many as needed adjust the Address!
  msg[1]='1';  //  These 2 bytes are used to help verify the data in the Master Sketch
  for(int i=0;i<4;i++){
      delay(10);
  int sensorValue = analogRead(i)/4;
      delay(10);
  if(sensorValue>254){sensorValue=254;}
  //sensorValue=constrain(map(sensorValue, 0, 1020, 0, 254), 0, 254);
  msg[i+2]=sensorValue;
  }
}

void loop() {
  int RTSFlag = digitalRead(2);
  if (RTSFlag != lastRTSState) {
    lastResponseTime = millis();
  }
  if ((millis() - lastResponseTime) > ResponseDelay) {
    if (RTSFlag != RTSState) {
      RTSState = RTSFlag;
      if (RTSState == LOW) {
  msg[0]='A';  //  Used to identify which Arduino, Use as many as needed adjust the Address!
  msg[1]='1';  //  These 2 bytes are used to help verify the data in the Master Sketch
  for(int i=0;i<4;i++){
    delay(10);
  int sensorValue = analogRead(i);
    delay(10);
  sensorValue=constrain(map(sensorValue, 0, 1020, 0, 254), 0, 254);
  msg[i+2]=sensorValue;
  }
      }
    }
  }
    lastRTSState = RTSFlag;   
    yield();
}