#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
int relay=2;
float pressureinPSI;
float lastSysPressure=0;
long pressure;
long avgSysPressure,sysPressure;
long pressureSum;
long baseLinePressure;
bool motorOn=false;
byte i;
float delta;
float prevdelta;
void setup() {
int setpress=0;
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while(1) {}
}
pinMode(relay, OUTPUT);
digitalWrite(relay,HIGH);
baseLinePressure=bmp.readPressure();
prevdelta=100000;
}
void loop() {
pressureSum=0;
for(i=0;i<5;i++)
{
pressure=bmp.readPressure();
pressureSum=pressureSum+pressure;
}
avgSysPressure=pressureSum/5;
sysPressure=avgSysPressure-baseLinePressure;
delta=sysPressure-lastSysPressure;
Serial.println(delta);
if(delta<-100 && !motorOn)
{
Serial.println("ON");
digitalWrite(relay,LOW);
delay(5000);
digitalWrite(relay,HIGH);
motorOn=true;
}
if(motorOn && delta<-500)
{
Serial.println("ON Second Time");
digitalWrite(relay,LOW);
delay(5000);
digitalWrite(relay,HIGH);
}
if(sysPressure>0 && sysPressure<100)
{
motorOn=false;
}
lastSysPressure=sysPressure;
prevdelta=delta;
}
Created August 28, 2023
Comments