Introduction: Remote Home Automation Example - Arduino + Ethernet Shield

Picture of Remote Home Automation Example - Arduino + Ethernet Shield

Welcome again!

In this Instructable, I will detail how to use various sensors and items with an internet connected Arduino. In my opinion, this was a very fun project to put together and tinker with! Plus, I got to brush up on my HTML and Java (albeit, it was pretty basic stuff while making this project, there's nothing more refreshing than getting back to basics!). Unfortunately, as much as I'd like to, I will not be covering the SD portion of the Ethernet Shield. That's for next time :)

This project assumes that one has some working knowledge of basic HTML/Java, programming an Arduino, and working with various sensors. I will cover and detail as much as I can, as well as provide the sketch at the end of this tutorial.

--Objective--

We will program the Arduino to serve up a webpage that displays information about two sensors (LM35 Temperature Sensor, PIR Motion Sensor) and allows one to toggle an LED on and off, as well as adjust the angle of a Servo Motor.

Step 1: Bill of Materials

Picture of Bill of Materials

For this project you will need -

-Arduino Uno
-Arduino Ethernet Shield
-PIR Motion Sensor
-LM35 Analog Temperature Sensor
-LED
-Servo Motor
-Jumper Wires
-Ethernet Cable

As far as software goes, the Arduino IDE should be the only one you should use. Now, to build a webpage to serve up, you will need to have a basic to intermediate knowledge of HTML. If there is one place I know to gain a good understanding of HTML (and Java, consequently) it's http://www.pageresource.com. That was and is my go to resource for making webpages. I was introduced to that page back in high school, and have referred to it since. A vast wealth of information there!

If you already have a good understanding of HTML and Java, you can move on :)

Step 2: The Ethernet Shield

Picture of The Ethernet Shield

So...the Arduino Ethernet Shield. It's a very handy shield for the Arduino which, obviously, allows you to put your Arduino on the internet, and, consequently, gives you the ability to serve up a custom web page.

The IDE comes bundled with a library for the shield, as well some example sketches to get your feet wet, but before you can start remotely controlling your Arduino, there are a few steps to take to get all of your hardware talking to eachother.

First up, you'll want to enable port forwarding on your internet router (if applicable). Doing so is mostly device specific, but a quick Google search on your own router and port forwarding should get you going.

You'll need also to identify the MAC address to your ethernet shield. This is unique to newer models, and should be labeled on the box it came in, but for older models, you should be able to create one. More information at http://arduino.cc/en/Guide/ArduinoEthernetShield.

Your IP address for your shield is also needed. If you're running windows, this will be easy to find. Usually, windows will automatically assign one to it (or so it seems). Open up your command prompt and enter ipconfig. It should be labeled there, and you can use that address to identify the IP address in the Arduino sketch.

The Arduino IDE has several example sketches to get you started with the Ethernet Shield. I began with the WebServer Sketch and basically built off of that. I'll try to point the way in the next step...

Step 3: "Sketching" the Ethernet Shield

Picture of "Sketching" the Ethernet Shield

It's a pretty basic setup. The sketch provides you with most everything you'll need. You can discern from it where you should put your HTML and Java code, and how it should integrate with the sketch code. Serving the webpage is easy. Interacting with it is, well...still easy.

Basically what we are doing is, HTML wise, clicking on a link. The Arduino reads the link, and acts accordingly. What I did, however, was instead of using a link, I opted for a little Java and used a button. It just makes things look a little nicer :)

Step 4: Notepad Is Our Friend :)

Picture of Notepad Is Our Friend :)

One good thing to do is to use Notepad to build up your webpage before uploading to the Arduino, that way you can tweak and change your code without having to upload every time you make a change. It is important to note that when using Notepad, you will want to save the document as an HTML document (just add .html or .htm to the end of the name), that way you can double-click and it will open up in your web browser. You don't even need to close your browser when you make changes. Just make the changes, save, and refresh. Go ahead and play around at pageresource.com and the WebServer sketch to familiarize yourself with HTML.  No special software needed!

NOTE - I've grown apart from Notepad recently, and decided to use Notepad++. Think of it like Notepad, but instead of just text, you can use it to write C++, HTML, Java...almost whatever programming language you wish! Although it doesn't compile or program anything, it's got some special features, such as syntax highlighting, that is not available in Notepad. You can get a free download at http://www.notepad-plus-plus.org should you like to check it out!

Step 5: Alright...let's Hook It All Up!

Picture of Alright...let's Hook It All Up!

I'll cover all the gadgets in this one step. Let's bust out the PIR Motion Sensor, the LM35 Analog Temperature Sensor, your trusty Servo Motor, and an LED. Don't forget the Arduino and the shield...otherwise you've just got a bunch of stuff laying out...

