Toward Sustainable Gentle Awakenings and Sleep Inertia Mitigation: A Low-Cost IoT-Based Adaptable Lighting and Temperature Control Approach

: In this paper, our design aims to assist in sleep inertia reduction and avoid the startle response and irritation caused by alarm-made unpleasant wakeup stimuli. Thus, we propose an approach that employs a soft and alerting sunrise simulation, conditionally utilizes natural light, and appropriately lowers the bedroom temperature for awakening a sleeper tenderly and gradually to gain full alertness. This approach is inspired by known scientiﬁc implications conﬁrming the effectiveness of lights and temperatures on wakefulness. In this regard, we present an economical do-it-yourself digital tech-assisted system for bedroom lighting and temperature control. The system design is based on the smartphone and Internet of Things (IoT) technology. We develop the hardware and software in the system for implementing three IoT-based control tasks. One is the tuning of artiﬁcial light brightness using the pulse width modulation technique. Another is the opening of the window curtain using stepper motor control and light detection. The other is the activation of the air-conditioning setting using an infrared remote control and temperature detection. We construct a testbed for conducting experiments. Experimental results demonstrate that the proposed system can execute task requirements satisfactorily. The proposed system is promising for achieving our goal. It embodies features of sustainability.


Introduction
In our daily experience, having a comfortable and relaxing morning awakening can usually make us feel refreshed.Consequently, it may in turn enhance work/study efficiency throughout the day.However, a lot of people may complain and feel irritated and drowsy if they are awakened by means of undesirable stimuli (e.g., the loud sound of traditional alarm clocks).More unpleasant experiences (e.g., behavior and safety problems) are likely to occur among adolescents and students with deep sleep and being suddenly shocked into awakening.Alerstedt et al. [1] indicated that sleep and wakefulness are two distinct behavior states that differ in terms of muscular and neuronal activity and consciousness.In addition, the transition from sleep to waking involves physiological operations that yield a new behavior state although wakeups intrinsically change as a function of several factors such as circadian phase, age, and sleep quality.This indication, together with the aforementioned experiences, suggests that sudden awakenings essentially lead to abrupt changes in melatonin and cortisol levels and neurotransmission rates that could cause agitating feelings and sleep inertia.Accordingly, our daily morning awakening ritual is a vital event that potentially has a great impact on wellbeing and work performance.It is logical to support the idea of gentle awakenings closer to wakefulness.
Light can enter the eyes even though eyelids are closed during sleep.It stimulates the retina to send a signal down to a nerve tract to the circadian clock in the brain.In this regard, numerous studies (e.g., [2][3][4] and references in [5]) have shown that light plays a crucial role in affecting circadian rhythm and human health.Boivin et al. [2] demonstrated that humans are quite sensitive to light, and even dim indoor room light can significantly influence the circadian clock.Czeisler et al. [3] showed that bright light can reset the human circadian pacemaker.Blume et al. [4] indicated that light has an effect on sleep and mood, which in turn affects health.Moreover, early morning exposure to light was found to decrease the secretion of melatonin (e.g., [2]) and increase cortisol levels (e.g., [6,7]), thus mitigating morning drowsiness.Similarly, artificial dawn awakenings in healthy persons can result in enhancing wakefulness, which reduces sleep inertia complaints (e.g., [8][9][10]).Hilditch et al. [11] also indicated that light can be utilized as a countermeasure to sleepiness.These findings imply that artificial/natural light makes awakening and wakefulness easy.
Krauchi et al. [12] showed that thermoregulation has an impact on the decay of sleepiness.Thus, some studies (e.g., [11,12]) have suggested that the regulation of ambient temperature may be useful for counteracting sleep inertia.Heat tends to make people feel fatigued and drowsy.In contrast, when you are cold, your body needs to work harder to retain its warmth, which keeps you more alert.Therefore, it is plausible that an adequate drop in the bedroom temperature within a short period of time may effectively trigger gentle awakenings and expedite the dissipation of sleepiness.
In this paper, our design aims to assist in sleep inertia mitigation and avoid the startle response and annoyance caused by alarm-made unpleasant wakeup stimuli.To tackle the problem, the innovation of a gentle and inexpensive awakening scheme that can enhance one's wellbeing is vital.Thus, we propose an approach that employs a soft and alerting sunrise simulation, utilizes natural light if applicable, and appropriately lowers the bedroom temperature for awakening a sleeper tenderly and gradually to gain full alertness.This approach is inspired by the abovementioned scientific implications and the advice in [13][14][15] that lighting design in rooms and buildings has to take health issues into account.Moreover, this approach is proposed herein because it seems promising for achieving the design goal and improving one's wellbeing.In this regard, we present an economical digital tech-assisted system for adaptable bedroom lighting and temperature control.We herein make the overall design process of the proposed system accessible to everyone for do-it-yourself (DIY) implementation.The proposed system design is focused on simplicity, low-cost implementation, easy maintenance, high reliability, and convenient personalization and expandability.
In recent years, many research and development efforts have already been made on enabling technologies for Internet of Things (IoT) (e.g., [16,17]) to support various applications, including the improvement of the quality of life (e.g., home services in [18][19][20] and parking systems in [21]), the enhancement of economic growth (e.g., irrigation systems in [22] and supply chains in [23,24]), and the advancement of environmental sustainability (e.g., big data analytics in [25]).Moreover, the integration of wireless sensor networks and IoT has been proposed for environmental condition sensing and monitoring (e.g., [26][27][28]).In particular, a smartphone has been integrated with an IoT platform for providing personalized services (e.g., [29]) because it has been a common personal mobile communication device.In addition, a smartphone has a built-in function of playing relaxing music.This function can be set up and activated at the alarm time as pleasant noise to lower the stress level of the user after an awakening, which may help reduce sleep inertia.Hence, the advantages of the aforementioned practices motivate us to achieve our design goal using the smartphone and IoT technology.
In this study, we employ the Node MicroController Unit (NodeMCU) [30], equipped with inexpensive and powerful IoT-enabling digital technologies, for connecting to a smartphone through Wi-Fi and performing lighting and temperature control.This choice is made because the NodeMCU is suitable for our system design and much cheaper than other microcontrollers available in the market (e.g., the Raspberry Pi used in [29]).Bluetooth devices are not used herein because they can be easily disconnected with the interference of environmental noise.Although a feedback control approach for adjusting lighting levels in buildings has been proposed in [31], its performance, however, depends on the quality of a photodetector used in the feedback loop of the lighting output.To avoid this drawback, we utilize an open-loop pulse width modulation (PWM) technique for a dawn simulation.This simulation starts with stably tuning one yellow color light tube to mimic the gradual transition of yellow light color and intensity of sunrise and then turns on one white color light tube as soon the yellow color light tube is switched off.The tender yellow light stimulus from a simulated dawn can help a sleeper prepare the body out of deeper sleep stages and closer to wakefulness.Hence, this artificial process is scheduled to take place in an adjustable span of 5-15 min prior to the alarm time that the white color light tube is turned on and the smartphone plays relaxing music.Unlike [29,32,33], the bright white light is also adopted in our design as an awakening stimulus because it has alerting attributes and can subdue any ongoing melatonin production.Based on findings, waking up to natural light is the best.This condition together with the idea of climate-based daylight utilization in the interior room design in [34] motivates us to incorporate stepper motor control and light detection into our design for opening window coverings at the alarm time.To appropriately drop the bedroom temperature during the dawn simulation, we choose air conditioning because air conditioners are among the most common electrical appliances in homes within many countries and can effectively cool down a room.We first utilize a sensor for reading the ambient temperature at the beginning of the dawn simulation as a referenced value.Then, a desired temperature is the result of subtraction of a prescribed degree of temperature drop from the referenced value.Subsequently, the air conditioner is activated and associated with the desired temperature setting using an infrared remote control.
We build a testbed for conducting experiments.The total cost of the testbed (excluding the smartphone and the air conditioner) is no more than USD 32.00.The experimental results substantiate the consistency between the quantitative data and qualitative observations of the proposed system for performing a sunrise simulation, curtain opening, and bedroom temperature drop.The outcomes confirm that the system performance can reliably satisfy our design requirements.
Overall, the proposed system is promising for achieving our design goal.In addition, it embodies the environmental, economic, and social aspects of sustainability (e.g., [35]).Specifically, the proposed system is eco-friendly.It is sustainable from the economic perspective since it is affordable and can be easily maintained.In the social aspect, the proposed system promotes health, and the system construction is inexpensive and accessible to everyone, which implies equity in the opportunity of DIY implementation.
In comparison with the existing lighting systems that are closely related to our work, the advantages and disadvantages of the proposed system are given as follows.Distinct from other existing lighting systems, the proposed system performs lighting regulation and temperature control.In this way, the proposed system can help achieve our design goal more effectively.Our system design can yield a high-quality dawn simulation superior to the method for a sleep care system in [29] in which light brightness is only partitioned into five prespecified levels.The proposed DIY design and various sunrise alarm clocks available commercially in [30] have the same purpose of performing an excellent dawn simulation.They are more sophisticated than the awakening stimulus control system in [33].The proposed design is distinct in many aspects from those in [32,33] in accordance with the design method and system functions.For instance, sunrise alarms in [32] and the system in [33] were standalone and lacked expandable features for home automation, so they cannot incorporate the utilization of natural light.The proposed design is also distinguished from the methods in [36,37], which only control the on/off switch of lighting equipment.Because the proposed system employs the HTTP protocol for the internet connection, its drawback is that no internet security protection is applied.As such, the proposed system may break down due to cyberattacks.To cope with the problem, plausible approaches may include the incorporation of cryptographic techniques or attack-resilient control methods into the software design of the proposed system.
We summarize our contribution in the following. a.
We develop a new low-cost adaptable bedroom lighting and temperature control system based on the smartphone and IoT technology.b.
The proposed system performs a soft and alerting dawn simulation, conditionally makes use of natural light, and adequately cools the bedroom down.c.
The proposed system is promising for effectively achieving sustainable gentle awakenings and assisting in sleep inertia reduction.d.
The proposed system aligns with the values of sustainability, such as environmental friendliness, economic viability, and positive social development.
The rest of the paper is organized as follows.In Section 2, we present the proposed system and the design of hardware and software.In Section 3, we describe the experimental setup and provide experimental evaluations of the proposed system on performance reliability.In Section 4, we discuss the results, findings and future works.

