31
EEL 4924 Electrical Engineering Design 2 (Senior Design) Final Design Report 23 April 2013 Project Title: Interactive BreakerBox Team Members : Name: Ambrose Coulliette Name: Aaron Joseph Project Abstract: The goal of our project is to measure the power consumed by three individual breaker circuit by calculating the RMS voltage and currents for each one. This information is displayed on a LCD screen mounted on the breaker box front panel and sent wirelessly to a computer to be shown on a python GUI display. The GUI can also displays KWh and cost associated with each breaker circuit and has the ability to send command to turn a circuit on and off. A smartphone can remotely access the GUI. 1

EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Embed Size (px)

Citation preview

Page 1: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

EEL 4924 Electrical Engineering Design 2(Senior Design)

Final Design Report23 April 2013

Project Title: Interactive BreakerBox

Team Members:Name: Ambrose Coulliette Name: Aaron Joseph

Project Abstract:The goal of our project is to measure the power consumed by three individual breaker

circuit by calculating the RMS voltage and currents for each one. This information is

displayed on a LCD screen mounted on the breaker box front panel and sent wirelessly to

a computer to be shown on a python GUI display. The GUI can also displays KWh and cost

associated with each breaker circuit and has the ability to send command to turn a circuit

on and off. A smartphone can remotely access the GUI.

1

Page 2: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Table of Contents Page(s)

Project Abstract ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 1

Project Features ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 3

Components ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 5

Hardware ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 7

Distribution of Labor ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 14

Projected Timeline ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 15

Conclusion ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 15

Appendix A ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 16

Appendix B ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 23

Appendix C ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 31

List of Tables

1. BOM (bill of materials) ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 14

2. Distribution of Labor ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 14

List of Figures

1. LCD screen ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 3

2. Python GUI ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 4

3. GUI access by smart phone ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 4

4. LCD­NHD­0420AZ­FSW­GBW­33V3 ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 5

5. XBee­XB24­AWI­001­ND ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 5

6. Split Core Current Transformer ECS1030­L72 ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 6

7. Relay­T9AS1D12­5 ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 6

8. Project layout ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 7

9. Sensor and control layout ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 7

10. Typical current sensor schematic ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 8

11. Current sensor experiment results ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 8

12. Voltage sensor ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 9

13. Other component schematics ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 10

14. Main PCB ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 11

15.Relay schematic ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 12

16. Relay PCB ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 13

17. Gantt Chart of Timeline ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 15

2

Page 3: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Project FeaturesThe following are our projects features:

Measure power consumed by three breaker circuits (see appendix B) by

Calculate RMS current : ( ) / R input from non­invasive current transformer see figure 6

Calculate RMS voltage: input from transformer connected in parallel to circuits

LCD screen displays (see appendix B)

RMS currents

RMS voltage

Power

Figure 1: LCD screen

Wirelessly send data to a computer via XBee (see appendix B)

RMS currents

RMS voltage

Python GUI (see appendix A)

Displays

RMS currents

RMS voltage

Powers

KWh

Cost

Relay commands

Turn circuit on

Turn circuit off

3

Page 4: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Figure 2: Python GUI

Python GUI access by smart phone

VNC (software connection)

Server

Client

password protection

Figure 3: GUI access by smart phone

4

Page 5: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

ComponentsThe following are the main components we have chosen :

NHD­0420AZ­FSW­GBW­33V3 ­ Character Liquid Crystal Display Module shown

in figure 4.

This model was chosen because it has 4 lines and can display 20 characters

per line, which will be more than enough to display the real time power usage

for each of the three breaker circuits

The backlight is powered with 3V and the reference voltage is 3.3V this

means that its power consumption is relatively low.

We have used a similar LCD before in other classes which were very simple

to use

Figure 4: NHD­0420AZ­FSW­GBW­33V3

XB24­AWI­001­ND ­ XBee model shown in figure 5

This model was chosen because it was the cheapest XBee that met our

project needs

There are lots of tutorials on how to use this model online

There is a 30m range of communication for this series 1 model

Figure 5: XB24­AWI­001­ND

Split Core Current Transformer ECS1030­L72 model shown in figure 6

5

Page 6: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