At any rate, we will connect all our respective 5V pins and ground pins to 5V and ground. If you're unfamiliar with the LM35, do continue...

Step 6: LM35 Analog Temperature Sensor

Picture of LM35 Analog Temperature Sensor

The LM35 is an Analog Temperature Sensor, meaning instead of a digital signal (1 or 0) it outputs a certain voltage depending on the temperature. I have a digital temperature sensor, but I chose to use the LM35 for simplicity. You can read right from it on any one of the Analog Pins on the Arduino. We will be using A5 for this project.

In the sketch, we will use "temp" as the variable, and make it equal to analogRead(A5) - int temp = analogRead(A5).

But wait! That won't really give us a temperature reading. Looks like we are gonna have to do some math and convert the output voltage to something more...usable.

When you're reading from an Analog Pin, you will see numbers anywhere from 0-1023 (the Arduino uses a 10-bit ADC, which is why we get these numbers). Let's convert this to a temperature.

We will use the formula temp = (5*val*100/1024) where "val" is the analog reading from the LM35. This will give us a centigrade temperature. If you'd like, you can use this formula, F = (temp*1.8)+32, to convert centigrade to a fahrenheight temperature.

In my sketch, to save a little room, I combined both formulas into (((5*analogRead(A5)*100/1024)*1.8)+32) to get straight to the fahrenheight temperature :)

So, with that out of the way, we will connect the LM35 to it's power, ground, and we will hook up the output to Analog Pin 5 of the Arduino.

Step 7: The Rest of It...

Picture of The Rest of It...

If you haven't followed my previous instructable including the PIR Motion Sensor, I'll give a quick lesson.

The PIR has three pins - 5V, Ground, and Output. When it senses motion, it's output pin goes high. We will connect it's output pin to Digital Pin 3 of the Arduino. It's very simple to use and doesn't require much setup. Just don't forget to set Digital Pin 3 to INPUT.

The LED we will put on Pin 2. Set that pin to OUTPUT and you're good to go!

**NOTE - Disregard where the PIR is connected in the picture. I put it there for illustration purposes.**

Step 8: Building the Page

Picture of Building the Page

https://gist.github.com/gtrstitch/5992603

The link above will take you to the HTML file for the webpage. It's not the Arduino Sketch, but merely the HTML side of what will be going into the sketch. It will save as an HTML file, and when you want to edit it, just right click and open with Notepad.

Feel free to tweak and change what you please to fit it to your needs!

As I said, this is not the Arduino Sketch, and that being so, you may notice the temperature and motion sections. They don't really show temperature and motion indications. I set those there just to get an idea of what the end result would look like. All part of the design process!

Let's move on and take a look at the Arduino portion...

Step 9: Building the Sketch

Picture of Building the Sketch

https://gist.github.com/gtrstitch/5992646

The link above is the Arduino Sketch. You'll notice there is a lot of client.print(). That's where we put all the HTML code. Anything in the <> is the actual part of the code. The parts we don't see. Everything else is what we do see.

Be sure you keep track of your quotation marks! One untamed quotation mark can put a wrench in things. If there is an area of HTML that absolutely needs quotations, just use an apostrophe, ' , in place of quotations. You can get away without using quotations, most of the time.

You may also notice that I left off the page refresh part in the HTML file. This is because I preferred not to have the page refresh every few seconds, as I didn't need it to.

Step 10: Conclusion...

Picture of Conclusion...

All in all, it's a fairly simple project, but the potential is left to the imagination.

One may use this to remotely monitor the temperature in their home, and with the use of a servo or stepper motor, you could switch on or off your A/C, or even adjust the thermostat. 

You could also use it in conjunction with the Arduino Home Security project and keep tabs on what's happening at home while you're away. 

I hope you enjoyed this Instructable and along the way, gained some valuable information to pave the way to your next awesome project! If you have any questions/comments/suggestions, as always, feel free to drop a line!

~~Credits~~

Big thanks to http://www.pageresource.com for being a most invaluable tool throughout the years, and I sincerely hope it helps you as much as it's been a help for me!

Singing off,

~GtrStitch

Comments

fayaz ali (author)2017-10-16

