Power Manager: Remote Power Control Through LAN using Atmega644

Introduction

Overview

PowerManager is a remote power management system that can be controlled through a web browser on a local area network (LAN). Devices plugged into PowerManager’s outlets can be turned on or off with the click of a button on a webpage. PowerManager runs on an ATMEGA644 microcontroller and an ENC28J60 Ethernet controller. Together, this embedded system acts as a web server to serve a web page that allows the user to turn on or off the supply of power to the connected devices. The project serves as a fundamental element in a home automation system.
 Remote Power Control Through LAN using Atmega644

Rationale

These days, everyone has a smart phone in their pocket connected to their home LAN. With such a powerful device, why should anyone have to physically control their home’s power and lighting? With the advancement of micro controller technology, it is now possible to have every device in a home be connected to a home LAN. These home devices can act as web servers to provide a web-based GUI to control and monitor the device. The simplest and most necessary kind of control is turning a device on or off. PowerManager fulfills this need in a standard way; any device with a standard electrical plug can be controlled (on or off) through home LAN.

High Level Design

System Overview

The PowerManager system is based on a client server model of communication. The PowerManager acts as a web server embedded on the ATMEGA644 MCU and ENC28J60 Ethernet controller. The MCU connects to the Ethernet controller through an SPI interface; the controller handles the physical and MAC layers of networking, and provides a standard interface to the MCU to send and receive packets. With this interface, the MCU is able to run IP, TCP, and HTTP layers. Additionally, the MCU connects through an audio cable to a power box. The power box contains a relay to control the flow of power to standard electrical sockets; the other end of the audio cable is used to control this relay, allowing full control of power from the MCU.
To use the system, a client (perhaps a browser on an iPhone) sends a request over HTTP to the PowerManager web server, which returns a page indicating the current state of power (on or off) and a button to toggle the state. When receiving a state change request, the MCU calls a CGI function to change its output to the power box, effectively changing the state of power flow to the electrical outlets.

High Level Design

System Overview

The PowerManager system is based on a client server model of communication. The PowerManager acts as a web server embedded on the ATMEGA644 MCU and ENC28J60 Ethernet controller. The MCU connects to the Ethernet controller through an SPI interface; the controller handles the physical and MAC layers of networking, and provides a standard interface to the MCU to send and receive packets. With this interface, the MCU is able to run IP, TCP, and HTTP layers. Additionally, the MCU connects through an audio cable to a power box. The power box contains a relay to control the flow of power to standard electrical sockets; the other end of the audio cable is used to control this relay, allowing full control of power from the MCU.
To use the system, a client (perhaps a browser on an iPhone) sends a request over HTTP to the PowerManager web server, which returns a page indicating the current state of power (on or off) and a button to toggle the state. When receiving a state change request, the MCU calls a CGI function to change its output to the power box, effectively changing the state of power flow to the electrical outlets.

Software Overview

The design architecture for PowerManager can best be described on a modular level. The system is made up of both networking and system modules. The networking modules work together to provide data transmission and retrieval functionality. The system modules implement system dependent data structures and timers. All of these modules work together to provide the functionality that PowerManager requires to accomplish its goals.

Hardware Overview

PowerManager uses an ATMEGA644 micro controller (MCU) embedded on the standard ECE 4760 custom PC board. The MCU connects to an ENC28J60 Ethernet controller chip through an SPI interface on Port B. A module for the Ethernet controller was custom built on a solder board, and appropriately connects the controller to power, ground, I/O, etc. The Ethernet controller runs a 3.3V, so a power regulator is used to drop the MCU’s 5V VCC signal to 3.3V for the chip. Since the Ethernet controller’s outputs to the MCU are at 3.3V, level shifters are used to turn the signal back to 5V. This is not needed in the reverse direction, since the controller’s inputs are 5V tolerant. An RJ45 Ethernet jack is connected to the Ethernet controller.
In terms of power control, a custom power box was built. This box can plug into any standard U.S. electrical outlet, and contains 2 outlets, a master switch, and a 3.5mm audio port. Another audio port is on the MCU and wired to pin A7, and a 3.5mm audio cable can connect between the two. This audio cable provides input to a relay inside the power box, which controls the power from the main wall line to the 2 outlets.

Networking Open Systems Interconnection (OSI) Model

The OSI model is a standard way to do networking at all levels, from the physical electrons on the wire to the applications communicating with eachother. PowerManager implements all layers of this model.

Physical Layer