This component was chosen because it can be used to measure AC current

at 50/60 Hz

It was cheap

It mounts easily

It has a linear relationship between primary current and output voltage

Figure 6: Split Core Current Transformer ECS1030­L72

Atmega164PA microcontroller

This microcontroller was chosen because we got free samples

It is easy to program

Contains an appropriate number of ADC and i/o pins

T9AS1D12­5 ­ Power Relays model shown in figure 7

The model was chosen because it has a rated current of 30A

It is rated for a switching Voltage max of 277VAC

It has a coil Voltage of 5VDC

Figure 7: T9AS1D12­5

6

Page 7: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

HardwareOverall project layout:

The overall project layout is shown in figure 8. Components inside of the green rectangular

boundary indicates components placed inside the breaker box; therefore, housed inside

the breaker box are the LCD, uP, one XBee, current sensors and the voltage sensor.

Figure 8: Project layout

Sensors and control layout:

The sensors and control layout shown in figure 9 gives an indication of how the voltage

sensor input, current sensor inputs and relay circuits were implemented. Each circuit has a

mechanical breaker switch much like a traditional breaker box, a relay circuit which acts

like a switch that can be controlled by our microcontroller, and a current transformer which

serves as the input to a current sensor. The voltage sensor input which is a transformer, is

placed in parallel to the circuits.

Figure 9: Sensor and control layout

7

Page 8: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Current sensors:

A typical current sensor schematics is shown in figure 10. The input to the current sensor is

a current produced by the current transformer. This current flows through a resistor. The

voltage across the resistor is rectified. The rectified voltage servers as an input to an ADC

pin on our microcontroller. The rectified voltage makes it possible to have only positive

voltages and better resolution than other techniques when calculating the RMS values.

Figure 10: Typical current sensor schematic

In order to test the accuracy of the current sensor some experiments were performed. The

results of these experiments over two periods are shown in figure 11.

Figure 11: Current sensor experiment results

8

Page 9: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Voltage sensor:

The voltage sensor schematic is shown in figure 12. The secondary voltage of the

transformer serves as an input to a voltage divider circuit. Much like the current sensor

circuit the output of the voltage divider circuit is rectified then the rectified voltage serves as

an input to an ADC pin on our microcontroller.

Figure 12: Voltage sensor

Other circuits:

Figure 13 shows the schematics for the other components implemented in the main PCB.

These other component are 3.3V and 5V regulator, XBee, ATmega164PA, and LCD.

9

Page 10: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Figure 13: Other component schematics

10

Page 11: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Main PCB:

The main PCB shown in figure 14 is made of current sensors, voltage sensor, and other

components schematics shown in figure 13 .

Figure 14: Main PCB

Relay schematics:

The relay schematic is shown in figure 15.To control power to each circuit relays were

used. As the micro controller can’t supply enough current to operate the relay a transistor is

used as a switch. There is no polygon pour in Figure 16 on the right side of the PCB to

prevent high currents up to 15 amps from arching.

11

Page 12: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Figure 15: Relay schematic

12

Page 13: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Figure 16: Relay PCB

13

Page 14: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

B.O.M.:

The following table shows the bill of materials used in constructing this project. It also gives

an estimated cost ($319.78) for replicating this project.

Table 1: BOM (bill of materials)

Distribution of LaborThe following table shows the breakdown of each team member's projected labor by

approximate percentage.

Table 2: Distribution of Labor

14

Page 15: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Projected TimelineThe following is a Gantt chart of the projected timeline for the project in figure 6.

Figure 17: Gantt Chart of Timeline

ConclusionThis project measures the power consumed by three breaker circuit by calculating the RMS

voltage and current for each one. That information is displayed on a LCD screen and sent

wirelessly to a computer to be displayed on a python GUI. The GUI also displays KWh and

cost associated with each circuit, it can also send commands to turn a circuit on and off.

The GUI can be remotely accessed by a smartphone.

This project is prelude to a tool that residential power consumers can use to conserve

power through self­awareness, observe appliance normal power consumption, and offer a

convenient way to turn appliances on and off while away from home.

15

Page 16: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Appendix APython GUI program:

