Automatic Controller for Teleoperated Switching between Multiple Energy Sources in a Residential Building Nanogrid

Erratic power supply from the utility grid has grave effect of the development of several countries. In a bid to overcome this challenge, many residential buildings have become electrically self-sustaining by the integration of various backup power supply source. Yet the act of transition from one source to another has remained a manual task that tends to discourage users from going through the rigour. Internal combustion engine AC generators and batteries have been found to be the most common backup options. An automatic transition system that gives user the flexibility of monitoring and controlling resources remotely from a mobile phone application is thus presented in this paper. The microcontroller-based system monitors the status of the energy resources and protects the building against undervoltage or overvoltage conditions. Based on the state of charge of the battery and the fuel level in the generator, the system activates the appropriate alternative backup source in the event of an outage form the grid supply. This system affords users a new level of comfort and reliability of power supply, as in the automatic mode, the users are guaranteed power supply with minimal downtime, except when all resources are unavailable.


Introduction
In most developing countries, the problem of inadequate electricity supply is still very significant. More than 600 million people in Africa live without electricity, including more than 80 percent of those residing in rural areas. (Blimpo and Cosgrove-Davies, 2019) In regions such as sub-Saharan region of Africa, rural electrification is about 14% (Trotter, 2016). This is much significantly lower than that of any other region in the world. Electrification is crucial for economic development as its impacts the education, income, health, security and social well-being of the society (Amadi, 2015). Household electrification is estimated to result in an average rise of around 7% in school enrolment, 25% in employment and 30% in income. (World Bank, 2019) Microgrids and nanogrids have been identified as potential solutions for providing better electricity supply for region with inadequate service by the traditional municipal electricity grid. The term nanogrid has been suggested for defining a small microgrid, for instance a single house (Nömm, Rönnberg and Bollen, 2018). For regions with smart grids and smart building facilities, several home energy management systems have been proposed, with dynamic pricing schemes, Load scheduling and other demand response technologies put in place to stabilise the grid. However, in regions with erratic electricity supply from the utility grid, residential buildings are forced to run as nanogrids, operating in either grid connected mode or in islanded mode (Member et al., 2016).
Automatic transfer switch (ATS) serves as an interface between utility power and secondary sources in order to maintain a continuous supply of electricity to the load with minimal interruption of supply. Critical loads which typically require closed transition switching with switching time less than 500ms classically have their own designated small backup systems with static transfer switches (Castenschiold, no date). Static Transfer Switches have selective gating strategy which can operate at different operating conditions while optimizing the transfertime, making then suitable for UPS systems (Mokhtari, Dewan and Iravani, 2000). A number of Automatic transfer switches have been developed, but these are seldom IoT enabled. Thus, typically require the physical presence of an operator to manual start/stop the alternative energy source.
An Automatic Transfer Switch (ATS) using Programmable Logic Controller (PLC) suitable for the manufacturing industry and large commercial applications is demonstrated in (Ashour, 2004). A description of a three-phase automatic change over with generator control mechanism is given in (Ezema et al., 2012). This design considers a stand-by type generator which is simply toggled on or off by a simple switching action. For a singlephase implementation of an automatic change over with generator control mechanism, the authors in (Eshovo and Salawu, 2017) showcase an electronics based control, while (Agbetuyi et al., 2011) present a microcontroller based transition system. In the simulation environment, (Amuzuvi and Addo, 2015) present a cost-effective approach to implementing a microcontroller-based automatic transfer switching system for a standby electric generator with under voltage, overvoltage and over current protection.
Many modern residential buildings possess multiple energy sources being combined appropriately, to meet the load demand, based on a couple of factors particularly availability of natural renewable energy resources. As residential buildings are fast becoming smart homes, with IoT enabled devices easing the control and monitoring of loads in the building, it is essential to also consider the control and monitoring of the energy supply system.

