I built a Scuba compressor and it is controlled by an Arduino (UNO)
On that UNO I have:
4 buttons - Start and stop (Compressor, Oxygen solenoid, purging timer circuit, Oxygen calibration)
4 Relays - Output for 3 buttons and the last one for an alarm
4 sensors - High Pressure (PSI while filling the scuba tanks)
- Oxygen (O2) (amount of oxygen NITROX)
- Temperature (Temperature of the compressor)
- Light sensor (Detect alarm of an independent Carbon monoxide detector)
- Flow sensor (Detect when air is blowing out during the purging)
I have different conditions (if)
Stop compressor when reach 3,150 PSI
Stop Oxygen and Compressor if higher than 40% Oxygen
etc..
I can see the sensors value on two LCD's
I also installed an Arduino NANO that takes the value of the sensors from the UNO (TX pin)
and this NANO is driving a RF transmitter (HRF24L01) and sends the signal to a small box
with an OLED display so I can monitor my compressor while I'm away (few hundreds feet) is enough.
All this is working well
I'm new with coding and Arduino. I began playing with that 3 months ago and I'm learning
with examples. I find a code near of what I need, I integrated in my existing code and I modify it to fit my needs.
But now I need more and I need help.
The compressor need to be purge of the humidity every 6 minutes. I installed a small circuit timer
that open a close the purge valve every 6 minutes. The valve is open and close by a DC motor that I
modify with a sproket created with my 3D printer.
Every six minute the circuit timer is opening and closing the valve to purge and during a 2 or 3 seconds, a high pressure air is blowing in a small hose. at the end of that hose I install a water flow sensor working with a hall effect. So every six minutes the air blow and the flow sensor reach a value.
I add a small code that say "if flowRate" is higher that 20 open a LED and it's working. that code was only to test the flow sensor and it is ok. But now I need to go further,
DMS
I need to add a "dead man switch" this DMS will monitor the purging that append every 6 minutes.
I want a counter that I can see on my LCD, that count from 0 to 360 and if it reach the value of 360, I want "stateRELAY1" to go LOW (relay that control the compressor). Every time the air blow in my flow sensor, it should reset the counter to 0 and start counting again. Results, that flow sensor will act as a DMS. If the system is not purge between 0 and 360 seconds, I want the compressor to stop.
I also need to:
Monitoring the increase of the PSI
The high pressure sensor is monitoring the PSI. I already put a condition that when PSI reach 3,150 PSI, the compressor stop. But I also want to monitor the increasing PSI and if the PSI in not increasing for X PSI per second or minutes it will mean that I have an air leak and I want the compressor to stop.
Below in clear text, see the part of the code about the FlowSensor and the counter.
See attache files for the full code.
//*********************************************************FlowSensor
//this section is taking care of the FlowSensor
//I put an LED to see if the sensor was working
void FlowSensor(){
pulseCount++;
if((millis() - oldTime) > 1000) // Only process counters once per second
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount);
oldTime = millis();
Serial.print("Flow rate: ");
Serial.println(int(flowRate));
attachInterrupt(sensorInterrupt, FlowSensor, FALLING);
}
if (flowRate > 20){
digitalWrite(LED1, HIGH);
}
else
{
digitalWrite(LED1, LOW);
}
}
//**************************************************LcdCounter for DMS (testing phase)
void LcdCounter(){
// this section is my first few attenps to create the counter for the DMS
// My first problem is that when it start counting, it stop as soon as the flowrate value is below 20.
// It's normal for the flowRate to reach higher than 20 only for a few seconds since the air blow from the
// purge is very short.
if (flowRate > 20)
{
a ++;
lcd_2.setCursor(11, 1);
lcd_2.print(a);
}
// Below I put 30 as a value just to see is it's working.
// But I didn't find a way to reset the counter so when the counter reach 30,
// the two relays stop and "Purge" is printed on the LCD but I don't
// have any way to make it reset unless reseting the Arduino.
// if (a > 30){
// stateRELAY1 = LOW;
// stateRELAY2 = LOW;
// lcd_2.setCursor(11, 1);
// lcd_2.print(F("Purge"));
// }
}
//*********************************************************LOOP
void loop(){
Button();
analysing_O2(0,calibrationv,"O2 ");
Pression();
Temperature();
LightSensor();
FlowSensor();
LcdCounter();
pulseCount = 0; // this line should probably removed one day but for now I need it otherwise
// the counter go crazy. like starting for no reason and doesn't stop counting.
// probably a bug in the FlowRate section