#!/usr/bin/python# ­*­ coding: iso­8859­1 ­*­

########################################################### Interactive BreakerBox GUI ## Composers: Ambrose Coulliette, Aaron Joseph ## Last update: 4/20/13 ###########################################################import Tkinterimport serialimport timeimport datetime

# Try connecting to The XBee COM porttry: ser = serial.Serial(8,timeout=1) # open COM9 serial port print ser.portstr # check which port was really usedexcept: print "No Port Detected" ser = "0.0"

### Set global vers ###global cir_sel; cir_sel = "1"global i; i = 1global j; j = 1global k; k = 1global Kwh_tot; Kwh_tot = 0.0global cost_char; cost_char = "1"global time_last; time_last = time.time()global p1_tot; p1_tot = 0.0global p2_tot; p2_tot = 0.0global p3_tot; p3_tot = 0.0

### define the class ###class simpleapp_tk(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.paremt = parent self.initialize()### Define Buttons ### def initialize(self): self.grid()

#initialize breaker select buttons #Star button resets KWh and total cost StartButton = Tkinter.Button(self, text=u"ReStart "

16

Page 17: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

, command=self.OnStartButtonClick) StartButton.grid(column = 0, row=0, rowspan = 2, sticky='NEWS', padx=1,pady=1) #button 1 ­ 3 are for current display button = Tkinter.Button(self, text=u"Breaker one " , command=self.OnButtonClick) button.grid(column = 0, row=2, sticky='W', padx=1,pady=1)

button2 = Tkinter.Button(self, text=u"Breaker two " , command=self.OnButtonClick2) button2.grid(column= 0, row=3, sticky='W', padx=1,pady=1)

button3 = Tkinter.Button(self, text=u"Breaker three" , command=self.OnButtonClick3) button3.grid(column= 0, row=4, sticky='W', padx=1,pady=1)

#button 4 ­ 6 are breaker disengage buttons self.buttonVariable = Tkinter.StringVar() self.buttonVariable.set("Disengage") button4 = Tkinter.Button(self, textvariable=self.buttonVariable, command =self.OnButtonClick4) button4.grid(column = 3, row=2, sticky='E') #sticky='E'

self.buttonVariable2 = Tkinter.StringVar() button5 = Tkinter.Button(self, textvariable=self.buttonVariable2,command=self.OnButtonClick5) button5.grid(column= 3, row=3, sticky='E') self.buttonVariable2.set(u"Disengage")

self.buttonVariable3 = Tkinter.StringVar() button6 = Tkinter.Button(self, textvariable=self.buttonVariable3,command=self.OnButtonClick6) button6.grid(column= 3, row=4, sticky='E') self.buttonVariable3.set(u"Disengage")

#Text entry field for setting price per KWh self.entryVariable = Tkinter.StringVar() self.entry = Tkinter.Entry(self, textvariable=self.entryVariable) self.entry.grid(column = 1, sticky='EW') self.entry.bind("<Return>", self.OnPressEnter) self.entryVariable.set(u"Enter Price Per kWh.") ############################################# # Label Declarations # # # #############################################

#labels for displaying circuit breaker power usage self.labelVariable1 = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.labelVariable1, anchor="w", fg="white", bg="blue") label.grid(column=1, row=2, columnspan=1,sticky='WE')

17

Page 18: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

self.labelVariable1.set(u" 0.0000W | 0.0000KWh | 0.0000$ ")

self.labelVariable2 = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.labelVariable2, anchor="w", fg="white", bg="blue") label.grid(column=1, row=3, columnspan=1,sticky='WE') self.labelVariable2.set(u" 0.0000W | 0.0000KWh | 0.0000$ ")

self.labelVariable3 = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.labelVariable3, anchor="w", fg="white", bg="blue") label.grid(column=1, row=4, columnspan=1,sticky='WE') self.labelVariable3.set(u" 0.0000W | 0.0000KWh | 0.0000$ ")

# Total power displays self.topBanner = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.topBanner, anchor="w", fg="blue", bg="white") label.grid(column=1, row=0, columnspan=3, sticky='EW') self.topBanner.set(u" Power | KWh | Cost ")

