I am working on my master thesis, which is about battery degassing using vacuum. I have completed my initial setup of the machine but would like to add a safety feature using the pressure sensor data. I am using a IFM PN7004 pressure sensor which is a industrial purpose sensor. I am currently trying to use the sensors output to operate two solenoid valves.
One of the solenoid valves is for the 3-way valve to connect to the high vacuum pump and an auxiliary vacuum pump.
The other solenoid valve is to operate a double acting pneumatic cylinder which is used to pierce the battery.
If the pressure is low after piercing the my OPTA should be able to open the high vacuum side of the pump and which the pressure is back to normal, high vacuum closes and at the same time the solenoid valve to release the double acting cylinder should activate.
I am currently using the below code for my arduino.
const int pressureSensorPin = 2; // Digital pin for pressure sensor switching output
const int relay1Pin = 3; // Digital pin for relay 1 (valve 1)
const int relay2Pin = 4; // Digital pin for relay 2 (valve 2)
bool isHighPressure = false; // Flag to track high pressure state
void setup() {
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
digitalWrite(relay1Pin, LOW); // Initial state: relays off
digitalWrite(relay2Pin, LOW);
pinMode(pressureSensorPin, INPUT); // Set pressure sensor pin as input
Serial.begin(38400); // Set serial communication at 38400 baud rate
Serial.println("Pressure Control System Initialized");
}
void loop() {
int pressureState = digitalRead(pressureSensorPin);
Serial.print("Pressure State: ");
Serial.println(pressureState);
if (pressureState == HIGH) {
if (!isHighPressure) {
// Transition to high pressure state
digitalWrite(relay1Pin, HIGH); // Activate relay 1 (valve 1)
digitalWrite(relay2Pin, LOW); // Deactivate relay 2 (valve 2)
isHighPressure = true;
}
} else {
if (isHighPressure) {
// Transition to low pressure state
digitalWrite(relay1Pin, LOW); // Deactivate relay 1 (valve 1)
digitalWrite(relay2Pin, HIGH); // Activate relay 2 (valve 2)
isHighPressure = false;
}
}
delay(1000); // Adjust delay as needed
}
The serial monitor reads "pressue state : 0" all the time but whereas my pressure sensor is showing a digital value on the sensor.
I would like to know if i am making a mistake with my code. Use code tags to format code for the forum