Ideas for using those 5 sensors?

Hello,

Right now, my ideas would be to use 5 sensors: MQ5, Sound sensor, Dust Sensor, DHT11, Photocell.

Next step would be to get a better rendering of the air quality by adding sensor and add a barometric sensor

I was wondering if you got ideas on how can I make this code cleaner and may get the most of it by adding new functions.

Here is the code

#include <DHT.h>

//Dust Sensor Configuration
int measurePin = A6;
int ledPower = 12;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

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

//MQ5 Sensor
int sensor=A4;
int gas_value;

//Microphone Sensor
int soundDetectedPin = A2; // Use Pin 3 as our Input
int soundDetectedVal = HIGH; // This is where we record our Sound Measurement
boolean bAlarm = false;
unsigned long lastSoundDetectTime; // Record the time that we measured a sound
int soundAlarmTime = 500; // Number of milli seconds to keep the sound alarm high


//DHT Sensor
#define DHTPIN A3
#define DHTTYPE DHT11 


DHT dht(DHTPIN, DHTTYPE);
 
void setup() 
{
Serial.begin(115200);
Serial.println("DHT11 TEST PROGRAM ");
delay(1000);
dht.begin();
pinMode(ledPower,OUTPUT);
pinMode(sensor,INPUT); 
pinMode (soundDetectedPin, INPUT) ; // input from the Sound Detection Module
 
}
void loop() {
Serial.println("\n");
  //Dust Sensor
  
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
 
  voMeasured = analogRead(measurePin); // read the dust value
 
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
 
  // 0 - 3.3V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (3.3 / 1024);
 
  dustDensity = 0.17 * calcVoltage - 0.1;
 
  Serial.print("Raw Signal Value (0-1023): ");
  Serial.print(voMeasured);
 
  Serial.print(" - Voltage: ");
  Serial.print(calcVoltage);
 
  Serial.print(" - Dust Density: ");
  Serial.println(dustDensity);
 
  delay(1000);
  //SoundSensor
  soundDetectedVal = analogRead (soundDetectedPin) ; // read the sound alarm time   
  //Photocell
  photocellReading = analogRead(photocellPin);  
  delay(1000);
  //MQ5 Sensor
  gas_value=analogRead(sensor);
  //DHT11
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) 
  {
  Serial.println("Failed to read from DHT sensor!");
  return;
  } 
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" degrees Celsius Humidity: ");
  Serial.print(h);
  Serial.print("Gas Sensor Value:");
  Serial.println(gas_value);
  Serial.print("Photocell Reading = ");
  Serial.println(photocellReading);     // the raw analog reading
  Serial.print("Sound Reading = ");
  Serial.println(soundDetectedVal);     // the raw analog reading
}
//Microphone Sensor
int soundDetectedPin = A2; // Use Pin 3 as our Input

If you are going to have useless comments, you MUST make then accurate, useless comments.

void setup()
{
Serial.begin(115200);
Serial.println("DHT11 TEST PROGRAM ");
delay(1000);
dht.begin();
pinMode(ledPower,OUTPUT);
pinMode(sensor,INPUT);
pinMode (soundDetectedPin, INPUT) ; // input from the Sound Detection Module
 
}

Some
indenting
would
certainly
help.

Put the blank line BETWEEN the functions, not at the end of the function.

Serial.println("\n");

Stupid stuff should be commented.

  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
 
  voMeasured = analogRead(measurePin); // read the dust value
 
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);

Comments should explain WHY the code is the way it is, not what the code is doing. Anyone can see that you are turning a pin on and off. What is NOT clear is why you are turning an LED on and off. I suspect that there is not really an LED connected to that pin. If that is the case, the name of the variable sucks.

I really don't see what role the sound sensor plays, with the gas sensor, etc. What, exactly, are you trying to accomplish?

  if (isnan(h) || isnan(t))
  {
  Serial.println("Failed to read from DHT sensor!");
  return;
  }

If the temperature sensor fails, why does that mean that you don't care about the sound level, etc.?

Thanks, I am gonna correct this. The sound sensor was supposed to be added to a PIR in order to detect sound people in the room. This could be during the day or the night.