self.totalVals = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.totalVals, anchor="w", fg="blue", bg="white") label.grid(column=1, row=1, columnspan=3, sticky='EW') self.totalVals.set(u" 0.0000W | 0.0000KWh | 0.0000$ ")

#Bottom of the screen data labels self.labelVariable4 = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.labelVariable4, anchor="w", fg="white", bg="blue") label.grid(column=0, row=6, columnspan=4,sticky='EW') self.labelVariable4.set(u"Voltage: 0V")

self.labelVariable5 = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.labelVariable5, anchor="w", fg="white", bg="blue") label.grid(column=0, row=7, columnspan=4,sticky='EW') self.labelVariable5.set(u"current: 0A")

self.labelVariable6 = Tkinter.StringVar() label = Tkinter.Label(self, textvariable=self.labelVariable6, anchor="w", fg="white", bg="blue") label.grid(column=0, row=8, columnspan=4,sticky='EW') self.labelVariable6.set(u"Cost per KWh: 1.00$")

# resizing stuff self.grid_columnconfigure(0, weight=1) self.resizable(True,False)

18

Page 19: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

self.update() self.geometry(self.geometry()) self.entry.focus_set() self.entry.selection_range(0, Tkinter.END)

############################################# # button click Definitions # # # ############################################# def OnStartButtonClick(self): # Restart global Kwh_tot; Kwh_tot = 0.0 global p1_tot; p1_tot = 0.0 global p2_tot; p2_tot = 0.0 global p3_tot; p3_tot = 0.0 self.entry.focus_set() self.entry.selection_range(0, Tkinter.END)

def OnButtonClick(self): # Circuit one global cir_sel; cir_sel = "1" self.entry.focus_set() self.entry.selection_range(0, Tkinter.END) print "Circuit one outputting"

def OnButtonClick2(self): # Circuit two global cir_sel; cir_sel = "2" self.entry.focus_set() self.entry.selection_range(0, Tkinter.END) print "Circuit two outputting"

def OnButtonClick3(self): # Circuit three global cir_sel; cir_sel = "3" self.entry.focus_set() self.entry.selection_range(0, Tkinter.END) print "Circuit three outputting"

#### Relay buttons ### def OnButtonClick4(self): if i == 1: ser.write("a") self.buttonVariable.set("engage ") global i; i = 0 else: ser.write("A") self.buttonVariable.set("Disengage") global i; i = 1 self.entry.focus_set() self.entry.selection_range(0, Tkinter.END)

def OnButtonClick5(self): if j == 1:

19

Page 20: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

ser.write("b") self.buttonVariable2.set("engage ") global j; j = 0 else: ser.write("B") self.buttonVariable2.set("Disengage") global j; j = 1 self.entry.focus_set() self.entry.selection_range(0, Tkinter.END)

def OnButtonClick6(self): if k == 1: ser.write("c") self.buttonVariable3.set("engage ") global k; k = 0 else: ser.write("C") self.buttonVariable3.set("Disengage") global k; k = 1 self.entry.focus_set() self.entry.selection_range(0, Tkinter.END)

### Text field entry ### def OnPressEnter(self, event): global cost_char; cost_char = self.entryVariable.get() self.labelVariable6.set("Cost per KWh:" + self.entryVariable.get() + "$") self.entry.focus_set() self.entry.selection_range(0, Tkinter.END)

############################################## Background Loop ## ##############################################def task(): st = "w" global cir_sel; global time_last; ser.flushInput() # flush out any erroneous data ser.write(st) # send command to AtMega time.sleep(1) # wait a sec for data to come back current1 = ser.read(4) current2 = ser.read(4) current3 = ser.read(4) voltage = ser.read(4) try: # If valid data is not received skip main loop c1 = float(current1) #convert string to float vals c2 = float(current2) c3 = float(current3) v = float(voltage) time_now = time.time() #calculate time difference

20

Page 21: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