Methodology
This paper presents a system for remotely monitoring and controlling the changeover process of an automatic transition switching system for buildings with multiple energy supply sources. The test case considers the possibility of having a building with public utility electricity supply, a standby internal combustion engine (ICE) AC generator and inverter-battery supply. Such network topology common in developing countries with erratic utility power supply is shown in Figure 1. A single-phase AC utility grid source is considered for the building mains supply. The main supply experiences regular unpredictable outages, thus backup supply from an energy storage system is introduced, while a fossil fuel based AC generator is required for further backup. The battery is charged by a charge controller embedded in an off-the-self bidirectional inverter. The DC voltage from the battery is however used to power the Microcontroller, sensors, relay drivers and other low voltage signal electronic components in the system. Two DC voltage signal levels are maintained in the system using voltage regulators (LM7805) for 5 V DC and (LM7812) for 12 V DC operations (Fairchild Semiconductor, 2005).

AC Bus
Figure 1: Nanogrid topology for test system The ability to monitor the status of the various sources remotely from a mobile device with the required application software is an important feature. Particularly because smart mobile phones have become a more affordable ubiquitous part of our modern society and the advent of android operating system has made customised application development easily accessible.
Transition between three electrical power sources without the need of manual operation of changeover switching gears would most definitely require an array of sensors, actuators, communication devices and control system. The system thus consists of four main subsystems: 1. The automatic transfer switch mechanism, to change contacts from one source to another. 2. The system monitoring unit, equipped with appropriate sensors to measure the load and source status. 3. The generator start-up and shutdown mechanism to remotely energize or deenergize the ICE generator. 4. The control and communication unit to monitor the state of the various sources constantly and initiate the required triggers to enable power supply to the load with minimum downtime. A suitable communication system is integrated into the system to permit remote operation of the system from an android mobile application. A block diagram showing the interconnection of these various subsystems is shown in Figure 2.  Figure 2: Block diagram on the complete automatic transition system for a three source nanogrid with remote monitoring and control.

The Automatic Transfer Switch Mechanism
The changeover circuit basically comprises of a step-down transformer, diodes, voltage regulator and relays. The automatic changeover circuit is designed such that when there is presence of electricity supply from the utility mains power supply, the AC voltage is stepped down by the transformer and then converted to DC with a fullbridge diode rectifier. The expected rippled from the rectifier stage filtered with a capacitor, C1 and further regulated to the required relay coil rated voltage by the voltage regulator. The circuit diagram of the automatic changeover system designed is shown in Figure 3. The changeover mechanism employs a coupled relay switching assembly to transfer its operation between the utility MAINS to the local alternative (ALT) backup supply. The ALT live and the ALT neutral are connected in a Normally Close (NC) configuration while the MAINS live and the MAINS neutral are connected in Normally Open (NO) configuration of the relays RL1 and RL2 respectively. When there is mains power supply from the public utility supply system, the relays will switch to the NO contacts thereby supplying the load form the MAINS line. When a power failure from the public utility supply system occurs, the relay switches from NO to NC contacts making the ALT inputs to be active supply for the load.
In order to control the enabling of the changeover process by the microcontroller, a thyristor (U2) is integrated along the forward path of the DC supply to the relays. By design, the thyristor would be gated ON by a pulse signal sent from the microcontroller when the power from the MAINS is sensed to be within the safety limits. As long as there is sufficiently high voltage supply from the voltage regulator, the thyristor would remain latched ON. In order to switch off the thyristor, in the event of an under voltage or over voltage from the mains supply, an IGBT (Q1) is connected in parallel to the thyristor. When a disable pulse is sent from the microcontroller, the IGBT gates a shunt path for current and the thyristor trips OFF. Consequently, the relays return to the NO position.
The DC power supply is designed considering the voltage requirements for the relays which operate at 12V DC, while most of the other sensing and control components operate on 5V DC. Hence, a transformer of turns ratio 20:1 is required to stepdown an expected supply voltage of 240V AC to 12V AC RMS, according to eqn. 1. After undergoing rectification (using 2W005G), the peak value of the voltage approx. 17V DC (eqn. 3) is fed to the voltage regulator (LM7812) to yield a 12V DC output.

→
( 1 ) , √2 ( 2 ) 12 √2 16.9705 17 ( 3 ) Where, and are number of primary and secondary transformer coil windings respectively, and are primary and secondary transformer coil RMS voltages respectively, and is the peak secondary voltage. From the datasheet (2W005G (Fairchild Semiconductor, 1999)), the maximum forward voltage drop, , for the bridge rectifier is 1.1V. Thus, for the actual peak voltage value, : ( 5 ) 16.9705 1.1 15.8705 ( 6 ) Assuming a ripple voltage of 20%, the change in peak voltage value, over the discharge period, 3.1741 ( 7 ) Total current consumption for this design is not expected to exceed 600mA Hence the value of the filter capacitor is obtained thus: .