Materials and Methods
We briefly recapitulate our design goal, proposed approach, rationale, and implementation method as follows.Our design aims to awaken a sleeper gently and help to reduce sleep inertia.In this respect, we propose an approach that conducts a soft and alerting dawn simulation, conditionally utilizes natural light, and moderately cools the bedroom down for awakening a sleeper progressively to be alert.This approach is promising for attaining our design goal because it is proposed in accordance with known scientific findings confirming the effectiveness of lights and temperature on human wakefulness.As mentioned previously, IoT plays an important role in sustainability.So, to implement the proposed approach, we present an IoT-based adaptable bedroom lighting and temperature control system.
In the sequel, we introduce the main function, hardware and software development of each unit in the proposed system.

Functional System Structure
The proposed system framework is composed of a sunrise simulation and temperature control alarm app (SSTCAA), SSTCAA database, NodeMCU, real-time clock (RTC), controllable lamp illuminance (CLI) unit, controllable daylight utilization (CDU) unit, and temperature control (TC) unit.The interconnection between functional units is illustrated in Figure 1.
ternet connection, its drawback is that no internet security protection is applied.As suc the proposed system may break down due to cyberattacks.To cope with the proble plausible approaches may include the incorporation of cryptographic techniques or a tack-resilient control methods into the software design of the proposed system.
We summarize our contribution in the following.
a. We develop a new low-cost adaptable bedroom lighting and temperature contr system based on the smartphone and IoT technology.b.The proposed system performs a soft and alerting dawn simulation, conditiona makes use of natural light, and adequately cools the bedroom down.c.The proposed system is promising for effectively achieving sustainable gentle awa enings and assisting in sleep inertia reduction.d.The proposed system aligns with the values of sustainability, such as environmen friendliness, economic viability, and positive social development.
The rest of the paper is organized as follows.In Section 2, we present the propos system and the design of hardware and software.In Section 3, we describe the expe mental setup and provide experimental evaluations of the proposed system on perfo mance reliability.In Section 4, we discuss the results, findings and future works.