time_diff = float(time_now ­ time_last) time_last = time_now print str(time_diff) app.labelVariable6.set(u"Price per KWh: " + cost_char + "$") p1 = c1*v #calculate instantaneous power power1 = str(p1) p2 = c2*v power2 = str(p2) p3 = c3*v power3 = str(p3) power_tot = p1 + p2 +p3 Kwh = power_tot*time_diff/3600000 #calculate Kilowatt hours P1_KWh = p1*time_diff/3600000 P2_KWh = p2*time_diff/3600000 P3_KWh = p3*time_diff/3600000 global Kwh_tot; Kwh_tot = Kwh_tot + Kwh global p1_tot; p1_tot = p1_tot + P1_KWh global p2_tot; p2_tot = p2_tot + P2_KWh global p3_tot; p3_tot = p3_tot + P3_KWh KWh_total = str(round(Kwh_tot,4)) global cost_char; global hold_cost_char; try: #throw an error is user inserts invalid Cost input junk = float(cost_char) except ValueError,e: print "error",e,"on line",i cost_char = hold_cost_char app.labelVariable6.set(u"type in value as X.XX format") cost_float = float(cost_char) hold_cost_char = cost_char tot_cost = Kwh_tot*cost_float total_cost = str(round(tot_cost,4)) #calculate total cost ### Print the labels ### app.totalVals.set(u" " + str(round(power_tot,2)).ljust(7,'0') + "W | " + KWh_total.ljust(6,'0')+"KWh | "+total_cost.ljust(6,'0') +"$ ") app.labelVariable4.set(u"Voltage: " + voltage + " Volts") if cir_sel == "1": cur_display = current1 elif cir_sel == "2": cur_display = current2 elif cir_sel == "3": cur_display = current3 app.labelVariable5.set(u"Current" + cir_sel + ": " + cur_display + "Amps") app.labelVariable1.set(u" " + str(round(p1,2)).ljust(7,'0') + "W | " +str(round(p1_tot,4)).ljust(6,'0') +"KWh | "+str(round(p1_tot*cost_float,4)).ljust(6,'0')+"$ ") app.labelVariable2.set(u" " + str(round(p2,2)).ljust(7,'0') + "W | " +str(round(p2_tot,4)).ljust(6,'0') +"KWh | "+str(round(p2_tot*cost_float,4)).ljust(6,'0')+"$ ") app.labelVariable3.set(u" " + str(round(p3,2)).ljust(7,'0') + "W | " +str(round(p3_tot,4)).ljust(6,'0') +"KWh | "+str(round(p3_tot*cost_float,4)).ljust(6,'0')+"$ ") except:

21

Page 22: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

print "missed a step" app.entry.focus_set() app.entry.selection_range(0, Tkinter.END) app.after(5000,task)

############################################## The end ## ##############################################if __name__ == "__main__": app = simpleapp_tk(None) app.title('BreakerBox GUI') app.after(5000,task) app.mainloop()

22

Page 23: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

Appendix BMicrocontroller program:/* * Created : 2/11/2013 * Author : Ambrose Coulliette * Last mod: 3/7/2013 * AtMill with PYSERAL V 2.0 */

#include <avr/io.h>#include <util/delay.h>#include <string.h>#define F_CPU 1000000L//#define BAUD 9600//#define MYUBRR F_CPU/16/BAUD­1

///////// LCD functions /////void lcd_command(char);void lcd_char(char);void lcd_string(char *data);void lcd_init();

///////USART XBEE STUFF/////void USART_Init( unsigned int baud );void USART_Transmit( unsigned char );// data outunsigned char USART_Receive( void ); //returns UDRnunsigned char usart_kbhit(void);void USART_Flush( void );void usart_putchar(char data);void usart_putstring(char *data);void number_to_usart( float number_float);unsigned int baud = 6;

/////// ADC functions //////long int ADC_read( void );float ADC_scale( long int volt_float );void volt_to_LCD( float volt_float);

////// other initializations /////char temp, temp2;char test_char;int x;

/************************** MAIN PROGRAM ***********************/

int main(void)

ADCSRA = 0X80;

23

Page 24: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

ADMUX = 0x60;DIDR0 = 0x01;DDRB = 0xFF;DDRD = 0xFF;

_delay_ms(100);lcd_init();USART_Init( baud );PRR0 = (0 << PRUSART0);unsigned int highest_volt = 0;int sample = 217;float volt_float[217];float RMSvoltage ;float RMScurrent[3];float RMS = 0;float Power[3];float Power_tot;float Currection_factor[3] = 1.17,1.18,1.16;