The physical layer is the first and lowest layer in the OSI model of computer networking. This layer abstracts different hardware transmission technologies on a network. The physical layer defines electrical and mechanical specifications for devices and is perhaps the largest and most complicated layer in the OSI model. Protocols in this layer define means of translating digital information into analogue signals and vice versa. It handles the bit by bit transmission of data over both wired and wireless communication mediums. PowerManager uses the ENC28J60 module to handle this layer, and allows the MCU to use this layer through an SPI interface.

Data Link Layer

The data link layer arranges the bits handled by the physical layer into logical sequences called frames. It abstracts the physical layer by providing the functional and procedural means to transfer data between adjacent nodes or devices in a network. The data link layer also provides specifications for correcting certain errors that may occur over the physical layer. The ethernet protocol is defined in the data link layer for LAN. Ethernet is a fundamental standard for networking primarily because it is the first layer where nodes are differentiated on a network. In the ethernet protocol each device is mapped to a globally unique 48-bit address. This address provides a means to route frames to their correct destination. PowerManager also uses the ENC28J60 module to handle this layer. PowerManager spltis this layer between the MCU and the Ethernet controller. The MCU must first generate (and write into it’s device’s EEPROM) a globally unique MAC address. Once this MAC address is configured and set, the ENC28J60 driver stamps packet headers with both this address and the MAC address of the device where the packet is designated to go. With this information, the Ethernet controller is then able to push data onto the network using a built in Media Access Control (MAC) module.

Network Layer

The network layer provides the functional and procedural means for communication among different networks. This is different from the data link layer because the data link layer supports communication in the same network. IP is the de facto communications protocol used for relaying datagrams across an internetwork. Although this layer is not entirely necessary for PowerManager, it provides the foundation for reliable protocols in higher layers like TCP. It also makes it possible to control power in devices that may be in subnetworks managed by multiple routers in an encompassing LAN.

Remote Power Control Through LAN using Atmega644 Schemetic

PowerManager handles this layer using the uIP module. This module handles stripping IP addresses from packets generated by a browser client. It handles both IPv4 and IPv6 addresses. The uIP module abstracts away lower layers by providing functions which accept any form of an IP address along with the content for a desired packet and interfaces with the NIC and ENC28J60 modules to correctly structure and transmit it. It also provides a means to accept packets in their raw form and deconstruct them to pull out the relevant information. PowerManager also uses the uIP module to perform Address Resolution Protocol (ARP) broadcasts and requests. ARP is a popular standard used to resolve an IP address from a MAC address. Every device on the LAN (including PowerManager) maintains an ARP cache which is necessary for routing packets to their correct destinations. ARP is necessary because IP addresses are dynamic and have the potential to change (unlike MAC addresses which are persistent throughout a device’s life) with the devices life cycle within its network.

Parts List:

Description Part # Unit Cost Quantity Total
Ethernet Controller ENC28J60-I/SP-ND $3.86 1 $3.86
3.3V Regulator LD117-3.3 $0.64 1 $0.64
RJ45 Jack 380-1106-ND $5.57 1 $5.57
25 MHz Crystal CTX1158-ND $0.60 1 $0.60
High Voltage Relay GA8-2B02 From Lab 1 $0.00
Ferrite Bead From Lab 1 $0.00
100 nF Capacitor From Lab 7 $0.00
10 �F Capacitor From Lab 2 $0.00
22 pF Capacitor From Lab 2 $0.00
Misc. Resistors From Lab 15 $0.00
NPN Transistors 2N3904 From Lab 4 $0.00
Audio Ports From Lab 2 $0.00
Heatsink From Lab 1 $0.00
Electric Wall Plug From Home 1 $0.00
Electric Wall Socket $2.97 1 $2.97
Electric Wall Switch $1.24 1 $1.24
Electric PVC Box $1.97 1 $1.97
Electric PVC Box Cover $1.19 1 $1.19
Solder Board $2.50 1 $2.50
Power Supply $5.00 1 $5.00
ECE 4760 Custom PC Board $6.00 1 $6.00
ECE 4760 Custom Serial Board $5.00 1 $5.00
Serial Chip Max233CPP $7.00 1 $7.00
Serial Connector RS232 Connctor $1.00 1 $1.00
Microcontroller AtMega644 $6.00 1 $6.00
DIP Socket $0.50 2 $1.00
Jumper Cables $1.00 6 $6.00
SIP sockets/plugs $0.05 80 $4.00
TOTAL $61.54

For more detail: Power Manager: Remote Power Control Through LAN using Atmega644


About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter
Scroll to Top