Hi Guys and Gals,
new to the forum so hello everyone whom reads it,
I have been been having issues with getting relays to trigger from a sensor value on I2C,
I have been looking all over the net for a few days now but no progress,
i have a simple monitor system that works fine and spools the data to serial monitor,
but i can not trigger the other relays from a "set point" value,
i know i have messed the script up but i cant see where.
consists of
Uno,
CCS811 CO2 sensor,
BME280 temp humdity sensor
4 channel "Arduino type" relay
#include <SparkFunBME280.h>
#include <SparkFunCCS811.h>
//Resources:
//Uses Wire.h for i2c operation
//The BME280 and the CCS811 are both on the I2C bus, in parallel
//use the hardware pins for clock (SCl) and data (SDA)
// Hardware Connections (Breakoutboard to Arduino)
//3.3V to 3.3V pin
//GND to GND pin
//SDA to A4
//SCL to A5
#define BME280_ADDR 0x76 //Default I2C Address
#define CCS811_ADDR 0x5A //Alternate I2C Address
// Define relay Pin and names
#define Fan 2
#define Trickle 4
#define Purge 7
#define Humidity 8
//Global objects for sensors
CCS811 myCCS811(CCS811_ADDR);
BME280 myBME280;
int time=0;
void setup()
{
Serial.begin(9600);
pinMode (Fan, OUTPUT);
pinMode (Trickle, OUTPUT);
pinMode (Purge, OUTPUT);
pinMode (Humidity, OUTPUT);
Serial.println("Please Allow 20 Mins For The CO2 & TVOC Sensor To Self Calibrate.");
Serial.println();
//This begins the CCS811 sensor and prints error status of .begin()
myCCS811.begin();
//For I2C, enable the following and disable the SPI section
myBME280.settings.commInterface = I2C_MODE;
myBME280.settings.I2CAddress = 0x76;
//Initialize BME280
//For I2C, enable the following and disable the SPI section
myBME280.settings.commInterface = I2C_MODE;
myBME280.settings.I2CAddress = 0x76;
myBME280.settings.runMode = 3; //Normal mode
myBME280.settings.tStandby = 0;
myBME280.settings.filter = 4;
myBME280.settings.tempOverSample = 5;
myBME280.settings.pressOverSample = 5;
myBME280.settings.humidOverSample = 5;
delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
//Calling .begin() causes the settings to be loaded
myBME280.begin();
}
//---------------------------------------------------------------
void loop()
{
digitalWrite(Fan, LOW); // NC terminals
digitalWrite(Trickle, HIGH);
digitalWrite(Purge, HIGH);
digitalWrite(Humidity, HIGH); // Humidifier
//Check to see if data is available
if (myCCS811.dataAvailable())
{
//Calling this function updates the global tVOC and eCO2 variables
myCCS811.readAlgorithmResults();
//printInfoSerial fetches the values of tVOC and eCO2
//printInfoSerial();
if(time%20==0) Serial.println(" ");
const int x=8;
int y=12;
const int delty=21;
float BMEtempC = myBME280.readTempC();
float BMEhumid = myBME280.readFloatHumidity();
//This sends the temperature data to the CCS811
myCCS811.setEnvironmentalData(BMEhumid, BMEtempC);
}
else if (myCCS811.checkForStatusError())
{
delay(2000); //Wait for next reading
time+=2;
}
//getCO2() gets the previously read data from the library
Serial.println("Reading Sensors");
delay (1500);
Serial.print(" CO2: ");
Serial.print(myCCS811.getCO2());
Serial.println(" ppm");
delay(1500);
//getTVOC() gets the previously read data from the library
Serial.print(" TVOC: ");
Serial.print(myCCS811.getTVOC());
Serial.println(" ppb");
delay(1500);
Serial.print(" Temp: ");
Serial.print(myBME280.readTempC(), 2);
Serial.println(" C");
delay(1500);
Serial.print(" Humidity: ");
Serial.print(myBME280.readFloatHumidity(), 2);
Serial.println(" %");
delay(1500);
Serial.println();
//// this is where I'm stuck ////
if (myBME280.readTempC() > 18)
{
digitalWrite(Trickle, LOW);
}
if (myCCS811.getCO2() < 1200);
digitalWrite(Purge, LOW);
}