loading

This instructable describes how a simple but powerful webserver used for controlling of home appliances can be done. The hart of the circuit is the ATmega328 microcontroller. I have chose this because I wanted to use all available Arduino libraries compatible with them. The Ethernet chip used is ENC28J60. A lot of Arduino libraries exist also for it. The webserver is designed in the way that it control 4 channels (3 LED's and a relay). It have two outputs for "status"/"mode" LED's (which of course can be used also for control of other devices). I have used one analog input for some sensor (can be LDR, thermoresistor, thermometer chip, hall sensor, current monitor chip like ACS712...etc).The webserver has two buttons - first for reset, and the second for mode selection or some additional settings. A power indicator LED shows if the webserver is supplied or not.

The movie above demonstrates the webserver functioning using a simple basic program.

Step 1: Design Description

The schematic of the webserver is shown on the picture. There can be seen the three channels, each controlling a pair of LED's. Here LED's are meant in more wide aspect - they can be standard LED's, but also could be LED's, which are parts of optocouplers used for relay control as these on the picture above. It could be also combination of LED indicating if the relay is activated and the optocoupler. On the schematic diagram can be seen also both "status"/"mode" LED indicators. Using binary encoding they could show for example which mode of four available is active in the moment or to give some other useful information. Looking at the schematic can be noticed also that the power supply circuitry consist of three different power chips, which seems to work together in parallel. This is not true :-). This approach of schematics drawing gives further, when designing the PCB, to place there three different footprints of these chips and finally to solder only one, but having a big choice for alternatives. The current PCB supports linear regulators in SOT223 and TO263 packages, as well the National Semiconductors (TI) "simple switcher" regulator LM2825N (both versions: adjustable or fixed voltage 3.3V). Using switching power supply in this case may be is better solution because of the higher power efficiency comparing with the linear one. The ENC28J60 chips is consuming relatively high current and the power loss in the linear regulator can be high. I have soldered LM2825N-3.3. (The supply must be kept in these limits, because the ENC28J60 can be burned at 5V!)

The design files in "Eagle" format are available for download. They can be used and modified freely without asking of permission. From there can be extracted the part list. I will not give here the whole BOM. I will describe only the most specific parts.

As I said : the microcontroller used is the ATmega328 in DIP28 package.Can be used also the low power version ATmega328P. Here you should be careful with the chip signatures used by the Arduino programmer - for both chips they differ. How to solve the problem can be seen here. The ETH chip is ENC28J60 in DIP package. On the PCB there is place where a Zettler relay AZ733-2C-12DE can be soldered, but it is optional. The most exotic part in the whole design is the Ethernet jack with embedded magnets "HanRun" HR911105A. The passive devices are mainly SMD. This could be problem for people not having experience with soldering of these devices, but in this site can be found a lot of instructions about this.

Step 2: Pictures of the Fabricated PCB

On the picture can be seen the dual layer fabricated PCB

Step 3: Almost Ready Device ...

The pictures show a populated PCB. Not all possible devices are soldered, but this is not always necessary. Depending on the use, some devices can be soldered or not, or simply replaced with others. For example: instead R25 a lot of other devices can connected - various temperature, light, humidity, voltage, current....and so..and so sensors can be attached. Instead the LED's at the PCB periphery optocouplers, triacs , MOS transistor switches or solid state relay can be connected.

Here I want to mention two things:

1) It is highly recommended that the ATmega328 chip is put on socket and can be extracted for programming

2) Although, there is SPI connector on the PCB, which could be used for the programming on place of the ATmega chip, it can create problems....

- a programmer working with 3.3V must be used, because the microcontroller and the Ethernet chip share the same power supply. If this voltage is overridden the ENC28J60 can be burned out.

- both chips share the same SPI bus, and a conflict could appear.

Other solution could be to put the ENC28J60 chip on socket and to solder the ATmega328 chip. In this case, before each programming the ETH chip should be removed and after that inserted back. The connection to the power supply chip of the webserver should be cut also by the use of the jumper JP4.

I personally programmed the ATmega328 chip on a breadboard using cheap USBtinyISP programmer from ebay. (see the next step).