lcd_string("Line:One |Two |Three");lcd_command(0xC0); //Send cursor to line 2lcd_string("Volt: | |");lcd_command(0x94); //Send cursor to line 3lcd_string("curr:");lcd_command(0xD4); //Send cursor to line 4lcd_string("Powe:");

while( 1) /// Main Loop ///

for(int k = 0; k < 4; k++)

if(k == 0 )ADMUX = 0x60;

else if(k == 1)

ADMUX = 0x61;else if(k == 2)

ADMUX = 0x62;else

ADMUX = 0x63;/****** Zero Crossing *****/if(k != 3)

int Z = 1;while(Z != 0)

Z = ADC_read();

24

Page 25: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

elseint Z = 1024;while(Z > 20)

Z = ADC_read();

/****************************/

int Z = 1024;while(Z > 100)

Z = ADC_read();

for(int i = 0; i < sample ; i++)volt_float[i] = ADC_read();

RMS = 0;

for(int i = 0 ; i < sample; i++) volt_float[i] = ADC_scale(volt_float[i]); volt_float[i] = (volt_float[i]*volt_float[i]);

RMS = RMS + volt_float[i];

if( RMS < 0.010) RMS = 0;

RMS = sqrt(RMS/sample); _delay_ms(100); if(k < 3) RMScurrent[k] = ((RMS/664) * 2000)*1.163; else

RMSvoltage = RMS*49.2; Power[k] = RMScurrent[k] * RMSvoltage;

Power_tot = Power[0] + Power[1] + Power[2];

/*********** read from UART *********/if(usart_kbhit()) test_char = USART_Receive();

/********* print to USART *********/test_char = test_char & 0x7f;

if(test_char == 'w')

25

Page 26: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

number_to_usart(RMScurrent[0]);number_to_usart(RMScurrent[1] );number_to_usart(RMScurrent[2] );number_to_usart(RMSvoltage );

else if(test_char == 'a')

PORTB |= (1<<PORTB0);

else if(test_char == 'A')

PORTB &= ~(1<<PORTB0);else if(test_char == 'b' )

PORTB |= (1<<PORTB1);else if(test_char == 'B' )

PORTB &= ~(1<<PORTB1);

else if(test_char == 'c' )PORTB |= (1<<PORTB2);

else if(test_char == 'C' )

PORTB &= ~(1<<PORTB2);

/*********** Write to LCD **********/

lcd_command(0xC5);volt_to_LCD(RMSvoltage);lcd_command(0x99);volt_to_LCD(RMScurrent[0]);lcd_string("|");volt_to_LCD(RMScurrent[1]);lcd_string("|");volt_to_LCD(RMScurrent[2]);lcd_command(0xD9);volt_to_LCD(Power[0]);lcd_string("|");volt_to_LCD(Power[1]);lcd_string("|");volt_to_LCD(Power[2]);

/////////////////////////////////////////////////// Functions begin //////////////////////////////////////////////////////////////********************* LCD functions ********************/void lcd_init()

26

Page 27: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

DDRC = 0xCF; //Set port C for outputlcd_command(0x33); //Initialize LCD Driverlcd_command(0x32); //Four bit modelcd_command(0x2C); //4 Line Modelcd_command(0x0C); // Display On, Cursor Off, Blink Offlcd_command(0x01); //Clear Screen, Cursor Home

void lcd_command(char cmd)

char temp = cmd;PORTC=0;

_delay_ms(5);

cmd = ( (cmd & 0xF0) >> 4) | 0x80; //Write Upper Nibble (RS=0) E ­­> 1PORTC = cmd;_delay_ms(5);cmd ^= 0x80; //E ­­> 0PORTC = cmd;

_delay_ms(5);

cmd = temp;cmd = ( (cmd & 0x0F) ) | 0x80; //Write Lower Nibble (RS=0) E ­­> 1PORTC = cmd;_delay_ms(5);cmd ^= 0x80; //E ­­> 0PORTC = cmd;

_delay_ms(7);

void lcd_string(char *data) //stringwhile(*data)