Materials and Methods
We briefly recapitulate our design goal, proposed approach, rationale, and imp mentation method as follows.Our design aims to awaken a sleeper gently and help reduce sleep inertia.In this respect, we propose an approach that conducts a soft an alerting dawn simulation, conditionally utilizes natural light, and moderately cools t bedroom down for awakening a sleeper progressively to be alert.This approach is prom ising for attaining our design goal because it is proposed in accordance with known s entific findings confirming the effectiveness of lights and temperature on human wak fulness.As mentioned previously, IoT plays an important role in sustainability.So, to im plement the proposed approach, we present an IoT-based adaptable bedroom lighti and temperature control system.
In the sequel, we introduce the main function, hardware and software developme of each unit in the proposed system.

Functional System Structure
The proposed system framework is composed of a sunrise simulation and temper ture control alarm app (SSTCAA), SSTCAA database, NodeMCU, real-time clock (RTC controllable lamp illuminance (CLI) unit, controllable daylight utilization (CDU) unit, an temperature control (TC) unit.The interconnection between functional units is illustrat in Figure 1.The SSTCAA on the smartphone is created for setting up the on/off status of the alarm, alarm time, sunrise simulation duration in the CLI unit, the on/off status of the window curtain opening in the CDU unit, and the on/off status of the air conditioner and the degree of temperature drop in the TC unit.As soon as the data on the SSTAA are submitted, they are stored in the NodeMCU and the SSTCAA database.
The SSTCAA database is created for information storage and retrieval.It is useful for the analysis of stored data.
The NodeMCU serves as the central control center for the proposed system.It provides very low-price and powerful IoT-enabled digital technologies consisting of an open-source software and hardware development environment and a system-on-a-chip called the ESP8266.It has built-in support for Wi-Fi connectivity, output pins for general purpose input/output (GPIO) and PWM, and an input pin for analog-to-digital conversion (ADC).Because the NodeMCU is equipped with those functions, it can be programmed to connect to the app and RTC, activate the CLI unit, optionally turn on the CDU unit, and switch on the TC unit.
The RTC is the DS1302 timekeeping chip.It provides the time information for the NodeMCU to access constantly so as to perform tasks timely based on the SSTCAA data.In this manner, the operations of the proposed system can continue even if the smartphone is powered off or set in airplane mode.
The main function of the proposed CLI unit is the sunrise illuminance simulation.The CLI unit gives off a yellow light color from dim to bright, and finally yields the bright white light color.The activation of the CLI unit is mandatory if the alarm is set "ON." The main function of the proposed CDU unit is to optionally make use of natural lights.The CDU unit detects the outdoor daylight illuminance and conditionally opens window coverings using stepper motor control.
The main function of the proposed TC unit is to lower the bedroom temperature.The TC unit detects the ambient temperature and switches on the air conditioner using an infrared remote control to yield a prescribed degree of the bedroom temperature fall.

Creation of the SSTCAA and SSTCAA Database
We employ MIT App Inventor [38], a cloud-based web application integrated development environment (IDE), for creating the SSTCAA that can run on a smartphone.Once the SSTCAA is built, the SSTCAA database is automatically created on the smartphone.
The web editor of MIT App Inventor uses a graphical user interface that allows us to drag and drop visual objects to build our functional app.As such, it makes the app development easy.We access the MIT App Inventor on a computer and smartphone using the same user account.Once the app is built or modified on the computer, it is updated in the cloud and on the smartphone simultaneously.We use visual programming items on the web editor for the functional development of the SSTCAA.The functional tasks of the SSTCAA are listed as follows.
 Store the data displayed on the SSTCAA and internet protocol (IP) address of the NodeMCU.
 Calculate the starting time of the sunrise simulation as We utilize visual tools on the web editor for the display design of the label, button, time picker, textbox, and background color of the app.Thus, the appearance layout of the SSTCAA is depicted in Figure 2. It is intuitive to use the SSTCAA.
We use visual programming items on the web editor for the functional development of the SSTCAA.The functional tasks of the SSTCAA are listed as follows.

•
Store the data displayed on the SSTCAA and internet protocol (IP) address of the NodeMCU.

•
Calculate the starting time of the sunrise simulation as

•
As soon as the "Submit" button is pressed, data displayed on the SSTCAA, the time stamp, and the result of ( 1) are sent to and stored in the NodeMCU via the Wi-Fi IP address of the NodeMCU.They are also stored in the SSTCAA database.

Hardware Implementation in the CLI Unit
The hardware in the CLI unit of this study consists of two Tube LED 5630 (one yellow light and one white light) and two negative impedance converters (NICs).The connected hardware in the CLI unit is shown in Figure 3.  As soon as the "Submit" button is pressed, data displayed on the SSTCAA, the time stamp, and the result of ( 1) are sent to and stored in the NodeMCU via the Wi-Fi IP address of the NodeMCU.They are also stored in the SSTCAA database.

Hardware Implementation in the CLI Unit
The hardware in the CLI unit of this study consists of two Tube LED 5630 (one yellow light and one white light) and two negative impedance converters (NICs).The connected hardware in the CLI unit is shown in Figure 3.As shown in Figure 3, the two NICs are constructed based on the selected resistors and HA17458 series dual operational amplifiers.An NIC is employed due to the following reasons: The "ON" output signal voltage of a PWM pin of the NodeMCU is 3.3 V, whereas As shown in Figure 3, the two NICs are constructed based on the selected resistors and HA17458 series dual operational amplifiers.An NIC is employed due to the following reasons: The "ON" output signal voltage of a PWM pin of the NodeMCU is 3.3 V, whereas the "ON" input signal voltage of the Tube LED 5630 requires 8.65 V. Therefore, the control of each Tube LED from the NodeMCU needs an NIC to perform the voltage conversion from 3.3 V to 8.65 V herein.

Hardware Implementation in the CDU Unit
The hardware in the CDU unit of this study consists of one stepper motor 28-BYJ, one stepper motor driver ULN2003, one window curtain, and one photoresistor TEMT6000.The connected hardware in the CDU unit is shown in Figure 4.
As shown in Figure 4, the stepper motor has four input connections, each of which needs a signal of 12 V to activate the motor.The outputs of the stepper motor are constant steps for opening a window curtain.A GPIO pin of the NodeMCU can only output an "ON" signal of 3.3 V. Therefore, the control of the stepper motor from the NodeMCU requires a stepper motor driver, which has four pairs of input-output connections, with each pair performing a signal voltage conversion from 3.3 V to 12 V.The photoresistor constantly provides analog data for the NodeMCU on the amount of outdoor light.Since the NodeMCU can only use digital data for light illuminance detection, the output of the photoresistor is connected to the ADC pin of the NodeMCU.
the "ON" input signal voltage of the Tube LED 5630 requires 8.65 V. Therefore, the control of each Tube LED from the NodeMCU needs an NIC to perform the voltage conversion from 3.3 V to 8.65 V herein.

Hardware Implementation in the CDU Unit
The hardware in the CDU unit of this study consists of one stepper motor 28-BYJ, one stepper motor driver ULN2003, one window curtain, and one photoresistor TEMT6000.The connected hardware in the CDU unit is shown in Figure 4.As shown in Figure 4, the stepper motor has four input connections, each of which needs a signal of 12 V to activate the motor.The outputs of the stepper motor are constant steps for opening a window curtain.A GPIO pin of the NodeMCU can only output an "ON" signal of 3.3 V. Therefore, the control of the stepper motor from the NodeMCU requires a stepper motor driver, which has four pairs of input-output connections, with each pair performing a signal voltage conversion from 3.3 V to 12 V.The photoresistor constantly provides analog data for the NodeMCU on the amount of outdoor light.Since the NodeMCU can only use digital data for light illuminance detection, the output of the photoresistor is connected to the ADC pin of the NodeMCU.

Hardware Implementation in the TC Unit
The hardware in the TC unit of this study consists of one infrared transmitter KY-005, one air conditioner Ho-562N/HI-56B, and one temp-humidity sensor DHT-22.The connected hardware in the TC unit is shown in Figure 5.The air conditioner is chosen herein because it is among the most common electrical appliances in homes within many countries and can cool down a room fast.

Hardware Implementation in the TC Unit
The hardware in the TC unit of this study consists of one infrared transmitter KY-005, one air conditioner Ho-562N/HI-56B, and one temp-humidity sensor DHT-22.The connected hardware in the TC unit is shown in Figure 5.The air conditioner is chosen herein because it is among the most common electrical appliances in homes within many countries and can cool down a room fast.As shown in Figure 5, the infrared transmitter has one input connection with a GPIO pin of the NodeMCU.Its outputs are PWM signals for commanding the activation and the temperature setting of the air conditioner.The temp-humidity sensor constantly provides the amount of the bedroom temperature for the NodeMCU.In this study, we only use the detected temperature at the starting time of sunrise simulation (i.e., the result of (1)).

Software Implementation in the NodeMCU
The NodeMCU is programmed to connect to the SSTCAA and RTC and control the CLI, CDU, and TC units.In this respect, we write code in the open-source Arduino IDE [39].The source code for connecting the RTC and controlling the CLI, CDU, and TC units is subsequently uploaded to the NodeMCU.

Wi-Fi Connection Setup
The initial task of the NodeMCU is to build its Wi-Fi connectivity.To do so, we incorporate the name and password of the Wi-Fi used on the smartphone and the utiliza- As shown in Figure 5, the infrared transmitter has one input connection with a GPIO pin of the NodeMCU.Its outputs are PWM signals for commanding the activation and the temperature setting of the air conditioner.The temp-humidity sensor constantly provides the amount of the bedroom temperature for the NodeMCU.In this study, we only use the detected temperature at the starting time of sunrise simulation (i.e., the result of (1)).

Software Implementation in the NodeMCU
The NodeMCU is programmed to connect to the SSTCAA and RTC and control the CLI, CDU, and TC units.In this respect, we write code in the open-source Arduino IDE [39].The source code for connecting the RTC and controlling the CLI, CDU, and TC units is subsequently uploaded to the NodeMCU.

Wi-Fi Connection Setup
The initial task of the NodeMCU is to build its Wi-Fi connectivity.To do so, we incorporate the name and password of the Wi-Fi used on the smartphone and the utilization of the ESP8266Wi-Fi library into our source code.Once the code is run in the Arduino IDE, the NodeMCU is connected via Wi-Fi and its IP address is generated.Then, we store the IP address of the NodeMCU in the SSTCAA previously created.This function enables the NodeMCU to receive data from and send acknowledgments to the SSTCAA via Wi-Fi.

RTC-Enabled Task Execution Procedure
The NodeMCU is programmed to access the time from the RTC constantly.Meanwhile, if the alarm is set "On", then the sunrise simulation algorithm for controlling the CLI unit and the temperature control algorithm for controlling the TC unit are enabled when the RTC time matches with the starting time of sunrise simulation given by (1), and the window curtain opening algorithm for controlling the CDU unit is enabled when the RTC time coincides with the alarm time.We summarize the RTC-enabled task execution procedure as the flowchart and pseudocode shown in Figure 6.

Program-Controlled CLI Unit
The sunrise simulation mimics yellow and white sunlight colors.A range of soft yellow lights can gently stimulate the body out of deeper sleep stages, whereas bright white light has alerting properties and can suppress any remaining melatonin production.Thus, the sunrise simulation starts with a gradual yellow light transition from dim until the bedroom is filled with soft bright yellow LED lights in the time span of sunrise of 5-15 min prior to the wakeup time.Henceforth, it disconnects the bright yellow LED light and turns on the bright white LED light.The white LED light stays on until the user switches it off.
To conduct the sunrise simulation, we control the CLI unit using the PWM technique.In this regard, the NodeMCU is programmed in the following way to send PWM signals via PWM pins to control the yellow and white LED lights.

•
Based on the default 8-bit time period of the PWM signal of the NodeMCU, the range of yellow lights is partitioned into 0-255 levels.Given the time span of sunrise (min), the time duration of each yellow light level is given by Time duration o f each yellow light level (ms) = Time span o f sunrise (min) × 60 × 1000 255 . ( The duty cycle of the PWM signal (i.e., the "ON" time percentage) for the ith yellow light level, i = 0, 1, . . ., 255, is given by The value of each duty cycle in (3) holds for the time duration in (2).After the time duration of the 255th light level expires, the yellow light is turned off as no PWM signal is generated.
As soon as the yellow LED light is switched off, the white light level is set as 255, which implies the corresponding duty cycle of the PWM signal is 100.The value of the light level holds until the user issues an "OFF"command to the NodeMCU via the smartphone.The overall yellow and white LED light levels are illustrated in Figure 7.
Accordingly, the sunrise simulation is carried out as follows.The yellow LED light is turned on at the time given by (1).The intensity of the yellow light is gradually increased based on (2) and (3) until it reaches the maximum at the alarm time.The white light is turned on when the yellow light is turned off immediately right after the alarm time.We summarize the sunrise simulation algorithm as the flowchart and pseudocode shown in Figure 8. duration of the 255 th light level expires, the yellow light is turned off as no PWM sign is generated.
As soon as the yellow LED light is switched off, the white light level is set as 25 which implies the corresponding duty cycle of the PWM signal is 100.The value of t light level holds until the user issues an "OFF"command to the NodeMCU via t smartphone.The overall yellow and white LED light levels are illustrated in Figure 7. Accordingly, the sunrise simulation is carried out as follows.The yellow LED light turned on at the time given by ( 1).The intensity of the yellow light is gradually increas based on ( 2) and (3) until it reaches the maximum at the alarm time.The white light turned on when the yellow light is turned off immediately right after the alarm time.W

Program-Controlled CDU Unit
To utilize natural lights as additional assistance for morning awakenings, we control the stepper motor in the CDU unit.Instead of employing the sophisticated control strategy in [40], the NodeMCU is programmed in the following way:

•
If the status of Open Curtain is "ON", and the detected outdoor illuminance received from the ADC pin exceeds a predefined threshold at the alarm time, then the NodeMCU issues signals via four GPIO pins to control the steps of the stepper motor.Specifically, the stepper motor driver receives four pulses sequentially in each periodic interval (i.e., 16ms), as shown in Figure 9, each of which holds for 4 ms and is sent from a distinct GPIO pin of the NodeMCU.The total number of motor steps (or periodic intervals) is predefined for fully opening the window curtain.
Based on the abovementioned operations of stepper motor control and outdoor light detection, we summarize the window curtain opening algorithm as the flowchart and pseudocode shown in Figure 10.

Program-Controlled TC Unit
To lower the bedroom temperature, the NodeMCU is programmed in the following way:

•
If the status of Air Conditioner is set "ON", then we get the ambient temperature from the temp-humidity sensor denoted as "Detected temp".Then, a desired temperature denoted as "Desired temp" is the result of subtraction of a prescribed degree of temperature drop denoted as "Degree of temp drop" from "Detected temp", namely, Next, the air conditioner is activated and associated with the desired temperature setting "Desired temp" using an infrared remote control.
Based on the abovementioned operations, we summarize the temperature control algorithm as the flowchart and pseudocode shown in Figure 11.
summarize the sunrise simulation algorithm as the flowchart and pseudocode shown in Figure 8.

Program-Controlled CDU Unit
To utilize natural lights as additional assistance for morning awakenings, we control the stepper motor in the CDU unit.Instead of employing the sophisticated control strategy in [40], the NodeMCU is programmed in the following way:  If the status of Open Curtain is "ON", and the detected outdoor illuminance received from the ADC pin exceeds a predefined threshold at the alarm time, then the NodeMCU issues signals via four GPIO pins to control the steps of the stepper motor.Specifically, the stepper motor driver receives four pulses sequentially in each periodic interval (i.e., 16ms), as shown in Figure 9, each of which holds for 4 ms and is sent from a distinct GPIO pin of the NodeMCU.The total number of motor steps (or periodic intervals) is predefined for fully opening the window curtain.sent from a distinct GPIO pin of the NodeMCU.The total number of motor steps (or periodic intervals) is predefined for fully opening the window curtain.

Program-Controlled TC Unit
To lower the bedroom temperature, the NodeMCU is programmed in the following way:  If the status of Air Conditioner is set "ON", then we get the ambient temperature from the temp-humidity sensor denoted as "Detected temp".Then, a desired temperature denoted as "Desired temp" is the result of subtraction of a prescribed degree of temperature drop denoted as "Degree of temp drop" from "Detected temp", namely,

Desired temp Detected temp Degree of temp drop
Next, the air conditioner is activated and associated with the desired temperature setting "Desired temp" using an infrared remote control.
Based on the abovementioned operations, we summarize the temperature control algorithm as the flowchart and pseudocode shown in Figure 11.

Results
Based on the proposed system development in Section 2, we build the testbed in a laboratory environment shown in Figure 12 for experimental purposes.We demonstrate that the CLI, CDU, and TC units yield desirable performance.

Results
Based on the proposed system development in Section 2, we build the testbed in a laboratory environment shown in Figure 12 for experimental purposes.We demonstrate that the CLI, CDU, and TC units yield desirable performance.

Experiment Setup
We consider the SSTCAA settings listed in Table 1 and illustrate their effects on the sunrise simulation in the CLI unit and the bedroom temperature regulation in the TC unit.These settings and the photoresistor detection output at the alarm time can be used to show their effects on the activation of the curtain opening in the CDU unit.

Experiment Setup
We consider the SSTCAA settings listed in Table 1 and illustrate their effects on the sunrise simulation in the CLI unit and the bedroom temperature regulation in the TC unit.These settings and the photoresistor detection output at the alarm time can be used to show their effects on the activation of the curtain opening in the CDU unit.We have the following arrangement to undertake a quantitative analysis for characterizing the qualitative performance of the CLI, CDU, and TC units.
To stand for a light level in the CLI unit within the time duration given by ( 2), we use its corresponding average current in the Tube LED.To obtain the average current, we connect the negative terminal of the Tube LED to a 1 Ω resistor whose negative terminal is attached to the ground and then measure the voltage of the resistor using the Instek GDS-1072A-U 2-channel digital storage oscilloscope.
To identify the opening of the window curtain in the CDU unit, we use the total number of motor steps that the stepper motor takes.The predefined total number of motor steps that the stepper motor can fully open the window curtain is 1517.

Performance of the CLI Unit
For Case A in Table 1, the sunrise simulation in the CLI unit is properly conducted.Figure 13 shows the quantitative data of the CLI unit for Case A. The average current in the Tube LED (yellow light) in Figure 13a increases linearly starting at 5:50 (i.e., starting time of the sunrise simulation) until 6:00.Moreover, the average current in the Tube LED (white light) in Figure 13b makes an abrupt change from zero to the maximum at 6:00.The outcome in Figure 13a coincides with the observation that the Tube LED (yellow light) yields a gradual increment of light levels from dim to bright during the 10-min time span of sunrise.In addition, the result in Figure 13b matches with the phenomenon that the white LED light switches on at 6:00 as soon as the yellow LED light is turned off.For Case B in Table 1, the sunrise simulation in the CLI unit is adequately performed.Figure 14 quantifies the results for Case B, which are similar to those for Case A except that the yellow light level begins at 5:45.The numerical results in Figure 14 and quantitative observations are consistent.For Case B in Table 1, the sunrise simulation in the CLI unit is adequately performed.Figure 14 quantifies the results for Case B, which are similar to those for Case A except that the yellow light level begins at 5:45.The numerical results in Figure 14 and quantitative observations are consistent.For Case B in Table 1, the sunrise simulation in the CLI unit is adequately performed.Figure 14 quantifies the results for Case B, which are similar to those for Case A except that the yellow light level begins at 5:45.The numerical results in Figure 14  For Case C in Table 1, the sunrise simulation in the CLI unit is disabled because Alarm is set as "OFF".So, no average currents exist in the two Tube LED lights.This outcome agrees with the observation that when the alarm is set as "OFF," it overrides the activation of the two Tube LED lights.For Case C in Table 1, the sunrise simulation in the CLI unit is disabled because Alarm is set as "OFF".So, no average currents exist in the two Tube LED lights.This outcome agrees with the observation that when the alarm is set as "OFF," it overrides the activation of the two Tube LED lights.
Accordingly, the quantitative outcomes and the qualitative observations of the CLI unit are consistent, which ensures that the sunrise simulation performs reliably and satisfactorily.

Performance of the CDU Unit
Because Alarm and Open Curtain in Case A are set as "ON", the activation of the curtain opening in the CDU unit mainly relies on whether the photoresistor detection output at the alarm time exceeds the threshold.Thus, for Case A in Table 1, we consider the photoresistor outputs shown in Figure 15, in which one exceeds the threshold, and the other is below the threshold at the alarm time of 6:00.Accordingly, the quantitative outcomes and the qualitative observations of the CLI unit are consistent, which ensures that the sunrise simulation performs reliably and satisfactorily.

Performance of the CDU Unit
Because Alarm and Open Curtain in Case A are set as "ON," the activation of the curtain opening in the CDU unit mainly relies on whether the photoresistor detection output at the alarm time exceeds the threshold.Thus, for Case A in Table 1, we consider the photoresistor outputs shown in Figure 15, in which one exceeds the threshold, and the other is below the threshold at the alarm time of 6:00. Figure 16 shows the numerical data of the stepper motor in the CDU unit in Case A along with the result presented in Figure 15. Figure 16a indicates that the stepper motor can operate at 6:00 until the total number of motor steps reaches the predefined value of 1517.This outcome agrees with the observation that the window curtain starts opening at Figure 16 shows the numerical data of the stepper motor in the CDU unit in Case A along with the result presented in Figure 15. Figure 16a indicates that the stepper motor can operate at 6:00 until the total number of motor steps reaches the predefined value of 1517.This outcome agrees with the observation that the window curtain starts opening at 6:00 until it is fully opened.Meanwhile, Figure 16b shows that the stepper motor is not activated at 6:00.This outcome coincides with the phenomenon that the window curtain remains closed.Regardless of the photoresistor outputs, the window curtain remains closed for Cases B and C in Table 1 because Open Curtain in Case B and Alarm in Case C are set as "OFF".To quantify that observation, we consider the photoresistor outputs shown in Figure 17 in which both exceed the threshold at the alarm time of 6:00.
No numerical data of the stepper motor in the CDU unit can be obtained for Cases B and C along with the results presented in Figure 17.It indicates that the stepper motor is not activated even though the photoresistor outputs are above the threshold at 6:00.This outcome coincides with the phenomenon that the window curtain remains closed throughout for Cases B and C.
Accordingly, the numerical outcomes and the qualitative observations of the CDU unit are consistent.Moreover, they confirm that the opening of the window curtain in the CDU unit is reliable.

Performance of the TC Unit
In the following, we show the experimental results of the TC unit based on Table 1 and verify their validity.
Because the status of Air Conditioner in Case A is set as "OFF", the bedroom temperature detected by the temp-humidity sensor almost stays unchanged, as shown in Figure 18.
Since the status of Alarm and Air Conditioner in Case B is set as "ON", the air conditioner turns on to lower 3 • C from the bedroom temperature at the starting time of sunrise.The result is depicted in Figure 19.It shows the TC unit operates reliably.
Because the status of Alarm for Case C is set as "OFF", the TC unit is not activated.This yields a result with a trend similar to that in Figure 18.So, the result is omitted.
The outcomes shown in Figures 18 and 19 have confirmed that the operations of the TC unit are valid.
Regardless of the photoresistor outputs, the window curtain remains closed for Cases B and C in Table 1 because Open Curtain in Case B and Alarm in Case C are set as "OFF."To quantify that observation, we consider the photoresistor shown in Figure 17 in which both exceed the threshold at the alarm time of 6:00.not activated even though the photoresistor outputs are above the threshold at 6:00.This outcome coincides with the phenomenon that the window curtain remains closed throughout for Cases B and C. Accordingly, the numerical outcomes and the qualitative observations of the CDU unit are consistent.Moreover, they confirm that the opening of the window curtain in the CDU unit is reliable.

Performance of the TC Unit
In the following, we show the experimental results of the TC unit based on Table 1 and verify their validity.
Because the status of Air Conditioner in Case A is set as "OFF," the bedroom temperature detected by the temp-humidity sensor almost stays unchanged, as shown in Figure 18.Since the status of Alarm and Air Conditioner in Case B is set as "ON", the air conditioner turns on to lower 3 °C from the bedroom temperature at the starting time of sunrise.The result is depicted in Figure 19.It shows the TC unit operates reliably.not activated even though the photoresistor outputs are above the threshold at 6:00.This outcome coincides with the phenomenon that the window curtain remains closed throughout for Cases B and C. Accordingly, the numerical outcomes and the qualitative observations of the CDU unit are consistent.Moreover, they confirm that the opening of the window curtain in the CDU unit is reliable.

Performance of the TC Unit
In the following, we show the experimental results of the TC unit based on Table 1 and verify their validity.
Because the status of Air Conditioner in Case A is set as "OFF," the bedroom temperature detected by the temp-humidity sensor almost stays unchanged, as shown in Figure 18.Since the status of Alarm and Air Conditioner in Case B is set as "ON", the air conditioner turns on to lower 3 °C from the bedroom temperature at the starting time of sunrise.The result is depicted in Figure 19.It shows the TC unit operates reliably.Because the status of Alarm for Case C is set as "OFF", the TC unit is not activated.This yields a result with a trend similar to that in Figure 18.So, the result is omitted.1.

Discussions
In this paper, we develop an inexpensive IoT-based bedroom lighting and temperature control system based on known scientific findings confirming the effectiveness of lights and temperatures on human wakefulness.The proposed system performs a dawn simulation, conditionally conducts daylight utilization, and optionally undertakes bedroom temperature regulation.The lower the temperature is, the higher the humidity needs to be.So, the temperature control in our proposed system also induces the humidity change in the bedroom.Such a humidity difference may awaken a sleeper tenderly.Furthermore, a built-in function of the smartphone can be set up and activated at the alarm time to play soothing music to lessen the stress level of the user after an awakening.To ensure the system can carry out required tasks timely and properly, we build a testbed for conducting experiments.Experiments demonstrate that the qualitative and quantitative results of the system performance are consistent, and the proposed system can reliably meet our design demands satisfactorily.This verifies the correctness of our hardware and software design.On the whole, it is promising that the proposed system can assist in gentle awakenings and sleep inertia mitigation.
Because the proposed system is developed based on the smartphone and IoT technology, it is found that we can conveniently expand and customize the system functions via DIY software design.This way incurs no additional cost.Like the proposed system, the updated system is economically viable and embodies features of sustainability.For instance, we can incorporate the Google speech recognizer in the MIT App Inventor into the SSTCAA.In this way, the user can input data into the SSTCAA through their voice.We can also design an app to control the ON/OFF and brightness level of yellow and white lights and the ON/OFF and opening position of the window curtain.
We can also conveniently adjust the scalability of the proposed system.For example, we can connect additional electronic units to the proposed system for controlling bedroom security.The proposed system can also be suitably integrated with the cyber-physical system (CPS) for residential energy management discussed in [41].This integration can be achieved because the IoT and CPS are closely related.In future works, we will focus on integrating more essential components into the proposed system for overcoming sleep inertia and strengthening the environmental feature of sustainability associated with the system.For instance, as indicated in [11], the quality control of the human sleep-wake cycle is a strategy for alleviating sleep inertia.In this regard, Takemura et al. [42] suggested that we can conduct a gradual transition of dimming the light starting at a sleep preparation time until bedtime.In this regard, the proposed system may carry out this task via the incorporation of a designed sleep-mode app into our system.Based on the insights in [25], it is hopeful that our proposed system may be enhanced in the environmental aspect of sustainability via the incorporation of big data analytics and artificial intelligence.More specifically, the user needs to be allowed to regularly evaluate the data in the SSTCAA database (including SSTCAA data, sensor-based temperature information, and daily system usage time collected over a long period of time) based on the satisfaction of their performance.It is noted that the daily system operation time is closely related to energy utilization.To achieve a tradeoff between the satisfaction of user performance and the reduction of energy consumption, advanced techniques related to statistical analysis and artificial intelligence may be employed in the system to yield appropriate parameter values for the SSTCAA setting based on those evaluations on big data.

Figure 1 .
Figure 1.Block diagram of the proposed system framework.

Figure 1 .
Figure 1.Block diagram of the proposed system framework.
Starting time o f sunrise simulation = Alarm Time − Time span o f sunrise.(1)

Figure 2 .
Figure 2. Display of the SSTCAA.We use visual programming items on the web editor for the functional development of the SSTCAA.The functional tasks of the SSTCAA are listed as follows. Store the data displayed on the SSTCAA and internet protocol (IP) address of the NodeMCU. Calculate the starting time of the sunrise simulation as Starting time of sunrise simulation Alarm Time Time span of sunrise = − .(1)

Figure 3 .
Figure 3. Hardware connection in the CLI unit.

Figure 3 .
Figure 3. Hardware connection in the CLI unit.

Figure 4 .
Figure 4. Hardware connection in the CDU unit.

Figure 4 .
Figure 4. Hardware connection in the CDU unit.

Figure 5 .
Figure 5. Hardware connection in the TC unit.

Figure 5 .
Figure 5. Hardware connection in the TC unit.

Figure 7 .
Figure 7. Yellow and white LED light levels in the CLI unit.

Figure 7 .
Figure 7. Yellow and white LED light levels in the CLI unit.

Figure 9 .Figure 9 .
Figure 9. Four sequential pulse inputs of the stepper motor driver in each periodic interval.

Figure 9 .Figure 10 .Figure 10 .
Figure 9. Four sequential pulse inputs of the stepper motor driver in each periodic interval.

Figure 12 .
Figure 12.A testbed based on the proposed system development.

Figure 12 .
Figure 12.A testbed based on the proposed system development.

Sustainability 2022 ,Figure 13 .
Figure 13.Numerical data of the CLI unit for Case A in Table 1.(a) The average current in the Tube LED (yellow light); (b) the average current in the Tube LED (white light).

Figure 13 .
Figure 13.Numerical data of the CLI unit for Case A in Table 1.(a) The average current in the Tube LED (yellow light); (b) the average current in the Tube LED (white light).
LED (yellow light); (b) the average current in the Tube LED (white light).

Figure 14 .
Figure 14.Numerical data of the CLI unit for Case B in Table 1.(a) The average current in the Tube LED (yellow light); (b) the average current in the Tube LED (white light).

Figure 14 .
Figure 14.Numerical data of the CLI unit for Case B in Table 1.(a) The average current in the Tube LED (yellow light); (b) the average current in the Tube LED (white light).

Figure 15 .
Figure 15.The detection outputs of the photoresistor and the threshold for Case A in Table 1.(a)The detection output is above the threshold at 6:00; (b) the detection output is below the threshold at 6:00.

Figure 16 .Figure 17 .Figure 16 .
Figure16.Numerical data of the CDU unit for Case A in Table1together with the detection results in Figure15.(a) The total number of motor steps for Case A along with the result in Figure15a; (b) the total number of motor steps for Case A along with the result in Figure15b.Regardless of the photoresistor outputs, the window curtain remains closed for Cases B and C in Table1because Open Curtain in Case B and Alarm in Case C are set as "OFF."quantify that observation, we consider the photoresistor outputs shown in Figure17in which both exceed the threshold at the alarm time of 6:00.

Figure 17 .Figure 17 .
Figure 17.The detection outputs of the photoresistor and the threshold for Cases B and C in Table 1.(a) The detection output for Case B exceeds the threshold at 6:00; (b) the detection output for Case C is above the threshold at 6:00.No numerical data of the stepper motor in the CDU unit can be obtained for Cases B and C along with the results presented in Figure17.It indicates that the stepper motor is

Figure 18 .
Figure18.The bedroom temperature for Case A in Table1.

Figure 19 .
Figure19.The bedroom temperature for Case B in Table1.

Figure 18 .
Figure18.The bedroom temperature for Case A in Table1.

Figure 18 .
Figure18.The bedroom temperature for Case A in Table1.

Figure 19 .
Figure 19.The bedroom temperature for Case B in Table 1.

Figure 19 .
Figure 19.The bedroom temperature for Case B in Table 1.

Table 1 .
Three cases of SSTCAA settings for the experiments.

Table 1 .
Three cases of SSTCAA settings for the experiments.