## 4 LOKA: LOw Power Consumption Algorithm
In our prototype we have integrated a HC-SR501 to detect motion, a DHT11 sensor to obtain the temperature and humidity and a Light Dependent Resistor (LDR) to measure luminosity. The HC-SR501 is wired to the WAKE UP pin of the LPC824 with the objective of generating an event in LOKA when movement is detected. In reference to DHT11, it has is own digital communication protocol, so, it is wired to a digital IO of the LPC824 taking into account that the wire needs a pull-up resistor, R9, to ensure that the signal is inside a valid logic level. The LDR is included into the voltage divider. The LDR chosen is the PDV-P8103. The result of the voltage divider is passed to the ADC input of the microcontroller. ### Energy Measure

The objective of this section is to evaluate the impact of LOKA in the energy consumption of a sensor mote. To do this, we have measured the energy consumption of our two prototype modules for a certain period of time in which both motes periodically send the sensors data to the collector mote (with and without LOKA). We have considered three different ways to measure the energy consumption contemplated in the state of art:

Figure 5: Charger and supply circuits. * By charging and discharging capacitors. Through the charge and discharge cycle of capacitors putting them between the supply and the prototype module as [PERSON] et al. [39] suggested. It was disapproved because it is an empirical solution that depends on the current leakages of the capacitors. * By ammeter. Another possibility is to measure the current consumption periodically to know the energy consumption. However, an ammeter is not enough for our propose because the time between measures is too long and the burden voltage of common ammeters is very high, with the subsequent loss of resolution and accuracy. * By shunt resistor and voltage amplifier. The last possibility is to measure the current consumption periodically jointing a shunt resistor and a low noise _chopper_ amplifier. This is the solution that we have chosen because the time between measures and the precision of the measures are higher than with the previous solutions. To implement the selected solution, we have used the commercial \(\upmu\)Current device as [PERSON] et al. [40] suggest. We have combined it with the ADC of the LPC824 microcontroller to measure the energy consumption. Technically, the \(\upmu\)Current device incorporates the shunt resistor and the _chopper_ amplifier. On the one hand, the most important characteristics of \(\upmu\)Current are mA range of measure, 0.2% on \(\upmu\)A measures accuracy and 0.5% on mA measure accuracy as well as 100 pA of resolution. On the other hand, the most important characteristics of the ADC of the LPC824 are 95 KSPS (Kilo Samples Per Second) proved frequency sample and 0.366 mV LSB minimum. The experiments with our prototype motes were carried out programing the WKT with different times (periodical transmit data interval), without movement (so wake up pin IRQ handle will never be activated), and with sufficient power battery so BOD IRQ handle will never be activated. In this way, the current of a sensor mote with LOKA and without LOKA is measured periodically. The Equation (1) calculates the energy assuming that the power supply (\(E\)) is constant and the time between the measures of the current (\(T\)) is periodic. If the time between measures is small enough, we can discretize the energy consumption as appear in the right term of the Equation (1). \[W[J]=\int_{1}^{2}Pdt=\int_{1}^{2}E(t)\cdot i(t)dt=E\cdot T\cdot\sum_{j=1}^{N}I _{j} \tag{1}\]

The Equation (2) corresponds to the ADC-LPC824 input where \(n\) is 12, the number of bits of the ADC and _result_ is the output value of the ADC. We set the Vrefp and the Vrefn to 2.4 V and 0.9 V respectively. These values enable the maximum sensibility for the ADC-LPC824.