1890
( 9 ) To provide a safety margin, the capacitor value chosen is more than the calculated value such that the nearest available capacitor value of 2,200µF is used as the filter capacitor, .

The System Monitoring Unit
Various parameters are monitored at different parts of the system. Table 1 gives a summary of the parameters measured from each device. The voltage measurement circuitry for the mains and generator differ from that of the battery, as they are AC sources while the battery is a DC source. For the AC sources, a 240V/6V stepdown transformer is used, as shown in Figure 4a. A simple voltage divider circuit with resistors and of ratio 4:1 produces about 1.5V sinusoidal signal. In order for the full sinusoidal signal to be observed within the 0V -5V permitted signal boundary of the analogue input pin of the microcontroller, an offset of 2.5V DC is applied. Given a of 5V and typical diode voltage drop, of 0.7, the resistors and are chosen as 22.5kohm and 40kohm respectively, according with equations 10 and 11.

1
( 1 1 ) Where, is the desired offset voltage, is the +5V reference voltage and is the forward voltage drop across the diode.
For the DC Source (battery), a similar voltage divider circuit is used to adjust the voltage to a proportionally lower value suitable for the microcontroller input. High frequency noise signals are eliminated with a filter circuit capacitor, . While a Zener diode with a reverse breakdown voltage of 5.1V serves as a protection component to ensure that the voltage signal to the microcontroller does not significantly exceed the 5V limit.

Temperature Sensing
The LM35 temperature sensor, which has a temperature measurement range of -55℃ to 150℃ is a suitable choice for the application. This low-cost precision Integrated Circuit temperature sensor gives an output voltage proportional to the centigrade temperature scale with zero offset voltage (Texas Instruments, 2017). The battery bank is typically going to be indoors with a room temperature of between 24℃ and 38℃ and the generator outdoors with a maximum expected body temperature of 120℃. With a sensitivity of 10 /℃ , at the maximum rated temperature of 150℃ the maximum output voltage ( ) is 1.5V, in line with equation 12. In order to enhance the accuracy of the readings from this small signal output device, an instrumentation amplifier with precision voltage reference (INA125) is incorporated as an interface between the sensor and the microcontroller with a reference voltage ( ) of 5V, as shown in Figure 5. The amplifier gives a gain, (from Equation 13), thereby resulting in an analogue input the microcontroller of magnitude, . The temperature reading, from any given output voltage, is thus calculated with equation 14. , ( 1 2 ) ( 1 3 ) ( 1 4 ) Figure 5: Temperature measurement circuit 2.2.3 Level Sensing Due to nature of the fluid (petrol or diesel), a non-contact, nonintrusive, sensing technique like that afforded by an ultrasonic sensor is preferred for this application. The principle of operation of ultrasonic level sensors involves the emission of acoustic pulses in the ultrasonic frequency range and measuring the time it takes the signal to be reflected by an obstacle and received by the source. Although the surface tension of such petrochemical fluids is significantly low, within the short range of measurement, the measurement accuracy of the device is still maintained. The HC-SR04 Ultrasonic sensor has a measurement range of 20mm to 4000mm and an accuracy of 3mm which is sufficient for this non precision application (Cytron Technologies, 2013).
The trigger and echo pins of the ultrasonic sensor are connected to the two digital I/O pins of the microcontroller and the and ground pins connected accordingly. With the sensor attached to the detachable lid of the fuel tank, the level of the fuel is the tank is calculated according to equation 16. The percentage of the fuel left in the tank is therefore given by equation 18.
( 1 5 ) , ( 1 6 ) ℎ ℎ , ( 1 7 ) ∴ , 100 ( 1 8 ) Where, is the Distance of obstacle from the sensor, is the speed of sound wave in air = 344m/s, is the time taken from pulse transmission to receiving the echo, and are the distances of fuel level from the sensor, when the tank is full and empty respectively.
Due to the irregular shapes of most generator tanks, the level measurement does not translate directly to fluid volume in the tank. However, it gives a reasonable estimate, suitable for decision making. It is also observed that the ultrasonic sensor does not give very reliable estimates when the tank is full (i.e. obstacle less than 30mm close to the sensor). This also does not pose a challenge to the required decision making which is more concern with fluid low level states.

