#include <DHT.h>
#include "HX711.h"
#define useCO2 0
#if useCO2
#include "DFRobot_CCS811.h"
/*
* IIC address default 0x5A, the address becomes 0x5B if the ADDR_SEL is soldered.
*/
//DFRobot_CCS811 CCS811(&Wire, /*IIC_ADDRESS=*/0x5A);
DFRobot_CCS811 CCS811;
#endif
HX711 escala;
// Variables to hold sensor data values
float hIn = 0;
float tIn = 0; // or dhtIn.readTemperature(true) for Fahrenheit
float hOut = 0;
float tOut = 0; // or dhtIn.readTemperature(true) for Fahrenheit
int soundValue = 0; // Variable to hold sound sensor value
float peso = 0.0; // variable to hold weight sensor
int co2Value = 0; // read CO2 value
int tvocValue = 0; // Read TVOC value
// Pins Definition
#define DHTPINin 2 // What digital pin we're connected to
#define DHTPINout 3 // What digital pin we're connected to
const int soundSensorPin = A0; // Pin analógico del sensor de sonido
const int DOUT_PIN = 4; // Pin digital conectado a DOUT del módulo HX711
const int SCK_PIN = 5; // Pin digital conectado a SCK del módulo HX711
// Uncomment whatever type you're using!
#define DHTTYPEout DHT22 // DHT 11 for Ioutside temperature
#define DHTTYPEin DHT22 // DHT 22 for inside temperature
DHT dhtIn(DHTPINin, DHTTYPEin);
DHT dhtOut(DHTPINout, DHTTYPEout);
void readSensorData() {
Serial.println("Read Sensor Data");
hIn = dhtIn.readHumidity();
tIn = dhtIn.readTemperature(); // or dhtIn.readTemperature(true) for Fahrenheit
hOut = dhtOut.readHumidity();
tOut = dhtOut.readTemperature(); // or dhtIn.readTemperature(true) for Fahrenheit
if (isnan(hIn) || isnan(tIn)) {
Serial.println("Failed to read from Inside DHT sensor!");
hIn = 0;
tIn = 0;
}
if (isnan(hOut) || isnan(tOut)) {
Serial.println("Failed to read from Outside DHT sensor!");
hOut = 0;
tOut = 0;
}
Serial.print("Inside Temp:");
Serial.print(tIn);
Serial.print(" | Humidity:");
Serial.print(hIn);
Serial.print(" | Outside Temp:");
Serial.print(tOut);
Serial.print(" | Humidity:");
Serial.println(hOut);
// Lectura del sensor de sonido
int soundValue = analogRead(soundSensorPin);
Serial.print("Nivel de sonido: ");
Serial.println(soundValue);
// Lectura de peso
peso = escala.get_units(10); // Lee el peso con 10 lecturas de promedio
Serial.print("Peso: ");
Serial.print(peso);
Serial.println(" kg");
#if useCO2
// Read CO2 sensor data
if (CCS811.checkDataReady() == true) {
co2Value = CCS811.getCO2PPM(); // read CO2 value
tvocValue = CCS811.getTVOCPPB(); // Read TVOC value
Serial.print("CO2: ");
Serial.print(co2Value);
Serial.print("ppm, TVOC: ");
Serial.print(tvocValue);
Serial.println("ppb");
} else {
Serial.println("Data is not ready!");
}
// /*!
// * @brief Set baseline
// * @param get from getBaseline.ino
// */
CCS811.writeBaseLine(0x447B);
#endif
}
void setup() {
Serial.begin(9600);
escala.begin(DOUT_PIN, SCK_PIN);
pinMode(soundSensorPin, INPUT); // Set sound sensor pin as input
dhtIn.begin(); // Initialize DHT in sensor
dhtOut.begin(); // Initialize DHT OUT sensor
}
void loop() {
readSensorData(); // First read sensor data
delay(2000);
}