Mechanical Engineering Senior Design Project HELP

Im doing a senior design project for my engineering program with a team of four people. Basically we are creating an automated compression cuff for medical purposes. We are using an arduino uno to control a solenoid, a LCD display, a momentary foot switch, and read a pressure sensor. Im having trouble with the loop part of the code with the foot switch. In this code we are using an LEDpin to mimic our solenoid. The solenoid will only open (because it is normally closed) when the foot switch is depressed. In this mock up, the opening of the solenoid is the LEDpin lighting up. Now the pin cannot light up if the pressure is too high. For our purposes the solenoid will only operate within a specified range. So, I want the solenoid to OPEN (LEDpin lighted up) for 5 seconds only when the foot swtich is depressed. BUT i want the foot switch to only open the solenoid for 5 seconds, NO MATTER how long the foot switch is depressed. Once the 5 seconds elapse, and the foot switch is released or not released there should be a delay before it is depressed again to do another 5 seconds. How do i implement this?

Here is my code:

ignore the commented out portion of coding

TESTcodeED2.ino (1.53 KB)

You'll get more people to look at your code, if you use the code tags </>.

here is his code so you don't have to download it.

#include <LiquidCrystal.h>

int pressurePin = A1;  //initialize pressure sensor
int readValue;  //initialize read value for sensor
int pressureValue;  //initialize actual value for sensor
int FOOTPin = A0;  //initalize momentary switch
int LED2Pin = 6;  //initialize solenoid
int FOOTstate = 0;  //momentary switch state
// Estop = A2;  //emergency stop button
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
unsigned int interval = 5000;


void setup() {
  Serial.begin(9600);
  pinMode(pressurePin, INPUT);  //pressure sensor
  pinMode(FOOTPin, INPUT);
  pinMode(LED2Pin, OUTPUT);  //solenoid
  digitalWrite(FOOTPin, HIGH);  //momentary switch
  //pinMode(Estop, INPUT);  //emergency stop button
 }
 
void loop() {
  readValue = analogRead(pressurePin);
  pressureValue = readValue*.1450377;  
  Serial.print("value in psi - ");
  Serial.println(pressureValue);
  FOOTstate = digitalRead(FOOTPin);
  
  //if (Estop == LOW)
  //{  
  //}
  
  //else (Estop == HIGH)
  //{
  //digitalWrite(LED2Pin, LOW);  
  //lcd.begin(16, 2);
  //lcd.print("Emergency Stopped");
  //}
  
  if (FOOTstate == HIGH)
  {
    digitalWrite(LED2Pin, LOW);
    lcd.begin(16, 2);
    lcd.print("System Ready");
    delay (150);
	
	//squeeze delay
	//control actuators to squeeze cuff
	
	//unsqueeze delay
	//control actuators to unsqueeze
	
	//while (FOOTstate == HIGH);
  }
  
  else
  {
    digitalWrite(LED2Pin, HIGH);
    //millis() == interval;
  }
  
  if (pressureValue>34)
  {
    digitalWrite(LED2Pin, LOW);
    lcd.begin(16, 2);
    lcd.print("System Error");
    delay (1000);
  }
}
 pressureValue = readValue*.1450377

You have pressureValue as 'type' int
.

We are using an arduino uno to control ... a momentary foot switch

Exactly how are you controlling the foot switch?

In this code we are using an LEDpin to mimic our solenoid.

I doubt that. You might be using an LED to mimic the solenoid.

BUT i want the foot switch to only open the solenoid for 5 seconds, NO MATTER how long the foot switch is depressed. Once the 5 seconds elapse, and the foot switch is released or not released there should be a delay before it is depressed again to do another 5 seconds. How do i implement this?

The state change detection example will show you how to determine that the switch has become pressed or has become released.

The blink without delay example will show you how you can turn the pin on when some event occurs, and turn it off a specific time later, without the need to block the whole code for the time that the solenoid is supposed to be active.

@PaulS we are using the foot switch to open the solenoid, meaning give it power, which the LED simulates in our mock up so far (LED is used for ON/OFF like the solenoid). When the foot switch is depressed, the LED lights up and stays on as long as the foot switch is depressed. We don't want that; we want the LED (solenoid) to stay on (open) for only 5 seconds then shut off (close, LED OFF). After that, there has to be a delay of 1 second before we can press the foot switch again to successfully repeat the cycle. The foot switch is controlled with an analog pin and power, two wires.

So the state change detection example along with blink without delay example will solve this?

Additional info: the pressure sensor used is from freescale semi-conductor, it has been calibrated and reads the correct atmospheric pressure. There will be an air line going to one nozzle of the sensor to read the pressure difference. In emergency cases, the foot switch cannot work (meaning solenoid cant open) if the pressure detected is too high. A mini air compressor supplies the air with regulator, but is not part of the arduino system.

thanks for quick replies.

Hi,

jimbo1326:
Im doing a senior design project for my engineering program with a team of four people.
Basically we are creating an automated compression cuff for medical purposes.
We are using an arduino uno to control a solenoid, a LCD display, a momentary foot switch, and read a pressure sensor.

Im having trouble with the loop part of the code with the foot switch.
In this code we are using an LEDpin to mimic our solenoid.
The solenoid will only open (because it is normally closed) when the foot switch is depressed.
In this mock up, the opening of the solenoid is the LEDpin lighting up.
Now the pin cannot light up if the pressure is too high.
For our purposes the solenoid will only operate within a specified range.
So, I want the solenoid to OPEN (LEDpin lighted up) for 5 seconds only when the foot swtich is depressed.
BUT i want the foot switch to only open the solenoid for 5 seconds, NO MATTER how long the foot switch is depressed.

Once the 5 seconds elapse, and the foot switch is released or not released there should be a delay before it is depressed again to do another 5 seconds.
How do i implement this?

jimbo1326:
@PaulS we are using the foot switch to open the solenoid, meaning give it power, which the LED simulates in our mock up so far (LED is used for ON/OFF like the solenoid).
When the foot switch is depressed, the LED lights up and stays on as long as the foot switch is depressed.
We don't want that; we want the LED (solenoid) to stay on (open) for only 5 seconds then shut off (close, LED OFF).
After that, there has to be a delay of 1 second before we can press the foot switch again to successfully repeat the cycle.
The foot switch is controlled with an analog pin and power, two wires.

So the state change detection example along with blink without delay example will solve this?

Additional info: the pressure sensor used is from freescale semi-conductor, it has been calibrated and reads the correct atmospheric pressure.
There will be an air line going to one nozzle of the sensor to read the pressure difference. In emergency cases, the foot switch cannot work (meaning solenoid cant open) if the pressure detected is too high.
A mini air compressor supplies the air with regulator, but is not part of the arduino system.

thanks for quick replies.

Sorry, but just couldn't concentrate trying to read it, can you read back any of your posts before posting them please?
To help us understand your project, can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks.. Tom.. :slight_smile:
Hint, you donot want to detect when the switch is ON, you need to detect when it is SWITCHED from OFF to ON, then instigate a timer.