## 4 Implementation
### IoT Nodes
#### 4.1.1 Actuator Nodes  
Although in the proposed HAS architecture it is possible to use any kind of actuator, in the implementation presented in this article, only LEDs and relays are included. Relays are important in an HAS, since they are able to switch off and on electrical appliances on demand (or automatically) through messages received from the corresponding MQTT topic. Thus, during the implementation, it was necessary to determine the number of relays required by each actuator node, taking into account that each code could manage up to 11 relays (i.e., the maximum number of GPIOs available in a NodeMCU), although an external multiplexer could be added to include more. In addition to relays, two sensors were embedded into every actuator node in order to monitor appliances. On the one hand, a current sensor (ACS712) that tolerates up to 5 A was used, which is enough to monitor appliances that require up to 1200 W. On the other hand, a temperature sensor was added to detect overheating and then prevent the current from flowing. The selected temperature  
Figure 4: Implemented communications architecture. sensor was an LM35, whose main characteristics are shown in Table 7 together with the ones related to the ACS712. Note that both the ACS712 and the LM35 are analog and a NodeMCU only has a single Analog-to-Digital Converter (ADC) pin, so it is necessary to select each signal independently through a multiplexer to obtain its value. In addition, note that, when using an ACS712, the ADC actually returns an integer value between 0 and 1023 that represents a voltage that has to be processed to obtain the consumed power. For such a conversion, the value collected form the ADC is first transformed into a decimal voltage by multiplying it by 3.22 (this specific value was determined by calibrating the sensor manually with the help of a high-precision voltmeter). The value obtained represents the peak voltage. To calculate the effective current, the following formula has to be applied:  
\[I_{ef}=0.707*\frac{V_{ADC}-\alpha}{sensitivity},\]  
where \(V_{ADC}\) is the voltage read by the ADC, \(\alpha\) represents the voltage read when there is no current flowing, and _sensitivity_ is the sensitivity of the sensor according to the manufacturer. After multiple measurements, it was determined that \(\alpha\) was 2.49 V, while _sensitivity_ was 185 mV/A according to the manufacturer datasheet. Once the effective current is calculated, it is only necessary to multiply its value by the contracted power (for instance, in Europe, 230 V) to obtain the consumed power. Figure 5 shows the schematic of an actuator node, which contains:  
* An external AC-DC converter. * A NodeMCU. * Two relays. * An analog multiplexer (HCF4066 BE) for choosing between the sensors that measure current (ACS172) and temperature (LM35). Note that, for the sake of clarity, instead of representing the whole integrated circuit, three of its four internal multiplexers are depicted in the schematic. * External devices connected to the relays and to the current sensors. \begin{table}
\begin{tabular}{l c c c c c c c} \hline \hline
**Sensor** & **Identifier** & **Output** & **Operation Range** & **Precision** & **Input Voltage Range** & **Consumption** & **Price** \\ \hline Temperature & LM35 & Analog & \(-\)55, +150 \({}^{\circ}\)C & \(\pm\)0.5 \({}^{\circ}\)C & 4-30 V & 114 \(\mu\)A & \$3 \\ Temperature & TMP36 & Analog & \(-\)40, +125 \({}^{\circ}\)C & \(\pm\)1-2 \({}^{\circ}\)C & 2.7–5.5 V & 40 \(\mu\)A & \$1.50 \\ Humidity & HHH-5030 & Analog & 0–100\% & \(\pm\)3\% & 2.7–5.5 V & 200 \(\mu\)A & \$10 \\ Luminosity & LDR & Analog & 1–1000 lx & - & max. 100 V & max. 75 mA & \$0.5 \\ Temperature & \multirow{2}{*}{DHT11} & \multirow{2}{*}{PWM} & \multirow{2}{*}{0–50 \({}^{\circ}\)C / 20–80\%} & \(\pm\) 2 \({}^{\circ}\)C / \(\pm\)5\% & 3–5 V & 200 \(\mu\)A & \$5 \\ \cline{1-1} \cline{5-5} Motion & & & & & & & \\ \cline{1-1} \cline{5-5} Current & ACS712 & Analog & Up to 30 A & \(\pm\)1.5\% & 4-5-55 V & 10 mA & \$3–55 \\ \hline \hline \end{tabular}
\end{table}