Hi. I found on internet this video. It show an controller made with Arduino for an air compressor.
I need to make this project but without display potentiometer and by-pass switch.
Here the block diagram. Please someone can tell me how to reduce the code? I only need to switch off when presure reach 6 Bar and switch on when the pressure is under 4 Bar. My sensor is the same like the one on the video.
Here the code from Benjamin Marshall
I need to make this project but without display potentiometer and by-pass switch.
Here the block diagram. Please someone can tell me how to reduce the code? I only need to switch off when presure reach 6 Bar and switch on when the pressure is under 4 Bar. My sensor is the same like the one on the video.
Here the code from Benjamin Marshall
Code:
#include <Adafruit_GFX.h>
#include <Adafruit_GrayOLED.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <Adafruit_SSD1306.h>
#include <splash.h>
#include <avr/wdt.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//Pins
#define ReadPressure A1
#define ReadSetting A2
#define Relay 2
#define BypassSwitch 3
#define WDT_Active A7
//Constants
#define MaxPressure 100
//Variables
int Pumping;
int Pressure;
int Setting;
float Threshold;
int BypassActive;
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 allocation failed");
for(;;);}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
pinMode(ReadPressure, INPUT);
pinMode(ReadSetting, INPUT);
pinMode(BypassSwitch, INPUT);
pinMode(Relay, OUTPUT);
pinMode(WDT_Active, INPUT);
display.println("RESET");
display.display();
delay(1000);
if(analogRead(WDT_Active) == 1023){
wdt_enable(WDTO_1S);
}
}
void loop() {
wdt_reset();
display.clearDisplay();
display.setCursor(0, 0);
Pressure = map(analogRead(ReadPressure), 101, 921, 0, 100);
Setting = 5 * (map(analogRead(ReadSetting), 0, 1023, 20, 0));
Threshold = Setting - 10;
BypassActive = digitalRead(BypassSwitch);
if(Pressure > MaxPressure){
BypassActive = 2;}
display.print("Pressure: ");
display.print(Pressure);
display.println(" PSI");
switch(BypassActive){
case 0:
if(Pressure < Threshold){
digitalWrite(Relay, HIGH);
Pumping = 1;}
if((Pressure > Setting)||(Setting == 0)){
digitalWrite(Relay, LOW);
Pumping = 0;}
display.print("Setting: ");
display.print(Setting);
display.println(" PSI");
display.print("Compressor: ");
if(Pumping == 1){
display.print("ON");}
else{
display.print("OFF");}
break;
case 1:
digitalWrite(Relay, HIGH);
display.print("BYPASS MODE ACTIVE");
break;
case 2:
digitalWrite(Relay, LOW);
Pumping = 0;
display.println("SAFETY OVERRIDE");
display.print("MAX PRESSURE EXCEEDED");
break;
}
display.display();
delay(100);
}