Compressor Controller

Product: https://www.tindie.com/products/williambailes/plex-controller/

This is the new compressor controller that I had made to replace the old one.
The old controller was a mechanical controller which used a bold to set the max pressure. The old controller was replaced 2 times because of the bolt’s thread got striped both times. This meant the compressor did not shut off when at the correct set pressure.
This new controller is all electronic and using the PLEX controller. On the controller, the pressure can be set and the pump will shut off when it needs to. The pump will then start again when the pressure is 10% less than the set pressure.

Code for Project

GNU General Public License v3.0

#include <LiquidCrystal.h>
#include <EEPROM.h>

#define maxPressure 100
#define sensorMultiplier 0.3
#define sensorOffSet -30
#define outputPin A1
#define sensorPin A5
#define upButtonPin 3
#define downButtonPin 10

double sensorValue;
double pressure;
byte setPressure = 0;
unsigned long timeLastSet = 0;
unsigned long timeLastOn = 0;
bool timeout = false;

LiquidCrystal lcd(2, 4, 5, 6, 7, 8);

void setup() 
{
  lcd.begin(16, 2);
  Serial.begin(9600);
  Load();
  changed();
  pinMode(outputPin,OUTPUT);
  pinMode(sensorPin,INPUT);
  pinMode(upButtonPin,INPUT);
  pinMode(downButtonPin,INPUT);
}

void loop() 
{
  readSensor();
  control();
  Set();
  displayreading();
}

#define samplecount 20
int samples[samplecount];

void readSensor()
{
  int indexI = (millis()/(1000/samplecount))%(samplecount);
  samples[indexI] = analogRead(sensorPin);

  for(int i = 0; i<samplecount;i++)
  {
    sensorValue += samples[i];

  }
  sensorValue = sensorValue/samplecount;
  pressure = sensorMultiplier*sensorValue+sensorOffSet;
}

void control()
{
  if(timeLastOn+120000 < millis())
  {
    timeout=false;
  }
  
  if(pressure < setPressure*0.2)
  {
    timeLastOn = millis();
    digitalWrite(outputPin,HIGH);
    timeout=false;
  }
  else if(pressure > setPressure || timeout)
  {
    digitalWrite(outputPin,LOW);
    timeout=true;
  }
  else if(pressure < setPressure*0.6)
  {
    timeLastOn = millis();
    digitalWrite(outputPin,HIGH);
  }
}

void displayreading()
{
  lcd.setCursor(0,0);
  lcd.print((int)pressure);
  lcd.print(" PSI        ");
  lcd.setCursor(0,1);
  lcd.print("set: ");
  lcd.print(setPressure);
  lcd.print(" PSI        ");
}

void Set()
{
  if(timeLastSet+500>millis())
    return;
  if(digitalRead(downButtonPin) == HIGH)
  {
    setPressure -= maxPressure*0.05;
    changed();
  }
  if(digitalRead(upButtonPin) == HIGH)
  {
    setPressure += maxPressure*0.05;
    changed();
  }
}

void changed()
{
  timeLastSet = millis();
  if(setPressure >= maxPressure)
    setPressure = maxPressure;
  if(setPressure <= 0)
    setPressure = 0;
  Save();
}

int address = 0;

void Save()
{
  EEPROM.write(address, setPressure);
}

void Load()
{
  setPressure = EEPROM.read(address);
}

Latest Projects

Popular Projects