Infineon Team
Published © MIT

The Ultimate IoT Sensor Box for Smart Offices and Buildings

Improve your flex desk office experience with this innovative IoT sensor box

BeginnerFull instructions provided4 hours1,733
The Ultimate IoT Sensor Box for Smart Offices and Buildings

Things used in this project

Story

Read more

Custom parts and enclosures

Baseplate of IoT sensor box

Cover of IoT sensor box

Schematics

Fritzing of IoT sensor box

Code

Main Code

Arduino
This is the main code running on your controller
/************************** Configuration ***********************************/
// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/
#include <Arduino.h>
#include <pas-co2-ino.hpp>
#include <Dps422.h>
#include "DHT.h"            

#define I2C_FREQ_HZ 400000 

//Humidity
#define DHTPIN 14     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
float humidity_read;
 
//CO2 sensor
PASCO2Ino cotwo;
int16_t co2ppm_read;
int i = 0;

//Pressure/ Temperature sensor
Dps422 Dps422PressureSensor = Dps422();
float temperature_read;
float pressure_read;

//Noise
const int sound_pin = 33;
int sound_read;

//presence
const int radar1_pin = 32; int radar1_read;
const int radar2_pin = 15; int radar2_read;
const int radar3_pin = 21; int radar3_read;
const int radar4_pin = 34; int radar4_read;

// set up the feeds
AdafruitIO_Feed *humidity = io.feed("humidity");
AdafruitIO_Feed *CO2 = io.feed("CO2");
AdafruitIO_Feed *pressure = io.feed("pressure");
AdafruitIO_Feed *temperature = io.feed("temperature");
AdafruitIO_Feed *Noise = io.feed("Noise");
AdafruitIO_Feed *presence1 = io.feed("presence1");
AdafruitIO_Feed *presence2 = io.feed("presence2");
AdafruitIO_Feed *presence3 = io.feed("presence3");
AdafruitIO_Feed *presence4 = io.feed("presence4");

void setup() {

  // start the serial connection
  Serial.begin(115200);
  // wait for serial monitor to open
  while(! Serial);

  // start all sensors
  Wire.begin(SDA,SCL,I2C_FREQ_HZ); 
  //CO2
  cotwo.begin();
  //Pressure / Temperature
  Dps422PressureSensor.begin(Wire);
  //humidity
  dht.begin();
  //noise detection
  pinMode(sound_pin, INPUT);  
  //presence detection
  pinMode(radar1_pin, INPUT);  
  pinMode(radar2_pin, INPUT);  
  pinMode(radar3_pin, INPUT);  
  pinMode(radar4_pin, INPUT);  
  
  Serial.print("Connecting to Adafruit IO");
  // connect to io.adafruit.com
  io.connect();
  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

  //Read all sensor values
  cotwo.startMeasure();
  do{cotwo.getCO2(co2ppm_read);
    i++; if(i>1000){Serial.print("no "); i = 0; break;}
    } while (0 == co2ppm_read);
    Serial.print("co2 ppm value : ");
    Serial.println(co2ppm_read);
  
  Dps422PressureSensor.measurePressureOnce(pressure_read);
    Serial.print("Pressure: ");
    Serial.print(pressure_read);
    Serial.println(" Pascal");
    
  Dps422PressureSensor.measureTempOnce(temperature_read);
    Serial.print("Temperature: ");
    Serial.println(temperature_read);

  humidity_read = dht.readHumidity();
    Serial.print("Humidity: ");    
    Serial.println(humidity_read);

  sound_read = pulseIn(sound_pin, HIGH);
    Serial.print("Noise: ");    
    Serial.println(sound_read);

  radar1_read = digitalRead(radar1_pin);
    Serial.print("Radar1: ");    
    Serial.println(radar1_read);
  radar2_read = digitalRead(radar2_pin);  
    Serial.print("Radar2: ");    
    Serial.println(radar2_read);  
  radar3_read = digitalRead(radar3_pin);
    Serial.print("Radar3: ");    
    Serial.println(radar3_read);  
  radar4_read = digitalRead(radar4_pin);
    Serial.print("Radar4: ");    
    Serial.println(radar4_read);  

  // save to feed on Adafruit IO
  Serial.println("sending -> ");
  CO2->save(co2ppm_read);
  humidity->save(humidity_read);
  pressure->save(pressure_read/100);
  temperature->save(temperature_read-4);
  Noise->save(sound_read);
  presence1->save(radar1_read);
  presence2->save(radar2_read);
  presence3->save(radar3_read);
  presence4->save(radar4_read);

  // Adafruit IO is rate limited for publishing, so a delay is required in
  // between feed->save events.
  delay(18000);

}

config.h

C Header File
this is the cofig file to connect to your wifi and the your Adafruit.io account
/************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME "your_username"
#define IO_KEY "your_key"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
//   - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
//   - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
//   - Feather M0 WiFi -> https://www.adafruit.com/products/3010
//   - Feather WICED -> https://www.adafruit.com/products/3056
//   - Adafruit PyPortal -> https://www.adafruit.com/product/4116
//   - Adafruit Metro M4 Express AirLift Lite ->
//   https://www.adafruit.com/product/4000
//   - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
//   - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
//   - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264

#define WIFI_SSID "your_ssid"
#define WIFI_PASS "your_pass"

// uncomment the following line if you are using airlift
// #define USE_AIRLIFT

// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) ||         \
    defined(ADAFRUIT_PYPORTAL)
// Configure the pins used for the ESP32 connection
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
// Don't change the names of these #define's! they match the variant ones
#define SPIWIFI SPI
#define SPIWIFI_SS 10 // Chip select pin
#define NINA_ACK 9    // a.k.a BUSY or READY pin
#define NINA_RESETN 6 // Reset pin
#define NINA_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
                   NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

Credits

Infineon Team

Infineon Team

72 projects • 113 followers

Comments