Step 4: Programming Setup

Programming of the microcontroller was done using the setup shown above.

I did not burn a bootloader in the chip. For programming I have used the "Load the sketch using programmer" menu item of the Arduino IDE.

A simple code switching ON/OFF 3 LED channels and the relay is attached to this step. Some explanation about the code will be given later.

Step 5: Loading the Program

Other possibility for the loading of the binary file in the ATmega chip is to use directly the AVRDUDE.

It must be started in DOS window. Normally I copy the *.hex file inside the WinAVR/bin folder and there I start directly AVRDUDE. The commands used can be seen on the pictures. (Again remark : Be careful with signatures!)

In all cases you have to use AVRDUDE to program the chip in the correct way - this is because also the fuses must be set. I write them exactly as they are written on the Arduino boards using the same chip. The commands for this can be seen on the pictures. More precise explanation how to use the AVRDUDE you can find here.

Step 6: Final Steps...

At first I want to say something about the code. In this part of the code :

static uint8_t mac[6] = {
0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,

static uint8_t ip[4] = { 192, 168, 1, 200 }; // IP address for the webserver

static uint16_t port = 80; // Use port 80 - the standard for HTTP

three data must be given: the mac and the IP address, eventually the port number.

Both must be unique for your LAN.

You can leave the mac address as it is. If you do not have other Arduino board connected to the LAN, may be you could be lucky. The IP address, which in this case is internal LAN address should start with 192.168. ...After choosing an address for the webserver, before programming, you have to be sure that another device in the LAN does not carry it. Try to ping it. If no response comes, it could be unique. Normally the standard port for HTTP communication is 80. But it can happen that for some reason it is blocked by your router. Try to unblock it. If impossible - change the HTTP port to 8080 in the code. This could work.

To test the webserver inside your LAN, connect a PC or laptop the network, open an internet browser and type there the IP address which you gave in the code. (In my case 192.168.1.200). The welcome screen of the webserver should appear. At success, you can try to access it from "outside". For that purpose you must configure first your router/modem to be able to forward the port 80. You have to log in and allow the port forwarding for HTTP. How to do this you can find in the manual of the device. I have "Samsung" Horizon media box - router. The picture shows the port forwarding settings. After this step you have to find your default gateway IP address. In Google type "whatismyip". Click on the first search result. It will give you your actual IP address. Now, using a device, which is not connected to the LAN (for example GSM with 3G or GPRS connection), but having an internet access, type your gateway IP in the internet browser. May be it will be needed to add also the port. If everything is set correct, you should be able to access your webserver.

Good luck in playing and thank you for the attention.

P.S. I have few bare PCB's available. I can provide you a piece against $12 (shipping included). Mail me at chicho.mecho@gmail.com for ordering.

<p>Thank you for your ideas. I also though to do something similar, and I have added a jumper in the supply line.It exist only in the design files provided for download, but not in my original PCB. You know that according the Murphy, you'll find that a problem exist only after receiving of the ordered PCB's :-). Because this design has only one version done until now some problems exist and they are still not corrected.</p><p>Never mind...In the version available for download I did not correct the problem with the ISP interface, because the solution, which I used is not so complicated. Or that solution, which I propose in the instructable (to put the ENC28J60 on socket) also can be used. In all cases: the PCB files are open for changes, and each guy, wanting to repeat the design is allowed to change them according his will and needs.</p>
Very nice build, I really like the quality of the PCB you built, thanks for sharing. Just a thought about programming via SPI, you can use 3 jumpers (scavenge any old PC motherboard for plenty of those) to &quot;cut&quot; the traces going to the other chip, leaving only the 328 connected to the SPI header. you can even do the same for the power supply: remove the jumpers and the 3.3V chip is disconnected from the power and SPI headers, program the 328 with 3.3V or 5V programmer, doesn't matter. Insert the jumpers again and everything is again connected.

About This Instructable

6,526views

89favorites

Bio: Thank you all for following me.
More by Milen:Party stroboscope done by recycled parts Arduino controlled power supply source Arduino Nano to Arduino Uno adapter 
Add instructable to: