Hi
I will reconstruct the Sensor part on a isolated & vibration free platform. (pics was from testing platform).
linear relationship you explained above is exactly I want to include in my code. I know I have to take regular
readings and go through calibration routine. I only need the code which relates linear movement into psi . can you please go through my project code and include this part in it, and include if analog set point > actual value ,activate switching of relay ,which will stop at analog setpoint= actual value. with Proportional Switching delay (Which is in my subject referred as PID).
My Project Code see below;
//sensor input(interepts pin 2,3). (no idea how to include this)
//value reads from the optical sensor with A-ch,B-ch and matches within the range of analog range from potentiometer will shut the relay off.
//pushButton assigned will turn on the relay swithing for set value by potentiometer.
// push to fill preset turn on relay second press turn off the relay
//Manual mode keep the relay on.....
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
int sensorPin= A0; // Potentiometer attached as human interface for selection of various states.this case air pressure.and swithing modes.
int buzzerPin= 4; // attached for long
int relayLed= 5; // GOES HIGH WHEN RELAY GOES HIGH.
int pushButton= 6; // Select Button,(TO INITIATE THE RELAY SWITCHING) AS PER SELECTION (VALUE OR MODE)
int servoPin=7; // assigned for later developments if required servo motor will be attached to a valve to release air. not considered now.
int relayPin1= 8; // 1st Relay 4 RELAY MODULE I WILL USE ONLY relayPin1 in this project.although all pins are initiated.
int relayPin2= 9; // 2nd Relay
int relayPin3= 10; //3rd Relay
int relayPin4= 11; //4th Relay
int ledPin1= 12; // HIGH WHEN SYSTEM IS READY (blinks when given loop in process after push button).
int ledPin2= 13; // POWER ON INDICATOR ON OUTSIDE PANNEL
void setup() {
pinMode(buzzerPin, OUTPUT);//declare buzzer ( beep per switching and long beep after pressure arrives at set point)
pinMode(relayLed, OUTPUT);//declare the ledPin as an output
pinMode(pushButton, OUTPUT); //declare the pushbutton attached
pinMode(servoPin, OUTPUT); // SERVO MOTOR WILL BE ATTACHED AT LATER STAGE. NOT NOW.
pinMode(relayPin1, OUTPUT);//ONLY ONE RELAY IS USED.PIN 8
pinMode(relayPin2, OUTPUT);//ONLY ONE RELAY IS USED.PIN 9
pinMode(relayPin3, OUTPUT);//ONLY ONE RELAY IS USED.PIN 10
pinMode(relayPin4, OUTPUT);//ONLY ONE RELAY IS USED.PIN 11
pinMode(ledPin1, OUTPUT);// declare the ledPin as an output
pinMode(ledPin2, OUTPUT);// declare the ledPin as an output
lcd.begin(16, 2);
lcd.setCursor(0, 0); //set cursor to top left corner
lcd.print("Booting....:"); //print the text to the lcd
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE); // Switch on the backlight
lcd.setBacklight(HIGH);
for (int i = 0; i <= 100; i++) { // you can change the increment value here
lcd.setCursor(12, 0);
if (i < 100) lcd.print(" "); //print a space if the percentage is < 100
if (i < 10) lcd.print(" "); //print a space if the percentage is < 10
lcd.print(i);
lcd.print("%");
delay(100); //change the delay to change how fast the boot up screen changes
}
lcd.setCursor(0, 0);// USES FIRST LINE TO PRINT WELCOME MESSAGE
// Print a message to the LCD.
lcd.print("WELCOME USER:");
lcd.setCursor(0, 1);//Second Line of the welcome message (0,1)
lcd.print("PASSWORD: *****");
delay(2000);
lcd.clear();
}
void loop() {
lcd.home(); //go home
lcd.print("Set Air Pressure:");
int sensorVal = analogRead (A0);
// DispltCursor (0, 1);
lcd.setCursor(0, 1);
// Read sensor value
float Pressure = sensorVal;
if (sensorVal <= 120) // List of Preset values and analog reference for the project <=120 analog Range
lcd.print("PUSH TO FILL."); //puSH BUTTON WILL MAKE RELAY PIN HIGH next press low
else if (sensorVal > 121 and sensorVal <= 160) // 121-160 analog Range
lcd.print("PSI 030 AUTO");
else if (sensorVal > 161 and sensorVal <= 200) // 161-200 analog Range
lcd.print("PSI 032 AUTO");
else if (sensorVal > 201 and sensorVal <= 240) // 201-240 analog Range
lcd.print("PSI 035 AUTO");
else if (sensorVal > 241 and sensorVal <= 280) // 241-280 analog Range
lcd.print("PSI 040 AUTO");
else if (sensorVal > 281 and sensorVal <= 320) // 281-320 analog Range
lcd.print("PSI 045 AUTO");
else if (sensorVal > 321 and sensorVal <= 360) // 321-360 analog Range
lcd.print("PSI 050 AUTO");
else if (sensorVal > 361 and sensorVal <= 400) // 361-400 analog Range
lcd.print("PSI 055 AUTO");
else if (sensorVal > 401 and sensorVal <= 440) // 401-440 analog Range
lcd.print("PSI 060 AUTO");
else if (sensorVal > 441 and sensorVal <= 480) // 441-480 analog Range
lcd.print("PSI 065 AUTO");
else if (sensorVal > 481 and sensorVal <= 520) // 481-520 analog Range
lcd.print("PSI 070 AUTO");
else if (sensorVal > 521 and sensorVal <= 560) // 521-560 analog Range
lcd.print("PSI 075 AUTO");
else if (sensorVal > 561 and sensorVal <= 600) // 561-600 analog Range
lcd.print("PSI 080 AUTO");
else if (sensorVal > 601 and sensorVal <= 640) // 601-640 analog Range
lcd.print("PSI 085 AUTO");
else if (sensorVal > 641 and sensorVal <= 680) // 641-680 analog Range
lcd.print("PSI 090 AUTO");
else if (sensorVal > 681 and sensorVal <= 720) // 681-720 analog Range
lcd.print("PSI 095 AUTO");
else if (sensorVal > 721 and sensorVal <= 760) // 721-760 analog Range
lcd.print("PSI 100 AUTO");
else if (sensorVal > 761 and sensorVal <= 800) // 761-800 analog Range
lcd.print("PSI 105 AUTO");
else if (sensorVal > 801 and sensorVal <= 840) // 801-840 analog Range
lcd.print("PSI 110 AUTO");
else if (sensorVal > 841 and sensorVal <= 880) // 841-880 analog Range
lcd.print("PSI 115 AUTO");
else if (sensorVal > 881 and sensorVal <= 920) // 881-920 analog Range
lcd.print("PSI 120 AUTO");
else if (sensorVal > 921 and sensorVal <= 960) // 921-960 analog Range
lcd.print("PSI 125 AUTO");
else if (sensorVal > 961 and sensorVal <= 1000) // 961-1000 analog Range
lcd.print("PSI 130 AUTO");
else if (sensorVal > 1001 ) // > 1001 ,No sensor reference ( relay pin goes HIGH for ever)
lcd.print("MANUAL--MODE");
}
Your question:
Have you given any thought to how you will deal with the situation if the Arduino crashes and fails to turn off the air?
Answer:
attaching a safety valve can avoid any accident. although such possibilities are minor as operator will always be present when filling air incase abnormality recognized by him he can manually shutoff the system . and buzzer is also high when relay is high so that would be helpful to recognize this.
if not Safety Valve calibrated at max PSI on the basis of regular use will automatically open and prevent any accident.
Please try to reply with code
Thanks.