shubh23795
Published

Bed Vacancy Alarm

It is generally for the safety of the patient.

BeginnerWork in progress1 hour802
Bed Vacancy Alarm

Things used in this project

Hardware components

Arduino UNO Click Shield
MIKROE Arduino UNO Click Shield
×1
force sensing resistor
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Schematics

20170420_122315_Aqp6MktYj9.jpg

Code

bed vacancy alarm

Arduino
/*
*Little Bed Vacancy Alarm
*Platform: Arduino UNO/ATmega328P-PU/IDE0022
*/
const int ledAlert = 13; // Pin 19 of IC2
const int ledStby = 12; // Pin 18 of IC2
const int beepAlert = 11; // Pin 17 of IC2
int fsrPin = 0; // FSR Input A0 / Pin 23 of IC2
int fsrReading; // Analog Reading-FSR input
int curCounter = 0; // Wake-Up Counter
void setup(void) /* This function is used to initialise
control pin as digital O/P */
{
pinMode(ledAlert, OUTPUT);
pinMode(ledStby, OUTPUT);
pinMode(beepAlert, OUTPUT);
}
void loop(void) /* This function is used to read FSR output and
generate an alarm, depending on the threshold value */ 
{
int fsrReading = analogRead(fsrPin);
  if (curCounter >=15)//Wake-Up Delay
  { 
  digitalWrite(ledAlert, HIGH); //Bed Vacancy-Alert ON
  digitalWrite(ledStby, LOW);
  playTone(500, 600);
  delay(100);
  playTone(500, 800);
  delay(100);
  }
  if (fsrReading < 100)// Bed Vacany Threshold (empirically-selected value/see text)
  { 
  curCounter++; // Increment Counter-Wake Up Mode
  }
else if (fsrReading > 600) // Bed Occupancy Threshold (empirically-selected value/see text)
  { 
  digitalWrite(ledAlert, LOW);
  curCounter = 0; // Reset Counter-Sleep Mode
  digitalWrite(ledStby, HIGH);
  playTone(0, 0);
  }
delay(100);
}
void playTone(long duration, int freq) // Alert Tone
{ 
duration *= 1000;
int period = (1.0 / freq) * 1000000;
long elapsed_time = 0;
  while (elapsed_time < duration) 
  {
  digitalWrite(beepAlert,HIGH);
  delayMicroseconds(period / 2);
  digitalWrite(beepAlert, LOW);
  delayMicroseconds(period / 2);
  elapsed_time += (period);
  }
}

Credits

shubh23795
1 project • 0 followers
I am biomedical engineer.

Comments