Very new here. Any help would be greatly appreciated

Hi all,

As mentioned above, I am very new to Arduino. Please bear with me here.

I have been tasked to create an 'out of bed' alarm, for a hospital, that will interface with an existing nurse call system.

Basic set up:

Pressure pad will be placed under a clients shoulders, so when they sit up in bed the nurse call system will alert staff. The nurse call system is looking for a closed contact to trigger the alarm, and only needs a 60mS input to trigger.

My plan:

I have a pressure pad that is normally open, when the client lays on it, it switches to a closed contact. I have chosen to use an Arduino to manage the change of state (so the alarm will trigger when the pressure pad changes to open, instead of closed), and also to implement a 2-5 second delay, to allow the client to move around in bed without setting off the alarm falsely. I will be driving a 5v relay board from the Arduino to switch the nurse call system 24v back into a nurse call system input to trigger a call.
I must also say that due to time restraints, the only gear I could get locally was a Funtronics 'Leostick', and slave relay board. The Leostick is basically a counterfeit Leonardo, compressed to fit onto a thumb drive sized USB stick. I have uploaded a simple blink on/blink off sketch, and it appears to work correctly.

My idea:

I am thinking of code along the lines of: monitor digital input closed contact, when it opens, trigger timer for (say) 5 seconds. If input contact does not close with-in 5 seconds, digital output to trigger relay. If input contact closes with-in 5 seconds, stop and reset timer and continue to monitor digital input closed contact.
The setup does not need to latch the relay, as the nurse call system latches a call alarm, until a staff member pushes the reset button, so it only needs to switch the relay for a period greater that 60mS (say half a second, to allow a buffer).

Sorry for the long winded story, I would love to take my time with this and learn the coding myself first, but I have to find a solution to this problem as soon as possible, and I have been unable to find any suitable code anywhere as yet.

Any assistance with coding this project would be greatly greatly appreciated.

Many thanks,
Horn20

Horn20:
'out of bed' alarm, for a hospital,

I thought that was why we pay nurses ?

...R

It is a read switch and operate relay program.

Look at the learning tab at the top of this page. You will find the basics of what you need.

Remember to use a drive transistor for the relay (and bypass diode). Don't for get to use a pull up R with your switch to ground.

Once you get these going, we can help add the next parts such as time delay before activation and pulsing the relay.

Weedpharma

weedpharma:
It is a read switch and operate relay program.

Look at the learning tab at the top of this page. You will find the basics of what you need.

Remember to use a drive transistor for the relay (and bypass diode). Don't for get to use a pull up R with your switch to ground.

Once you get these going, we can help add the next parts such as time delay before activation and pulsing the relay.

Weedpharma

Thanks very much, I will do these things, and come back.

Well, I have finished setting up the hardware, and have uploaded a simple button push to turn on a LED, and a relay, and have used an internal resistor to pull up the pressure pad switch. The whole setup works beautifully.

Now I just need to figure out how to write in a 2-5 second delay before the relay output energizes, whilst continuing to monitor the pressure pad.

monitor switch,
switch goes high,
start timer 3 seconds,
if switch not pressed within 3 seconds,
trigger alarm,
else,
reset timer,
continue to monitor switch.

Thanks for the feed back Weedpharma.

I am a little excited to have my first Arduino project half done.

Any more help would be hugely appreciated.

Horn20.

look at both the debounce and blink without delay.
they use the concept of the timer to count

when your switch changes state, like in debounce,
you load your variable with the value of the system clock millis()

(1) you only load it once.

(2) then check how long it has been.

(3) you have to have a flag set to stop your variable from being set on each scan.

I call this series of programming steps a 3 card montie because you seem to have to do the thing you don't care about.

to set it up, you have to have a flag that looks at the switch state. this goes at the very end of the sketch, after everything else.

oldSwitchState=switchState; // load odSwitchState variable.

then, to see if the switch has changed,

if ( switchState == !oldSwitchState ) { // if it is = to the opposite of the oldSwitchState

then you load your variable with the system clock time. I use 'then' because I like simple terms.

then=millis()
}

now you have to see how long it has been, subtract time of then from the system clock.

if (millis() - then >= 2000 ) { // 2000 = 2 seconds or 2,000 ms
digitalWrite(nurseCallRelay,LOW); // LOW or HIGH, as needed
}

don't forget that sooner or later you have to re-set that relay.
maybe the nurse does that ?
or, maybe if the patient lies down again, you could write this again, for that ?

Thanks dave-in-nj,

I will have a play with this later today, and let you all know how I go with it.

Many thanks again.

Horn20

This is doing my head in!

I can't seam to get the sketch right, every one i have tried will compile ok, but then will react not as desired.

Starting to wonder if a delay will work, as follows, my question is, what is going to happen when this sketch runs continuously?

Thanks again.

button_with_delay.ino (1.54 KB)

digitalRead(buttonPin);

You forgot the assignment

Horn20:
Starting to wonder if a delay will work, as follows, my question is, what is going to happen when this sketch runs continuously?

Avoid delay() in any sketch you write!

An alarm by timeout condition can be done like that:

unsigned long timeoutStartMillis;
void loop() {
  buttonState = digitalRead(buttonPin);         // read the state of the pushbutton value:
  if (buttonState == HIGH) timeoutStartMillis=millis(); // reset start of timeout to current time
  
  if (millis()-timeoutStartMillis>=3000)  // timeout condition has become true
    digitalWrite(ledPin, HIGH);                 // turn LED on:
   else
    digitalWrite(ledPin, LOW);                 // turn LED off:
}