lcd_char(*data);data++;

void lcd_char(char data)

char temp = data;PORTC = 0x40;

_delay_ms(5);

data = ( (data & 0xF0) >> 4) | 0xC0; //Write Upper Nibble (RS=1) E ­­> 1

27

Page 28: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

PORTC = data;_delay_ms(5);data ^= 0x80; // E ­­> 0PORTC = data;

_delay_ms(5);data = temp;

data = ( (data & 0x0F) ) | 0xC0; //Write Lower Nibble (RS=1) E ­­> 1PORTC = data;_delay_ms(5);data ^= 0x80; //E ­­> 0PORTC = data;

_delay_ms(7);

/********************** USART functions ***************************/

void USART_Init( unsigned int baud ) UBRR0 = baud; /* Set baud rate */

/* Enable receiver and transmitter */UCSR0B = (1<<RXEN0)|(1<<TXEN0);/* Set frame format: 8data, 1stop bit */UCSR0C = (0<<USBS0)|(3<<UCSZ00)|(UPM00 << 0)|(UPM01 << 0);

unsigned char USART_Receive( void )

/* Wait for data to be received */while ( !(UCSR0A & (1<<RXC0)) );/* Get and return received data from buffer */return UDR0;

void USART_Flush( void )

unsigned char dummy;while ( UCSR0A & (1<<RXC0) ) dummy = UDR0;

void usart_putchar(char data) // Wait for empty transmit bufferwhile ( !(UCSR0A & (_BV(UDRE0))) );// Start transmissionUDR0 = data;

void usart_putstring(char *data) //string

28

Page 29: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

while(*data)usart_putchar(*data);*data ++;

unsigned char usart_kbhit(void) //return nonzero if char waiting polled versionunsigned char b;b=0;if(UCSR0A & (1<<RXC0)) b=1;return b;

void number_to_usart( float number_float)char number_char;int i = 0;

while(number_float > 10.0)number_float = number_float/10.0;i++;

number_char = number_float + 0x30; //48usart_putchar(number_char);if( i == 0)

usart_putchar('.');

number_char =number_float*10;while(number_char >= 10.0)number_char = number_char ­ 10.0;number_char = number_char + 0x30;usart_putchar(number_char);

if( i == 1)usart_putchar('.');

number_char =number_float*100;while(number_char >= 10.0)number_char = number_char ­ 10.0;number_char = number_char + 0x30;usart_putchar(number_char);

if( i == 2)usart_putchar('.');

29

Page 30: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

/************* ADC functions ***********/long int ADC_read( void )ADCSRA = 0xC0; //singular shot

while( bit_is_set(ADCSRA,6 ) != 0) //wait for flag loop int ADCLOW = ADCL;long int volt = ADCH;

volt = volt << 2; ADCLOW = ADCLOW >> 6; volt = volt + ADCLOW;

return volt;

float ADC_scale( long int volt )float volt_in = volt / 204.6; //returns float val from 0V to 5Vreturn volt_in;

void volt_to_LCD( float volt_float)char volt_char;int i = 0;

while(volt_float > 10.0)volt_float = volt_float/10.0;i++;

volt_char = volt_float + 0x30;lcd_char(volt_char);if( i == 0)

lcd_char('.');

volt_char =volt_float*10;while(volt_char >= 10.0)volt_char = volt_char ­ 10.0;volt_char = volt_char + 0x30;lcd_char(volt_char);

if( i == 1)lcd_char('.');

30

Page 31: EEL 4924 Electrical Engineering Design 2 (Senior Design) ·  · 2013-04-23EEL 4924 Electrical Engineering Design 2 (Senior Design) ... Calculate RMS voltage: input from transformer

volt_char =volt_float*100;while(volt_char >= 10.0)volt_char = volt_char ­ 10.0;volt_char = volt_char + 0x30;lcd_char(volt_char);

if( i == 2)lcd_char('.');

if( i == 3)

volt_char =volt_float*1000;while(volt_char >= 10.0)

volt_char = volt_char ­ 10.0;volt_char = volt_char + 0x30;lcd_char(volt_char);

Appendix CProject video link:http://youtu.be/8o95yYlJLIU

31