I’ve hacked-around your earlier code to add-in the necessary serial print statements.
In the process I’ve seen some things that are problematic and tried to fix them. I can’t do a test compilation, as I don’t have the necessary libraries installed, so there may be the odd compilation issue that needs to be fixed…
// Insert the missing parts of your sketch here...
int humidity;
int temp;
int co2;
int TVOC;
int airflowduration;
int airflowdelay;
int humiditycontrol; // Now declared globally
int temperaturecontrol; // Now declared globally
BLYNK_WRITE(V4)
{
//Controls Humidity on Pin14
humiditycontrol = param.asInt();
Serial.print("BLYNK_WRITE(V4)triggered - incoming value = ");
Serial.println(humiditycontrol);
Serial.print("->BLYNK_WRITE(V4)");
Serial.println(" ");
Serial.println("Blynk custom settings:");
Serial.println(" ");
Serial.print(" RH: ");
Serial.print(humiditycontrol);
Serial.print("%");
// This code moved to sensorDataRecive()
// if (humiditycontrol > humidity)
// {
// digitalWrite(14, HIGH);
// }
// else
// digitalWrite(14, LOW);
}
BLYNK_WRITE(V5)
{
//Controls Temperature on PinX !To enanble this funtion, assign new pin and remove //
temperaturecontrol = param.asInt();
Serial.print("BLYNK_WRITE(V5)triggered - incoming value = ");
Serial.println(temperaturecontrol);
Serial.print("->BLYNK_WRITE(V5)");
Serial.print(" Temp: ");
Serial.print(temperaturecontrol);
Serial.println("°C");
// Don't do this here, do it in sensorDataRecive()...
//if (temperaturecontrol > temp)
//{
// digitalWrite(15, HIGH);
//}
//else
//digitalWrite(15, LOW);
}
BLYNK_WRITE(V6)
{
//Sets value for airflowduration from the cloud and prints it in serial monitor
airflowduration = param.asInt();
Serial.print("BLYNK_WRITE(V6)triggered - incoming value = ");
Serial.println(airflowduration);
airflowduration = airflowduration * 1000;
Serial.print("airflowduration in ms = ");
Serial.println(airflowduration);
}
BLYNK_WRITE(V7)
{
//Sets value for airflowdelay from the cloud and prints it in serial monitor
airflowdelay = param.asInt();
Serial.print("BLYNK_WRITE(V7)triggered - incoming value = ");
Serial.println(airflowdelay);
airflowdelay = airflowdelay * 1000;
Serial.print("airflowdelay in ms = ");
Serial.println(airflowdelay);
}
BLYNK_WRITE(V100)
{
//Controls TestLED on Pin12
int pinValue = param.asInt();
digitalWrite(12, pinValue);
Serial.print("BLYNK_WRITE(V100)triggered - incoming value = ");
Serial.println(pinValue);
}
void Airflow() //swiches Fans on and off for a certain time
{
digitalWrite(27, HIGH); //swiches fan1 on
digitalWrite(12, HIGH); //swiches fan2 on
Serial.println();
airflowduration = * 1000
Serial.print("In void Airflow - airflowduration in ms = ");
Serial.print(airflowduration);
Serial.println("Timer starting");
timer.setTimeout(airflowduration, []()
{
// When the timer completes, any code here will be executed
digitalWrite(27, LOW); //swiches fan1 off
digitalWrite(12, LOW); //swiches fan2 off
Serial.print("Timer complete - AIRFLOW OFF FOR ");
Serial.print(airflowdelay);
Serial.println(" ms");
Serial.println();
});
}
void setup()
{
Serial.begin(115200);
//ccs811 start
Serial.println("CCS811 test");
if (!ccs.begin())
{
Serial.println("Failed to start sensor! Please check your wiring.");
while (1);
}
// Wait for the sensor to be ready
while (!ccs.available());
hdc1080.begin(0x40);
//ccs811 end
pinMode(12, OUTPUT); //Pin 12 is an Output pin
pinMode(14, OUTPUT); //Pin 14 is an Output pin
pinMode(27, OUTPUT); //Pin 27 is an Output pin
BlynkEdgent.begin(); //runs Blynk Connection Liberary
//timer.setInterval(10 * 1000L, CCS811); //runs void CCS811 every X*1000ms // seems to be a duplicate of what's happening in sensorDataRecive
//delay(200);
timer.setInterval(10 * 1000L, sensorDataRecive); //runs void sensorDataRecive every X*1000ms
// delay(200);
// timer.setInterval(10 * 1000L, sensorDataSend); //runs void sensorDataSend every X*1000ms // Not needed now
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V4); //HumidityControl
Blynk.syncVirtual(V5); //AirflowDuration
Blynk.syncVirtual(V6); //AirflowDuration
Blynk.syncVirtual(V7); //AirflowDelay
Serial.print("Setting timer to ");
Serial.print(airflowdelay + airflowduration);
Serial.println(" ms");
// note that this timer duration won't change until the device re-starts.
// probably need to delete the timer and re-create if different functionality is needed...
timer.setInterval((airflowdelay + airflowduration), Airflow);
}
void sensorDataSend()
{
// this code moved into sensorDataRecive
}
void CCS811() // Timer that trtiggers this is disabled
{
Serial.println("Sensor CJMCU 8118 meassurements:");
Serial.println(" ");
Serial.print(" RH=");
Serial.print(hdc1080.readHumidity());
Serial.print("% Temp=");
Serial.print(hdc1080.readTemperature());
Serial.println("°C");
if (ccs.available()) {
if (!ccs.readData())
{
Serial.print(" CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm TVOC: ");
Serial.println(ccs.getTVOC());
}
else
{
Serial.println("ERROR!");
while (1);
}
}
}
void sensorDataRecive()
{
// You can't do this, leave these commented-out...
//Blynk.syncVirtual(V4); //HumidityControl
//Blynk.syncVirtual(V5); //TemperatureControl
//Blynk.syncVirtual(V6); //AirflowDuration
//Blynk.syncVirtual(V7); //AirflowDelay
//Blynk.syncVirtual(V8); //CO2 Control
humidity = hdc1080.readHumidity() + 3;
temp = hdc1080.readTemperature() - 3.6;
co2 = ccs.geteCO2();
TVOC = ccs.getTVOC();
Blynk.virtualWrite(V0, humidity);
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V2, co2);
Blynk.virtualWrite(V3, TVOC);
if (humiditycontrol > humidity)
{
digitalWrite(14, HIGH);
}
else
{
digitalWrite(14, LOW);
}
}
void loop()
{
BlynkEdgent.run();
timer.run();
}
There is an issue with the logic around the timer intervals, as once the setInterval timer is initialised it won’t be updated when your airflowduration and airflowdelay values are changed in the app, the device will need to be rebooted to re-initialise the timer with the new values.
Once the code structure and functionality is resolved then we can look at a solution for that.
When this compiles and is uploaded, if it doesn’t work as expected then post the full serial output from boot-up, with timestamp turned on.
Once again, please do not paste snippets of code and snippets of serial output, they mean nothing. If you amend the code then post the full code and the full serial output.
Pete.

