air compressor pressure switch Arduino

Thread Starter

Mullins

Joined Dec 31, 2021
179
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
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);
}
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
The Truth is that I need it for an hydraulic system. It will work between 40and 50 Bar. I say 4-6Bar because I'm able to modify the parameters but unable to write the code. I also have pressure switch for industrial fridge but it can work up to 40Bar I think. Not enough for me.
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
The socket of my sensor is the same as pdf. Now I don't have the number but I'm sure it's like this.



In a Hydraulic-System there must also be Mechanical-Pressure-Relief-Valves.
Yes I have it but I need to use Arduino.

Please if you can tell me what part of the code I need to remove in order to use it without the components I mentioned before.
 

LowQCab

Joined Nov 6, 2012
4,314
I have no idea about writing Code,
but there are plenty of other people hear who know how.
But, I don't think that they will write the whole thing for You for free.

I do just about everything Analog.

Why do You need an Arduino for simply cycling a Pump-Motor ?
.
.
.
 

LesJones

Joined Jan 8, 2017
4,229
How do you plan to set the presure that it switches the pump off if you do not have a potentiometer ?
Do you need to set the hysteresis in the system to avoid rapid on/ off cycling ?

Les.
 
Last edited:

Ya’akov

Joined Jan 27, 2019
9,272
This sort of thing raises red flags for me. There is a great deal of potential danger in hydraulic systems and controls for them must have failsafe mechanisms. Given the pressures a mysterious program written by someone else hacked up without knowing the potential side effects seems quite unwise.

Since forum rules prohibit dangerous projects, could you explain why this is not one despite its appearance?
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
Since forum rules prohibit dangerous projects, could you explain why this is not one despite its appearance?
Great question. I consider myself a rational and objective person. The system is already tested and certified. Originally a ECU monitors the pressure via a 5v sensor. Activates the pump to keep the pressure within a certain range. The system is equipped with an 80bar pressure relief valve. In the event of over-pressure, the oil simply flows back into the tank. The fact is that I have to keep the pressure within a certain range, min40 max50bar. I can keep the pump on all the time and regulate the pressure with an adjustable pressure limiter equipped with a pressure gauge but this means increasing consumption and wear of the pump. The whole system works at 12vdc. It does not work at high voltages and there is no risk of injury. It is not a homemade project. this doesn't mean that all homemade projects are dangerous :)
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
ok, for those who may need this code in the future...
It's working even without by-pass switch and display.
Please be sure you put a mechanical protection for over pressure in case you use on an air compressor.
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
Pressure = map(analogRead(ReadPressure), 101, 921, 0, 100);
Setting = 5 * (map(analogRead(ReadSetting), 0, 1023, 20, 0));


this code is for this sensor LEPAZA60120 5v 100psi vout 0.4-4.5volt
Please can explain me the meaning of each number? I saw many example but are unclear for me.

For this line if my sensor is 7volt ( just for example) and 0 bar is 0.9volt max pressure (200bar) is 6.5volt, I will have:
7/1023=0,0068.....
0 bar = 0.9 volt; 9/0.0068...=131
200 bar = 6.5/0.0068...=950
so,
Pressure = map(analogRead(ReadPressure), 131, 950, 0, 200); is it correct?


What about the second line?
Setting = 5 * (map(analogRead(ReadSetting), 0, 1023, 20, 0));
 
Last edited:

LowQCab

Joined Nov 6, 2012
4,314
The Line of Sensors that You linked to does not include a "50-Bar" Sensor, ( roughly ~735-PSI ).

If You don't know anything about writing Code,
You could easily destroy some expensive Equipment.

If I were You,
I'd pay someone who is qualified to set-up your Pressure Regulating System,
or stick with a simple Analog-Circuit.
.
.
.
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
The Line of Sensors that You linked to does not include a "50-Bar" Sensor, ( roughly ~735-PSI ).
Hi @LowQCab,
Sorry for my English...
Obviously my sensor with be different. But, if I want to learn how to write the code I must first understand the relationship between the cited code and the cited sensor.
 
I want to learn how to write the code
I fully support all the cautionary words already posted and agree with the recommendation that an analog solution is both easier, safer and more reliable - not every problem needs a processor!

But if you want to learn how to write code it's typically a step by step process. Start with Arduino examples and modify the code to see if (a) it still works and (b) whether it does what you intended! Then, think of a safe low voltage electronics only project and write your own code from scratch, building it and testing it step by step - you'll learn so much from mistakes but each time you compile only add a small amount of code so you can go back easily to what worked before.

Then you can move on to understanding and modifying other people's code. I admire what Adafruit has achieved but I personally abhor the reliance on so many libraries which introduce their own instructions, but to be fair to Adafruit, it's almost always obvious to work out what those intructions do. It's bad practice to use code you don't understand and in this case it could be dangerous.

I urge you to go through this code line by line to work out exactly what it is doing. Personally, I've never used the map() instruction before so I searched "Arduino map instruction" and read about it on the Arduino Reference page. If you understand the code and the hardware details you should not need this forum to make the changes you desire.
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
Thanks everyone for the great advice. Don't get me wrong but I can't learn to write (literally code) at this age. I just want to be able to make small changes to already existing codes or at most put together parts of different codes. I support my family with a job that is far away from codes, arduino etc. So please whoever is able and willing to help me change these two lines.


Pressure = map(analogRead(ReadPressure), 101, 921, 0, 100);
Setting = 5 * (map(analogRead(ReadSetting), 0, 1023, 20, 0));


this code is for this sensor LEPAZA60120 5v 100psi vout 0.4-4.5volt
Please can explain me the meaning of each number? I saw many example but are unclear for me.

For this line if my sensor is 7volt ( just for example) and 0 bar is 0.9volt max pressure (200bar) is 6.5volt, I will have:
7/1023=0,0068.....
0 bar = 0.9 volt; 9/0.0068...=131
200 bar = 6.5/0.0068...=950
so,
Pressure = map(analogRead(ReadPressure), 131, 950, 0, 200); is it correct?


What about the second line?
Setting = 5 * (map(analogRead(ReadSetting), 0, 1023, 20, 0));
 

Thread Starter

Mullins

Joined Dec 31, 2021
179
In case I don't get help with the code this could be an analog solution. Two pistons with different diameters push each other. The smaller one receives oil from the pump while the larger one serves to reduce the pressure. I have to spend several hours at the lathe but I see no other solution.
 

Attachments

Top