I would like to add to this program that when the green light is on or when a pressure of 6 bars is detected, I can press the push button on pin 12. When I press the push button, the relay on pin 13 should only start working 3 seconds later and remain active for 6 seconds. Can someone help me?
const int pressureInput = A0; //select the analog input pin for the pressure transducer
const int pressureZero = 102.4; //analog reading of pressure transducer at 0psi
const int pressureMax = 921.6; //analog reading of pressure transducer at 200psi
const float pressuretransducermaxBAR = 13.79; //bar value of transducer being used
const int digitalOutput = 13; //select the digital output pin for activating the output
const int redLedPin = 4; //select the digital output pin for activating the red LED
const int greenLedPin = 2; //select the digital output pin for activating the green LED
const int orangeLedPin = 3;
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds
float previousPressureValue = 0; //variable to store the previous value coming from the pressure transducer
float pressureValue = 0; //variable to store the value coming from the pressure transducer
void setup() //setup routine, runs once when system turned on or reset
{
Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second
pinMode(digitalOutput, OUTPUT); //set the digital output pin as an output
pinMode(redLedPin, OUTPUT); //set the red LED pin as an output
pinMode(greenLedPin, OUTPUT); //set the green LED pin as an output
}
void loop() //loop routine runs over and over again forever
{
previousPressureValue = pressureValue; //save the current pressure value to previous pressure value
pressureValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
pressureValue = ((pressureValue-pressureZero)*pressuretransducermaxBAR)/(pressureMax-pressureZero); //conversion equation to convert analog reading to bar
Serial.print(pressureValue, 2); //prints value from previous line to serial with 2 decimal places
Serial.println("bar"); //prints label to serial
if(pressureValue >= 6.0) {
digitalWrite(greenLedPin, HIGH); // zet de groene LED aan
digitalWrite(redLedPin, LOW); // zet de rode LED uit
} else if(pressureValue <= 0.5) {
digitalWrite(greenLedPin, LOW); // zet de groene LED uit
digitalWrite(redLedPin, HIGH); // zet de rode LED aan
} else if(pressureValue != previousPressureValue) {
digitalWrite(orangeLedPin, HIGH); // Orange LED on
delay(100);
digitalWrite(orangeLedPin, LOW);
} else {
digitalWrite(greenLedPin, HIGH); // zet de groene LED aan
digitalWrite(redLedPin, LOW); // zet de rode LED uit
}
delay(sensorreadDelay); //delay in milliseconds between read values