Hi Sir please help me :(

I am working on project of home automation using ethernet shield . My web server ip is 35.198.198.132 and my Lan ip is 192,168.1.3 . is it necessary to bath ip should be same ?

wabbas1 made it! (author)2014-05-08

impressive project (Y)...really enjoyed making as weekend project.
can you please help how to monitor ECG/EKG using this?
thanks in advance

gtr_stitch (author)wabbas12017-05-04

I'm 3 years late but I'm really curious if you've been able to monitor an ECG/EKG with this or a similar setup?

jamjamchavez (author)2014-08-24

hi. my ethernet shield is not able to communicate with my LAN. I have uploaded your program to my Arduino, having the mac and IP addresses conforming with my network. I still can't access the webserver. :( please help. it always says that the webpage is not available.

gtr_stitch (author)jamjamchavez2017-05-04

I'm assuming you're trying to connect to it from inside your network. I don't think port forwarding matters in-network. Connect everything up and log into your router to be sure that it detects your setup. 3 years too late, probably, but if you need any other help let me know!

sebbou (author)2014-12-19

Wonderfull!!! This is simple and a really interesting base for future project!

Good job!

P.S. the first balise in your HTML code should be changed to "HTML" instead of "HMTL"...

gtr_stitch (author)sebbou2017-05-04

Nice catch! I've sent many an email with mistakes like that!

keshavadk (author)2016-05-12

Nice explanation. I have worked on Arduino uno for doing basic projects. Now i have interface Arduino Uno with ESP 8266 wifi module and 16*2 LCD. Now i want to send text from webpage that is i have a text box in webpage and submit button. When i type text in text box and click submit button,the text should appear on LCD. Any idea about both Html part and arduino part .

Thank you

gtr_stitch (author)keshavadk2017-05-04

I have done a project exactly like this a long time ago (well, not exactly. ESP8266 wasn't around yet!). I'm looking for the sketch at the moment, but I'll PM it to you (if possible). It shouldn't be too hard to adapt the code to work with the ESP.

sunil vijaya (author)2016-09-09

hi,

i managed to get the above project working at home. i can put off and on through laptop and my android phone using the address. but when try to access from outside home the html page doesn't show up. the forwarding port is defined in the sketch and also i did the telnet on windows. what more should i do to get this work this from other than home? pl help.

gtr_stitch (author)sunil vijaya2017-05-04

So sorry for the late response! So far everything looks good. Port forwarding is on, which is a major thing. One last thing I would suggest is, while connected to your home network, go into Google and enter 'what is my ip address'. This will give you the ip address of your home network as it appears outside of your network. I won't look anything like your run-of-the-mill 198.x.x.x or 10.x.x.x. So, let's say your external IP address is 23.4.5.67 and you're away from home, open your preferred web browser and put in 23.4.5.67:80 (assuming you've used port 80). That should be enough to reach your Arduino away from home. Let me know if you have troubles!

farsadheidari (author)2015-02-09

Thank you very very much

JohnathanDoes (author)2015-01-09

Java and JavaScript are completely different languages. The confusion is understandable as JavaScript was originally named to confuse people and piggy back off the marketing done for Java at the time JavaScript was launched.

loveisbetter (author)2014-07-23

hi i made this awesome project but the thing i want to know that i made 6 more buttons with this for other devices and i made tables for othe purpose please tell me devices are working but servo doesnot work even if i enter the servo code to activate the servo hte devices also stay idle and on any press nothing works what is this how many buttons can be here so they can work any help?? please

amnamrza901 (author)2014-07-05

i actualy want to know how did you get this access.when i type ip i did not find webpage kindly instruct me to actual command which i have to follow

amnamrza901 (author)2014-07-05

kindly tell me what are the steps for webserver making i mean i downloaded ur file for sketch and also i saved html page with coding but now tell me what to do next to upload it on net so it can communicate with the arduino thank u

nofeel (author)2014-01-18

why you use formula x5x100x1024?? what value is it? thank you

yyyyazj (author)2013-10-17

Brilliant. I want to use Arduino Ethernet to control the LED by telephone, if I use the Arduino Ethernet as the websever, how can I transfer the state of buttons on telephone to Arduino?

pprins (author)2013-08-31

I like it , made something similar using Android and Arduino called X10Domuino.
It uses X10 and RF and Infrared with a single Arduino connected to Ethernet
Regards
Philip

AskMP (author)2013-07-18

Great to see you diving into this. I’m doing something similar for myself but using a spare laptop to connect to an Arduino. It’s running a local NodeJS server that is also connected to another cloud NodeJS server. These can communicate to one another and I can then monitor and control everything in real time. My plans are to add full voice recognition through the browser on multiple devices through Chrome’s voiceRecognitionServer protocol as well as it’s speech synthesis. Keep us updated on what other elements you add to your project.

About This Instructable

222,718views

218favorites

License:

Bio: Hi! My name is stitch. On the professional side, I am currently pursuing a career in law enforcement...but at home...I am a circuit ... More »
More by gtr_stitch:Remote Home Automation Example - Arduino + Ethernet ShieldSuper Simple Arduino Keypad (the hard way)Arduino Home Monitor System
Add instructable to: