# Home energy managment Using Atmega644a ### Introduction

Our project implements a smart algorithm in order to power a house with a photovoltaic, batteries or the power grid.  For this project, we worked closely with a research team whose goal is to power a home with minimal power from the power grid.  In order to form this smart home, we needed to monitor the voltage and current flow from each of the sources (photovoltaic, batteries, and the grid) and the home.  We implemented these current and voltage monitors.  The next step was to come up with an algorithm that would determine what source should be powering the house and when the battery should be charged.  The final step was to send out data to a home display module so that the data can be analyzed. #### High Level Desig

Our project idea came from a research team focusing on building a smart home, since one of our group members is working with the team.  In order to decide how to power the house, it is necessary to find the power demand of the house and the available power from each source.  The power can be found by the following equations: P=IV, P=V^2/R, P=I^2R.
For AC power calculations we needed to find average power instead of instantaneous power. Therefore we needed to find the root-mean-squared value for the current and the power, and we also needed to find the phase difference between the voltage and the current.
I(t)=Ipeak*cos(2πft)
V(t)=Vpeak*cos(2πft + φ)
Pavg=I*V=Irms*Vrms*cos(φ) => Vrms=Vpeak/√2 and Irms=Ipeak/√2

For our project we are using the HCPL-7520 Linear Opto-isolator in order to determine the voltage drop across a resistor. These isolators can be modeled by the equation below, where Vin is the differential input.
Vin=.512/Vref*(Vout-Vref/2)
The voltages that we are measuring exceed 5V, therefore we used voltage dividers to scale down those voltages. For calculations, we found the actual voltage on the line by using the following equation, where the input to the microcontroller would be Vscale and the actual voltage would be Vhigh.
Vscale=R1/(R1+R2)*Vhigh
The diagram below shows the layout of the power sources, relays, and the load. The solar panel generates DC power and when Relay 1 is closed, that power is sent to an inverter, which transforms the power to AC. The inverter outputs a 120AC signal, which is then stepped-down to 12VAC using a transformer for safety purposes. The 12VAC is then sent to the home. The nickel-cadmium batteries generate DC power, which is also sent to the inverter when Relay 3 is closed in order to power the home. These batteries can be charged by the grid when Relay 4 is closed and by the photovoltaic when Relay 2 is closed. A DC to DC converter is needed when charging the battery with the photovoltaic in order to charge the battery properly. When charging the batteries with the grid power, we need to transform the AC power into DC. We achieved this by passing the signal through a full-wave rectifier and a DC to DC converter. In order to power the house with the grid, Relay 5 must be closed. In order to determine which relays are closed we monitored the available power from the battery and the PV. Using the power measurements we ran an algorithm that decided the most efficient way to power the house. 