Skip to main content

title

Using the Arduino Ethernet for web connected control and sensors.

I've worked with various Arduino boards previously, however, I have never used one with an Ethernet connection. Although I have a computer and use Wi-Fi etc., like many others I had taken computer networking for granted, as DCHP usually takes care of this without anyone having to think about it.

An Afternoon Reading

Before I made a start with the Arduino I did some reading up on networking and TCP/IP so that I understood some of the basics.

LED Server

To get started with I decided to use the Arduino Ethernet to remotely control LEDs on the board. I had a look on the web and managed to find an example sketch which did this. I connected eight LEDs with corresponding resistors each to digital pins and then connected these to GND.

title

The only changes required to this sketch is configuring the MAC address, gateway, subnet and the allocated IP address. The IP address is unique to the network which you are on and the MAC address is something which is unique to every manufactured Ethernet device in the world. The default MAC address in this sketch is DE-AD-BE-EF-FE-ED – while technically this could be used it would not be valid if two or more things connected to the same network shared this MAC address.

title

The best way to ensure the MAC address will work is by using the one which is allocated to the Ethernet device. This is usually printed somewhere on the board (found on the underside of the Arduino Ethernet).

title

Once uploaded the LEDs could be controlled via a basic web page. Although this was only a very simple project this gives you an idea what is possible using an Arduino Ethernet for controlling things over the web.

title

Working in reverse

After using the Arduino Ethernet to control the LEDs, I wanted to work the other way round. This time I would use the analogue pins on the Ethernet board to take readings and display these via a web page.

I looked at a few of the examples in the IDE and quickly decided that I would use the WebServer example.

title

Taking readings

To familiarise myself with the sketch I decided to confirm when an analogue input was connected to the board it would take reading. So to begin with I used a second Arduino (Uno) and uploaded this with an LED blink sketch.

title

I then connected the Arduino Ethernet to this to take readings and update the web page.

title

*The image above shows the values obtained if the analogue pins are left in a floating state.

Adding sensors

Testing the sketch worked exactly as it should, so I next moved on to use the Arduino Ethernet for something which could actually be useful. I wanted to create a remote thermometer so that you could monitor the temperature of a room remotely.

title

I used the TMP36 temperature sensor with the WebServer example. I connected the three pins of this to A1, 5V and GND. This began displaying readings via the web page, however, these were in the hundreds! For mid-summer in England this somehow didn’t seem quite right. I soon realised that I needed to include a calculation in the sketch to convert these readings into actual temperatures. I found such a calculation on the manufacturers data sheet, which would convert the readings into degrees Celsius. This was then added to the sketch so that the readings from the temperature sensor would be displayed on the web page in this format.

temperature = (((((reading/1024.0)*5)-0.5)*100))

title

Editing HTML

At this point I started looking at how I could edit the HTML so the web page would be more aesthetically pleasing. I added headings and changed the spacing to begin with. I also made changes in the sketch so that the web page would automatically refresh more frequently.

title

I next connected an LDR with a matching resistor to pin A2 on the Arduino Ethernet. I updated the sketch so that it would read this pin and display it's readings to say what it was reading rather than just “Pin A0 reads: ...”.

title

Once the LDR and temperature sensor were wired up and working together I took one last look at the HTML. I added additional headings for the LDR and after a lot of help from the web, I managed to figure out how to change the background colour of the page.

title

title

All in all I think the web page didn't look too bad when it was finished (for a first attempt at least). One of the advantages about this particular sketch is that you can have up to 6 analogue devices connected to the Arduino Ethernet at any one time. Extending the WebServer sketch could result in some really fun and exciting future projects!

Trainee Electronics Engineer, currently studying towards my degree in Electronic Engineering at the University of Hudderfsield. Completed my HND in Electrical & Electronic Engineering from Bradford College 2017. Love to try new things and build interesting projects!
DesignSpark Electrical Logolinkedin