In this project, a designed system obtain significant information on the behavior pattern of a resident with suitable sensors installed within the home. This system collects data on usage of water by the resident especially to the taps in the kitchen and bathroom. For diverse and precise outcomes, two sensors for the test with three development boards. Experiments to validate the results for each system in a constrained environment were performed.
One of the development boards transmits the sensor data using the Internet of Things platform. Thereby the person who had subscribed to the platform can view the information. The results analyze the behavioral patterns of the residents. This proposed system contributes as a source of information for people with dementia due to their reduced cognitive system. This valid information is useful to improve the quality of individual care for the patient.
Objective
The aim of the research is to obtain important information about the behavior of the patient in their home. A smart home system will be installed within the household to monitor the water usage of the subject is designed and developed. Primarily the sensors will be installed in the bathroom and kitchen, especially in the taps and showers. When the resident access the taps or use the bathroom shower, the system will detect and collect the data of the water usage.
The individual care for the patients will be improved through this information collected by the system. The system is taken to the next level by real-time monitoring of this information by a subscribed member of the family or caregiver. This is ultimately achieved by using the Internet of Things technology into the system. By the successful implementation of the system into the household, the people with dementia experience greater well-being and improvised clinical care.
Hardware Description
- Arduino Uno
- NodeMCU
- Piezoelectric Sensor
- Thermistor
- MCP3008
- Bread Board
- Resistors
- Connecting Wires
Contents
- Experimental Setup and Installation
- Analog Reading
- Threshold Calculations of the sensors
- Implementation with Arduino Uno
- Implementation with NodeMCU
1. Experimental Setup and Installation
The sensors connected to the analog pins of the development boards. The boards powered up to an external 12V battery or 12V adapter. The sensors taped on the pipes or taps and the whole system should be powered up.
2. Analog Readings
The analogread() reads the value from the specific analog pin. The development boards used in these experiments have a 10-bit analog to digital converters. This indicates that it will meet the range of 0V and the operating voltage of 5V or 3.3V mapped into the integer values between 0 and 1023. In some boards, a 12-bit Analog to Digital Converter is used. In that case, the operating voltage mapped into the integer values of 0 and 4095.
It only takes about 100 microseconds to read one single analog input. Hence the maximum reading rate is 10,000 times per second. Each analog pin is a 10-bit ADC and it can store 1024 values. For instance, if the operating voltage is 5V with a 10-bit ADC then it yields a resolution of 0.49mV per unit. This calculation reports a ratiometric value. The 5V is assumed to be the integer value of 1023 and 0V will be the integer value of 0.
The System Voltage and the Resolution of the ADC known from the development board. The ADC reading measured from the analog devices connected to the analog pin. The analog voltage calculated from the ratio. For instance, if the ADC reading is 500 and the System voltage is 3.3 V which has a 10-bit ADC then the analog voltage measured is 1.61V. Alternately, the Analog Voltage measured using a digital multimeter.
3. Threshold Calculations of the sensors
The analog sensors in this research have great sensitivity but the functions of the sensors limited. The sensors placed on the taps or pipes in such a way to detect only the water flow from the pipe. So a threshold value should set to the sensor by the user. Based on the surface of the material of the pipe, these values calculated from the trial and error method. First, the sensor placed on the material from which it is going to detect the water flow. A LED connected to indicate the output. The maximum threshold for the sensor is 1023 units as it reads from the analog pin of the Arduino. A random integer value set between 0 and 1023 units in the code to provide a maximum threshold for the sensors to detect the water flow in a pipe.
For example, the tap opened (water is flowing in the pipe) and the threshold value to a random integer say 500 units (2.44V). The user in the Arduino and if the LED blinks then the water flow detected at that particular threshold value. Hence for every time, the user sets a threshold value for the sensor by trial and error method to indicate the flow in the pipe. Therefore, a maximum and minimum threshold values at which the water flow detected based on their rate of flow.
4. Implementation with Arduino Uno
4.1 Arduino Uno and Piezoelectric Sensor
The experiment setup uses the piezoelectric effect on the sensor implemented with the Arduino Uno. The circuit represents a basic circuit in which 1 Megaohm resistor connected along with the Piezoelectric sensor and the analog pin A0. The threshold value calculated by the trial and error method as described in the previous section. Sometimes the signal from the sensor low, so an amplifier circuit and a voltage divider are to increase the signal from the sensor.
The amplifier circuit consists of an operational amplifier LM 6132 which provides new levels of speed versus power performance in applications. It consists of Rail-to-Rail Input Common mode voltage range of -0.25 V to 5.25 V. The LM 6132 can drive by the voltages that will exceed both the power supply rails thus eliminating the exceeding over the CMVR.
The piezoelectric sensor attached to the LM 6132 operational amplifier with 5K ohms feedback resistor and a 1K ohm resistor. The voltage divider circuit connected to the Operational amplifier which is to create a voltage less than the input voltage. The main purpose of the voltage divider circuit is to reduce the input voltage to a lower value based on the resistor values. This circuit helps to determine the output voltage given the input voltage and the given resistors. In this case, the resistor values are 5K ohms and the input voltage is 5V.
The code is in Arduino IDE in which some threshold values and the base values are for the sensor. According to the piezoelectric effect, when there is mechanical stress applied to the sensor the current is generated. By this principle when the tap is ON (water flowing inside the pipe), the sensor detects the flow with the provided threshold values in the code and presents the result. When the subject opens the tap to use water, the sensor detects the flow until the tap closes again.
4.1.1 Code
const int ledpin=12;
int sensor =A0;
int analogvalue =0; // Current reading for analog pin
int threshold;
int basevalue =0 ; // Base reading
int led= LOW;
void setup()
{
pinMode (ledpin, OUTPUT);
Serial.begin(9600);
threshold = basevalue; // setting the threshold at base analog reading
}
void loop()
{
analogvalue = analogRead(sensor);
if (analogvalue > basevalue)
{
analogvalue = analogvalue - basevalue;
}
else
{
analogvalue = basevalue - analogvalue;
}
threshold = (threshold * 0.5) + (analogvalue * 0.5);
if (threshold >200)
{
led=!led;
digitalWrite (ledpin, led);
float piezovoltage = threshold *(5.0 / 1024.0);
Serial.println(piezovoltage);
Serial.println("The tap is ON");
delay(1000);
}
}
4.1.2 Circuit Diagram
The output of the piezoelectric sensor is verified by connecting to the LED. When there is a flow, the LED blinks. The output depends on the threshold and the base reading values of the sensor. If the mechanical stress applied to the sensor is above the threshold value, the LED blink indicates a flow. However, there is a delay observed when the tap is OFF there is still an indication of the flow.
The sensor is attached to the tap and the setup is powered up.
The time period of the tap ON and OFF duration is 20 seconds. At 00.00.00 s the tap is ON with water flowing at full speed and exactly at 00.00.20 s the tap is closed. Totally 3 trials are used in this experiment. The speed of the water flow is constant for all the trails.
Result
The table represents the results of the experiments which contain some observed delays. The LED is still ON even when the tap is closed (the water supply is cut off). In the 1st trial, The tap is closed at 20th second and the water flow is cut off but the LED blinks OFF at 25th second. There is a delay observed for 5 seconds.
Basically, the delay is because of the charge accumulation on the crystal, leakage current or the internal resistance. Provided that, the alternate circuit which amplifies the signal from the piezoelectric sensor only increases the signal but it doesn’t reduce the delay in the output. A simple setup is enough for the detection of the vibration coming from the flow of water in a pipe.
4.2 Arduino Uno and Thermistor
The Arduino setup depicted in Figure 14 detects the water flow in an enclosed pipe. The thermistor taped to the pipe and to the analog pin A0 in the Arduino connected. A 10K ohm resistor connected along with the supply. The software implemented with the Arduino and the sensor reads from the analog values.
The NTC thermistors sense the temperature which made of semiconductor material, which has a large change in the resistance when there is a small change in temperature. Figure 13 shows a code snippet of Arduino IDE which describes the change in temperature. The last read temperature set at the analog integer value of 0. The sensor reads a temperature (new) and compares it with the last read temperature every 2 seconds. Whenever there is a change in the difference of +/- 10 analog values than the previous temperature, then there is water flow in the pipe. The new temperature set as the last read temperature and compares with the new temperature after a delay of 2 seconds.
4.2.1 Code
int ledpin=13;
int tempsensor= A0;
int tempanalog=0; //last temp
void setup()
{
Serial.begin(9600);
pinMode(ledpin,OUTPUT);
digitalWrite (ledpin,LOW);
tempanalog= analogRead (0); //last temperature is the tempanalog
}
void loop()
{
tempsensor=analogRead (0);
if (tempanalog > (tempsensor+10))
{
digitalWrite (ledpin,HIGH);
tempanalog= tempsensor; //setting the old temperature as new temp
}
if (tempanalog < (tempsensor-10))
{
digitalWrite (ledpin, HIGH);
delay (100);
tempanalog= tempsensor; //setting the old temperature as new temp
}
tempanalog= tempsensor; //setting the old temperature as new temp
float tempvol = tempsensor *(5.0 / 1024.0);
Serial.print("temp ");
Serial.println(tempvol);
delay(2000);
}
4.2.2. Circuit Diagram
5. Implementation with NodeMCU
In this setup, the sensor is connected to the pin A0 which is the one and only analog pin available in the NodeMCU. This board runs on the ESP8266 Wi-Fi SoC and is an open-source IoT platform. Especially for this type of setup, an Adafruit MQTT protocol (Message Queuing Telemetry Transport) is a cloud service for the experiment. The protocol is Adafruit IO which is a free cloud service for IoT experiments. The LUA script and the Arduino IDE are very much compatible with the NodeMCU. The SSID and the password fed in the code and the details of the API key from the Adafruit IO along with the server and the port information mentioned in the code.
5.1 NodeMCU and Piezoelectric Sensor
The circuit consists of a 1M ohm resistor along with the Piezoelectric sensor connected to the analog pin A0 and 3.3 V supply. The threshold value is between 5 and 20 analog values. In that case, when the sensor analog reading is above the threshold value then there is water flow in the pipe.
5.1.1Code
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WLAN_SSID "monisha"
#define WLAN_PASS "12345678"
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "monishavasu"
#define AIO_KEY "5442f5e59887494e84590cbe9b0cd936"
int ledpin=D1;
int sensor =A0;
int analogvalue=0; // Current reading for analog pin
int threshold= 20;
int led= LOW;
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// i am going to publish my data alone. no need of subscription, so feed is enough
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish Piezo_voltage = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Piezo_voltage");
Adafruit_MQTT_Publish piezo_graph= Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/piezo_graph");
/*************************** Sketch Code ************************************/
void setup()
{
Serial.begin(9600);
pinMode (ledpin, OUTPUT);
// Connect to WiFi access point.
Serial.print("\n\n\nConnecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(">>");
delay(5000);
}
Serial.println("WiFi connected");
//Serial.println("IP address: "); Serial.println(WiFi.localIP());
}
void loop()
{
MQTT_connect();
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
analogvalue = analogRead(sensor);
if (analogvalue>=threshold)
{
led=!led;
digitalWrite (ledpin, led);
float piezovoltage = analogvalue *(3.3 / 1024.0);
Serial.println(piezovoltage);
// Now we can publish stuff
Serial.print(F("\nSending piezo val "));
Serial.print(piezovoltage);
Serial.print("...");
if (! Piezo_voltage.publish(piezovoltage++)) {
Serial.println(F("\nFailed"));
} else {
Serial.println(F("\nOK!"));
}
if (! piezo_graph.publish(piezovoltage++)) {
Serial.println(F("\nFailed"));
} else {
Serial.println(F("\nOK!"));
delay (3000);
}
}
}
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect()
{
int8_t ret;
// Stop if already connected.
if (mqtt.connected())
{
return;
}
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(3000); // wait 3 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}
In the piezoelectric sensor, the graph changes proportional to the mechanical stress applied to the crystal. It maintains the minimum value with the range of 0V to 0.5V and goes to the maximum of 1.5V to 2V. Sometimes the sensor shows the errors such as a sudden rise to the maximum voltage of 3.3 V. Table 3 represents the delays and error observed in the experiment which held for 2 hours.
5.2 NodeMCU and Thermistor
The thermistor is connected to the only analog pin A0 available in the NodeMCU. The circuit consists of a 10K ohm fixed resistor connected to the sensor with the 3.3 V supply. The 10K ohm NTC thermistor is a variable resistor which is been used in the circuit. When there is a temperature change in the water flow, the thermistor detects the change in temperature and displays in a graph. According to the working principle of the NTC thermistor, when the temperature is increased, the variable resistor (thermistor) decreases and vice-versa. This phenomenon can be verified placing a multimeter across the thermistor.
5.2.1 Code
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WLAN_SSID "monisha"
#define WLAN_PASS "12345678"
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "monishavasu"
#define AIO_KEY "5442f5e59887494e84590cbe9b0cd936"
int ledpin=D0;
int tempsensor= A0;
int tempanalog=0; //last temp
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
// i am going to publish my data alone. no need of subscription, so feed is enough
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish thermistor_voltage = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/thermistor_voltage");
Adafruit_MQTT_Publish thermistor_graph= Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/thermistor_graph");
/*************************** Sketch Code ************************************/
void setup()
{
Serial.begin(9600);
pinMode(ledpin,OUTPUT);
digitalWrite (ledpin,LOW);
tempanalog= analogRead (0); //last temperature is the tempanalog
// Connect to WiFi access point.
Serial.print("\n\n\nConnecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(">>");
delay(5000);
}
Serial.println("WiFi connected");
//Serial.println("IP address: "); Serial.println(WiFi.localIP());
}
void loop()
{
MQTT_connect();
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
tempsensor=analogRead (0);
if (tempanalog > (tempsensor+10))
{
digitalWrite (ledpin,HIGH);
tempanalog= tempsensor; //setting the old temperature as new temp
}
if (tempanalog < (tempsensor-10))
{
digitalWrite (ledpin, HIGH);
delay (100);
tempanalog= tempsensor; //setting the old temperature as new temp
}
tempanalog= tempsensor; //setting the old temperature as new temp
float tempvol = tempsensor *(3.3 / 1024.0);
Serial.print("temp ");
Serial.println(tempvol);
delay(2000);
// Now we can publish stuff
Serial.print(F("\nSending Thermistor val "));
Serial.print(tempvol);
Serial.print("...");
if (! thermistor_voltage.publish(tempvol++)) {
Serial.println(F("\nFailed"));
} else {
Serial.println(F("\nOK!"));
}
if (! thermistor_graph.publish(tempvol++)) {
Serial.println(F("\nFailed"));
} else {
Serial.println(F("\nOK!"));
delay (5000);
}
}
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect()
{
int8_t ret;
// Stop if already connected.
if (mqtt.connected())
{
return;
}
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}
In thermistor, after many calibrations, the voltages at water flow at room temperature, during hot and cold water are analyzed and the values are noted down. The experiment is held nearly 2 hours from 8:58 pm to 10:48 pm. According to the World Health Organization’s standard for comfort room temperature for elder adults is a minimum [22] of 20 °C (68 °F). Table 4 shows various results for experimenting at different temperatures. At room temperature, the output voltage is from 1.4V to 1.6V. The output voltage decreases as the temperature decreases and the voltage increases as the temperature increases. There is no delay observed in this experiment.
6. Results
Results
Click here: Experiment implementation for Raspberry Pi in this post.