I’m a student at Clemson University and I am currently working on my senior capstone project which is to put together and program four temperature and relative humidity sensors in order to calculate moisture content in grain. These sensors are going to be applied to a miniature grain dryer. Right now I’m running a Metro 328 with a TCA9548A multiplexer and two BME280 temperature & relative humidity sensors. At the moment I’ve got both sensors displaying temp & humidity, which is great but it’s only halfway complete. Now I need to figure out how to incorporate an equation to calculate the moisture contents based off of each individual sensor’s readings. This is my first experience with writing code/programming, and so far everything that I’ve tried has resulted in multiple errors. So I figured it’s time to seek help and go to the forums.
The equation that I need to include looks like this:
MCdb = [(ln(1-RH))/(-K(T+C))]^(1/N)
Where:
MCdb = Moisture Content, dry basis
K, N, and C = coefficients defined for various grain types,
RH = relative humidity (decimal), and
T = temperature (degrees C)
I know that each coefficient has to be defined, but after that I’m lost. Could anyone point me in the right direction? I will attach a picture of my application for the sensors and paste the program I’ve got so far.
#include <Wire.h>
extern “C” {
#include “utility/twi.h” // from Wire library, so we can do bus scanning
}
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define TCAADDR 0x70
//MC Coefficients:
#define K (1)
#define C (1)
#define N (1)
Adafruit_BME280 bme1; // I2C
Adafruit_BME280 bme2; // I2C
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
while (!Serial);
delay(1000);
Wire.begin();
Serial.begin(9600);
Serial.println("\nTCAScanner ready!");
for (uint8_t t=0; t<8; t++) {
tcaselect(t);
Serial.print(“TCA Port #”); Serial.println(t);
for (uint8_t addr = 0; addr<=127; addr++) {
if (addr == TCAADDR) continue;
uint8_t data;
if (! twi_writeTo(addr, &data, 0, 1, 1)) {
Serial.print(“Found I2C 0x”); Serial.println(addr,HEX);
}
}
}
Serial.println("\ndone");
Serial.println(“BME280 Test”); Serial.println("");
tcaselect(0);
if(!bme1.begin())
{
Serial.println(“Ooops, no BMP280 detected … Check your wiring!”);
while(1);
}
tcaselect(1);
if(!bme2.begin())
{
Serial.println(“Ooops, no BMP280 detected … Check your wiring!”);
while(1);
}
}
void loop(void)
{
sensors_event_t event;
tcaselect(0);
Serial.print("Sensor 1 Temperature = ");
Serial.print(bme1.readTemperature()*9/5+32);
Serial.println(“F”);
/*
Serial.print(“Sensor 1 Pressure = “);
Serial.print(bme1.readPressure());
Serial.println(” Pa”);
*/
Serial.print(“Sensor 1 Humidity = “);
Serial.print(bme1.readHumidity());
Serial.println(”%”);
Serial.print("Sensor 1 MC = ");
Serial.print(
Serial.println(“Db”);
tcaselect(1);
Serial.print("Sensor 2 Temperature = ");
Serial.print(bme2.readTemperature()*9/5+32);
Serial.println(“F”);
/*
Serial.print(“Sensor 2 Pressure = “);
Serial.print(bme2.readPressure());
Serial.println(” Pa”);
*/
Serial.print(“Sensor 2 Humidity = “);
Serial.print(bme2.readHumidity());
Serial.println(”%”);
delay(10000);
}