### 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.

**Software/Hardware Tradeoffs**

Some software tradeoffs we made involved our calculations of the voltage, current, and power. When using a microcontroller, fixed-point math is the best way to go to make sure the calculations get done as quickly as possible. However, we are more concerned with the accuracy of these numbers and chose to use floating point instead. Since we are only doing major calculations every ten seconds, we were not concerned with the delay this floating-point arithmetic would have on our design. Another tradeoff that we made was to step down the voltages using a current divider in order to measure current and voltages. This is because we are using 12 V, and the opto-isolator we used could only handle inputs of up to 5V. We saw that a previous project had used this opto-isolator successfully so we decided to use it and risk having a small percent of error from scaling down. We decided to use TinyRealTime instead of interrupt service routines because we had to accurately schedule our tasks due to deadlines. Another tradeoff involved finding the charge of the batteries. Instead of following the discharge behavior of the batteries or integrating the current, we chose to simply measure the voltage and divide this voltage by the maximum voltage of the batteries to find the charge percentage. We could do this because nickel-cadmium has a nearly linear relationship between charge and voltage. This is a software tradeoff because it saved us time in calculations and proved an approximate result.

In terms of hardware tradeoffs, we had to decide how to accurately measure current without losing power to the house. We had two options: use a current divider, an opto-isolator, and an operational amplifier or use a current-sensing resistor and a differential opto-isolator. We attempted to use the first option, however the opto-isolator needed 1.8V across it. This voltage drop results in a decrease in power delivery to the house. Choosing the proper resistance values to get this 1.8V drop was difficult. The output of the op-amp was a voltage that we used to find the current flowing through the house, but we could not find the appropriate scaling factor between the voltage and current. The voltage output was on the milli-volt range, so we did not think the ADC converter would understand how to scale this small voltage. Therefore we decided to use the second option, which will be described in the Program Detail section.

There are many products on the market for saving energy and measuring the power consumption of your house. There are even companies that are devoted to producing the “Smart Home” we are trying to create. IEEE standards for sizing nickel cadmium batteries for a photovoltaic, IEEE standards for utility interface of residential and intermediate photovoltaic systems.

There are many products on the market for saving energy and measuring the power consumption of your house. These products include the *Kill-A-Watt* and various other surge protector based power conservation devices. There are even companies that are devoted to producing the “Smart Home” we are trying to create. For this type of product, we must satisfy IEEE standards for sizing nickel cadmium batteries for a photovoltaic as well as IEEE standards for utility interface of residential and intermediate photovoltaic systems.

**Program Details **

Our code consisted of four main tasks. The first task, getInput(), is a continuous task used to monitor the inputs from the user. In order to initiate the program, the user is required to input the start time (hour in military time, minute, second) for accurate time keeping. This function then continuously watches for inputs from the user in order to signify a demand response event has occurred. A demand response event is one in which the power company would signal that the home needs to reduce it’s power consumption. In order to represent this, the user would input the maximum power the house can use and the length of this power restriction.

The updateClk() task simply keeps track of time. It has a release and deadline time of 1.0 second and increments the second of the clock. When the second reaches 60, it is reset to 0 while the minute variable is incremented. The minute variable is incremented until it reaches 60 as well, where it is reset and the hour variable is incremented. The hour is in military time, so instead of rolling over to 24 it will reset to zero. Time keeping is very important in our project because we need to keep track of the price of energy, which varies throughout the day. The price of energy plays a role in our decision-making algorithm.

PVmonitor() is the monitoring task that calculates the power of the PV, power demand of the home, the battery charge, and the power being produced by or sold back to the grid. To get the power, we need to find the voltage and current for each source. We do this by reading in the outputs of the four opto-isolators into the ADC on the microcontroller, as well as the voltage from our voltage dividers. The voltage is calculated based on the voltage divider, as well as a calibration factor. In order to find the current, we calculate the actual voltage drop across our 2Ω current sensor by using the equation from the opto-isolator and a factor from our voltage divider.

**Vdiff=0.512/Vref(Vout-Vref/2)**

The ADC is an analog-to-digital converter, which takes in an analog value and converts it to a number between 0 and 255. We can retreive the original analog number by multiplying the ADCH number by 5/255, where 5 is the reference voltage.

Then we use Ohm’s Law to get the current by dividing Vdiff by 2Ω. The power can then be calculated by multiplying this current by the previous voltage we found.

## Parts List:

Product | Quantity | Cost Each | Total |

Avago Technologies HCPL 7520 | 4 | $6.02 | $24.08 |

Inverter from research group | |||

2 Transformers from Research Group | |||

Power Supply | 1 | $5.00 | $5.00 |

White Board | 5 | $6.00 | $30.00 |

STK500 | 1 | $15.00 | $15.00 |

Ni-Cad Batteries | |||

2 Ohm Resistors from Lab | |||

LM358 Op-Amp from Lab | |||

Various Capacitors and Resistors from lab | |||

Total | $74.08 |

For more detail: Home energy managment Using Atmega644