Current Sensing
A Hall Effect current sensor feeds the load current to the Microcontroller. The ACS712 ELC-30A sensor is preferred to measure current of the range 30 with an output sensitivity of 66mV/A (Inc Allegro MycroSystems, 2007). For a VCC of 5V the sensor typically gives an output voltage, of about 2.5V in no load (open circuit) condition. This offset voltage ( has to be accounted for in the calibration of the sensor. Hence, the current reading is given by equation 19. ( 1 9 )

Generator Control Unit
A regular electric starting petrol generator will compose of a manual choke, fuel flow valve and a key starting ignition. With little manipulation of the ignition terminals, the two pairs of wire designated to starting and stopping the generator engine can be identified. Consequently, relays connected to severe as switches to complete the circuit between each pair of wires would either start or stop the generator accordingly. The start wires are run through a normally open (NO) relay, while the stop wires are run through a normally closed (NC) relay. Before starting the generator, two procedures are important, the fuel flow valve needs to be open and the choke needs to be moved back and forth according to the state of the generator. The fuel flow valve is replaced with a 12V DC latching solenoid valve. This energy efficient valve maintains an open or closed position after an actuating pulse has been supplied without utilizing any further current. This three-wire valve comprises of two coils wound in opposite directions, with one wire connected to the ground terminal and the other two wires connected to the 12V supply via relays to be energized depending on the desired orientation of the valve.
The choke lever is attached to a push-type linear solenoid actuator. The solenoid is powered via a wire routed through a relay, which is energized from the microcontroller by a relay driver. When the solenoid is activated, the plunger pushes the choke to the generator starting position. The kick starter is then actuated. When the generator engine is up, the relay is deenergized and the solenoid retreats the choke level to the desired generator running position.
When the generator engine is successfully running, a relay is used as a local circuit breaker, which permits the generator to be loaded. All the relays are driven by a relay driver (ULN2003A) which is used as an interface to the microcontroller. The generator start/stop control circuitry is shown in the figure 6.

The Control and Communication Unit
The central control of the automatic transfer and source activation system relies on a microcontroller, programmed to control the several actuators and receive the various sensor inputs. The system is however designed to transmit status information as well as receive instructions and certain setpoint data from a remote user via a mobile phone application. With 12 digital I/O pins, 6 Analogue I/O pins and a couple of useful libraries, the Arduino Uno developmental board based on ATmega328 microcontroller is a suitable choice to this application.
The microcontroller is programmed to operate based on the flowchart in figure 7. The system initialisation takes place at powerup, when the system tries to establish connection with the internet for setpoint data, otherwise default settings are used. Subsequently the sensor inputs are monitored and the required control actions executed by signals sent to the actuators described in the previous sections. The active sources are chosen in a prescribed order of preference, such that in the event of a power outage (or fault) from the mains supply, the backup battery storage system is the next source to be considered for availability and suitability, before the Internal Combustion Engine petrol generator. When the power supply from the mains is restored, the supply voltage is monitored for 30 secs to ensure that it is stable within the acceptable range before the enable pulse is sent to the thyristor to permit the Relays (R1 and R2) to be energised.  Figure 7: Flowchart of main controller action for the source transition process While the voltage of the mains is read directly from the voltage sensing circuit, the state of charge (SoC) of the battery is estimated using the battery terminal voltage measured by the DC voltage sensing circuit, considering the relationships established in (Chen, Fu and Mi, 2013). The estimate of the state of charge is done from the open circuit voltage with the polynomial fitting method (eqn. 21). The open circuit voltage ( ) can be derived from the terminal voltage by the expression in equation 22 (Lee and Lee, 2015). ⋯ ( 2 1 ) ( 2 2 ) Where, is the SoC, ~ are the coefficients obtained by the least square method curve fitting, is the measured terminal voltage, is the discharging current and is the internal resistance of the battery. In order not to go beyond the scope of this current research this simplistic model was adopted, neglecting the effect of temperature and age on the SoC. Also, hypothetical coefficients for the OCV-SOC equation are gotten from (Olaniyan et al., 2018) to serve for the purpose of this experimental implementation.
The control algorithm of the subprocess for activating and deactivating the ICE generator is shown in figure  8. While the generator is on, the measured parameters are continuously monitored and the necessary actions are triggered by the microcontroller. A maximum of 3 attempts at igniting the generator engine are permitted, after which the failure is reported to the user's mobile phone as a notification. ISSN 2222-1727(Paper) ISSN 2222-2871(Online) Vol.11, No.5, 2020 Figure 8: Flowchart for Generator activation and deactivation control The architecture of the Internet of Things communication system configuration is shown in figure 9. The Arduino Uno board is linked to the internet via an ESP8266 Wi-Fi module connected to an internet access point, forming the local unit. A cloud based IoT analytics platform service, ThingSpeak is employed the interface between the local unit and the remote user. The status data from the local unit is sent to a designated channel in ThingSpeak were the data can be retrieved by a permitted user with a custom-built android app. Similarly, data sent over the internet from the Android device can be received by the microcontroller via the IoT platform. A custom android application was built using the Android Studio software.

Results and Discussion
In order to test the performance of the system, a couple of senecios where induced to observe the response of the controller to the status of the multi-source power supply system.
The following scenarios were used to analyse the system response: 1. The Controller was set to manual mode and an outage occurred in the main grid at some point in time (by manually tripping the incoming circuit breaker). 2. The Controller was set to automatic mode, while the SOC of the battery was close to 100% and there is sufficient fuel in the ICE Generator an outage from the main grid occurred. 3. After an hour, the battery SoC is below the tripping threshold, TT. 4. Utility mains power is restored shortly after, for about 30min. 5. Again, there is an outage from the main grid supply, the battery SoC is 30%. 6. The outage has persisted and the ICE has run low on fuel level below the threshold. The resulting system responses observed from the various scenarios are summarised in the Table 2. From the results, it can be observed that in the automatic mode, the system adjusts without any user intervention to ensure that the power supply is restored within the shortest possible time from the available sources. Consequently, there was only extended power outage when the alternative sources and the main grid were all unavailable (Scenario 6), and the authorised user was notified via the android notification system feature of the mobile application. For the overvoltage and undervoltage test, the automatic voltage regulator (AVR) was used to increase or decrease the output voltage of the generator, by rotating the small voltage adjustment screw clockwise or counter clockwise. The generator was automatically deactivated by the microcontroller at both voltage conditions outside the prescribed limit. The overvoltage and undervoltage features could not be tested with the main grid supply, but being the same voltage sensor circuit employed by the generator, the test proved that the feature worked as desired. Screenshots of the android application front end user interface are shown in figures 10 (a, b & c). After preliminary configuration during application installation, the operator is able to navigate from the home page to source specific pages to enable or disable auto mode, input the tripping thresholds and monitor source statuses. With a few seconds varying time delay the application is able to display the status of the devices. This is due to varying network signal strength from the internet service providers (ISPs) and mild cloud service congestions. However, this incidentally does not pose any challenge or threat to the functioning of the system as the real-time protection and actuation circuitry are all resident with the controller in the local unit. a: Home Page b: Generator Controls c: ESS controls Figure 10: Screenshots of Mobile Application monitoring and control interface

Conclusion and future work
This simple cost-effective implementation presents a solution that can be suitably adopted in several residential buildings with multiple energy resources, especially in low income countries with erratic utility power supply, non-smart grids or no sophisticated energy management systems available. The system autonomously responds to possible power outages from the grid by switching over to backup alternative sources. It also gives users the flexibility of monitoring the status of the system remotely and controlling certain parameters with a smartphone from a custom-built android application. The prototype of the system worked satisfactorily according to design specification and eliminates the stress associated with a manual power source change-over process.
Although, this design makes a fundamental assumption that all the sources can carry the entire load in the building. This is not the typical case, as most alternative sources have a rated capacity that can carry only a fraction of the load in the buildings conveniently. Further work could consider the integration of an automatic load sheading or load shifting control system in order to protect the sources from overload yet ensure critical loads are supplied energy at all times.